mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
Added comma support #2785
This commit is contained in:
parent
f5311301c9
commit
e9cf3d2fbe
15 changed files with 80 additions and 21 deletions
|
@ -7,6 +7,7 @@ class Admin::BankTransactionsController < AdminController
|
|||
end
|
||||
|
||||
def create
|
||||
comma_support_for(:bank_transaction, :sum)
|
||||
@bank_transaction = BankTransaction.new(
|
||||
bank_transaction_params.merge(bank_statement_id: params[:bank_statement_id])
|
||||
)
|
||||
|
@ -21,6 +22,7 @@ class Admin::BankTransactionsController < AdminController
|
|||
end
|
||||
|
||||
def update
|
||||
comma_support_for(:bank_transaction, :sum)
|
||||
if @bank_transaction.update(bank_transaction_params)
|
||||
flash[:notice] = I18n.t('record_updated')
|
||||
redirect_to [:admin, @bank_transaction]
|
||||
|
|
|
@ -17,6 +17,7 @@ class Admin::PricelistsController < AdminController
|
|||
end
|
||||
|
||||
def create
|
||||
comma_support_for(:pricelist, :price)
|
||||
@pricelist = Pricelist.new(pricelist_params)
|
||||
|
||||
if @pricelist.save
|
||||
|
@ -27,6 +28,7 @@ class Admin::PricelistsController < AdminController
|
|||
end
|
||||
|
||||
def update
|
||||
comma_support_for(:pricelist, :price)
|
||||
if @pricelist.update_attributes(pricelist_params)
|
||||
redirect_to admin_pricelists_url
|
||||
else
|
||||
|
@ -49,4 +51,5 @@ class Admin::PricelistsController < AdminController
|
|||
params.require(:pricelist).permit(:operation_category, :category, :price_category,
|
||||
:duration, :price, :valid_from, :valid_to)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -70,4 +70,10 @@ class ApplicationController < ActionController::Base
|
|||
return 'public' if user.nil?
|
||||
"#{user.id}-#{user.class}: #{user.username}"
|
||||
end
|
||||
|
||||
def comma_support_for(parent_key, key)
|
||||
return if params[parent_key].blank?
|
||||
return if params[parent_key][key].blank?
|
||||
params[parent_key][key].sub!(/,/, '.')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -45,4 +45,9 @@ module ApplicationHelper
|
|||
# can be api user or some other user
|
||||
link_to(model.updator, ['admin', model.updator])
|
||||
end
|
||||
|
||||
def currency(amount)
|
||||
amount ||= 0
|
||||
("%01.2f" % amount.round(2)).sub(/\./, ',')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,6 +23,10 @@ class Deposit
|
|||
false
|
||||
end
|
||||
|
||||
def amount
|
||||
BigDecimal.new(@amount.to_s.sub(/,/, '.'))
|
||||
end
|
||||
|
||||
def issue_prepayment_invoice
|
||||
valid? && registrar.issue_prepayment_invoice(amount, description)
|
||||
end
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
%tr
|
||||
%td= link_to(l(x.paid_at, format: :date_long), [:admin, x])
|
||||
%td= x.buyer_name
|
||||
%td= x.sum
|
||||
%td= currency(x.sum)
|
||||
%td= x.currency
|
||||
- c = x.binded? ? 'text-success' : 'text-danger'
|
||||
%td{class: c}= x.binded? ? t(:binded) : t(:not_binded)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
.form-group
|
||||
= f.label :sum, class: 'col-md-4 control-label required'
|
||||
.col-md-8
|
||||
= f.text_field(:sum, class: 'form-control', required: true)
|
||||
= f.text_field(:sum, value: currency(f.object.sum), class: 'form-control', required: true)
|
||||
|
||||
.form-group
|
||||
= f.label :reference_no, class: 'col-md-4 control-label required'
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
%dd= @bank_transaction.description
|
||||
|
||||
%dt= t(:sum)
|
||||
%dd= @bank_transaction.sum
|
||||
%dd= currency(@bank_transaction.sum)
|
||||
|
||||
%dt= t(:currency)
|
||||
%dd= @bank_transaction.currency
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
.form-group
|
||||
= f.label :price
|
||||
.input-group
|
||||
= f.text_field(:price, class: 'form-control')
|
||||
= f.text_field(:price, value: currency(f.object.price), class: 'form-control')
|
||||
%span.input-group-addon= Money.default_currency
|
||||
.form-group.input-daterange
|
||||
= f.label :valid_from, t(:valid)
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
%td= pricelist.category
|
||||
%td= pricelist.duration
|
||||
%td= pricelist.operation_category
|
||||
%td= pricelist.price
|
||||
%td= currency(pricelist.price)
|
||||
%td= l(pricelist.valid_from, format: :ydate)
|
||||
%td= l(pricelist.valid_to, format: :ydate)
|
||||
%td= link_to(t(:edit), edit_admin_pricelist_path(pricelist), class: 'btn btn-xs btn-primary')
|
||||
|
|
|
@ -14,19 +14,19 @@
|
|||
%tr
|
||||
%td= t(x.description)
|
||||
%td= x.unit
|
||||
%td= x.amount
|
||||
%td= x.price
|
||||
%td= x.item_sum_without_vat
|
||||
%td= currency(x.amount)
|
||||
%td= currency(x.price)
|
||||
%td= currency(x.item_sum_without_vat)
|
||||
%tfoot
|
||||
%tr
|
||||
%th{colspan: 3}
|
||||
%th= t(:total_without_vat)
|
||||
%td= @invoice.sum_without_vat
|
||||
%td= currency(@invoice.sum_without_vat)
|
||||
%tr
|
||||
%th.no-border{colspan: 3}
|
||||
%th= t('vat', vat_prc: (@invoice.vat_prc * 100).round)
|
||||
%td= @invoice.vat
|
||||
%td= currency(@invoice.vat)
|
||||
%tr
|
||||
%th.no-border{colspan: 3}
|
||||
%th= t(:total)
|
||||
%td= @invoice.sum
|
||||
%td= currency(@invoice.sum)
|
||||
|
|
|
@ -229,22 +229,22 @@
|
|||
%tr
|
||||
%td= t(x.description)
|
||||
%td= x.unit
|
||||
%td= x.amount
|
||||
%td= x.price
|
||||
%td= "#{x.item_sum_without_vat} #{@invoice.currency}"
|
||||
%td= currency(x.amount)
|
||||
%td= currency(x.price)
|
||||
%td= "#{currency(x.item_sum_without_vat)} #{@invoice.currency}"
|
||||
%tfoot
|
||||
%tr
|
||||
%th{colspan: 3}
|
||||
%th= t(:total_without_vat)
|
||||
%td= "#{@invoice.sum_without_vat} #{@invoice.currency}"
|
||||
%td= "#{currency(@invoice.sum_without_vat)} #{@invoice.currency}"
|
||||
%tr
|
||||
%th.no-border{colspan: 3}
|
||||
%th= t('vat', vat_prc: (@invoice.vat_prc * 100).round)
|
||||
%td= "#{@invoice.vat} #{@invoice.currency}"
|
||||
%td= "#{currency(@invoice.vat)} #{@invoice.currency}"
|
||||
%tr
|
||||
%th.no-border{colspan: 3}
|
||||
%th= t(:total)
|
||||
%td= "#{@invoice.sum} #{@invoice.currency}"
|
||||
%td= "#{currency(@invoice.sum)} #{@invoice.currency}"
|
||||
|
||||
#footer
|
||||
%hr
|
||||
|
|
|
@ -46,7 +46,7 @@ feature 'BankStatement', type: :feature do
|
|||
|
||||
click_link 'Back to bank statement'
|
||||
|
||||
page.should have_content('120.0')
|
||||
page.should have_content('120,00')
|
||||
page.should have_content('Test buyer')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -37,7 +37,7 @@ feature 'Invoice', type: :feature do
|
|||
page.should have_content('Record created')
|
||||
page.should have_content('Invoice no.')
|
||||
page.should have_content('Prepayment')
|
||||
page.should have_content('120.0')
|
||||
page.should have_content('120,00')
|
||||
page.should have_content(r.name)
|
||||
end
|
||||
|
||||
|
@ -107,7 +107,7 @@ feature 'Invoice', type: :feature do
|
|||
page.should have_content('689')
|
||||
page.should have_content('EE557700771000598731')
|
||||
page.should have_content('Not binded', count: 2)
|
||||
page.should have_content(invoice.sum.to_s)
|
||||
page.should have_content('240,00')
|
||||
page.should have_content('EUR')
|
||||
|
||||
click_link 'Bind invoices'
|
||||
|
@ -120,7 +120,7 @@ feature 'Invoice', type: :feature do
|
|||
|
||||
page.should have_content('Binded')
|
||||
page.should have_content(invoice.to_s)
|
||||
page.should have_content(invoice.sum.to_s)
|
||||
page.should have_content('240,00')
|
||||
page.should have_content(invoice.reference_no)
|
||||
page.should have_content(I18n.l(paid_at, format: :date_long))
|
||||
|
||||
|
|
39
spec/models/deposit_spec.rb
Normal file
39
spec/models/deposit_spec.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Deposit do
|
||||
context 'with invalid attribute' do
|
||||
before :all do
|
||||
@deposit = Deposit.new
|
||||
end
|
||||
|
||||
it 'should not be valid' do
|
||||
@deposit.valid?
|
||||
@deposit.errors.full_messages.should match_array([
|
||||
"Registrar is missing"
|
||||
])
|
||||
end
|
||||
|
||||
it 'should have 0 amount' do
|
||||
@deposit.amount.should == 0
|
||||
end
|
||||
|
||||
it 'should not be presisted' do
|
||||
@deposit.persisted?.should == false
|
||||
end
|
||||
|
||||
it 'should replace comma with point for 0' do
|
||||
@deposit.amount = '0,0'
|
||||
@deposit.amount.should == 0.0
|
||||
end
|
||||
|
||||
it 'should replace comma with points' do
|
||||
@deposit.amount = '10,11'
|
||||
@deposit.amount.should == 10.11
|
||||
end
|
||||
|
||||
it 'should work with float as well' do
|
||||
@deposit.amount = 0.123
|
||||
@deposit.amount.should == 0.123
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue