mirror of
https://github.com/internetee/registry.git
synced 2025-07-05 02:33:35 +02:00
Fix double binding issue
This commit is contained in:
parent
fe6804ab11
commit
18a2e27c19
3 changed files with 10 additions and 1 deletions
|
@ -30,6 +30,8 @@ class BankTransaction < ActiveRecord::Base
|
||||||
invoice = registrar.invoices.find_by(id: invoice_id)
|
invoice = registrar.invoices.find_by(id: invoice_id)
|
||||||
return unless invoice
|
return unless invoice
|
||||||
|
|
||||||
|
return if invoice.binded?
|
||||||
|
|
||||||
return if invoice.sum != sum
|
return if invoice.sum != sum
|
||||||
create_account_activity(
|
create_account_activity(
|
||||||
account: registrar.cash_account,
|
account: registrar.cash_account,
|
||||||
|
|
|
@ -2,11 +2,17 @@ class Invoice < ActiveRecord::Base
|
||||||
belongs_to :seller, class_name: 'Registrar'
|
belongs_to :seller, class_name: 'Registrar'
|
||||||
belongs_to :buyer, class_name: 'Registrar'
|
belongs_to :buyer, class_name: 'Registrar'
|
||||||
has_many :invoice_items
|
has_many :invoice_items
|
||||||
|
has_one :account_activity
|
||||||
|
|
||||||
accepts_nested_attributes_for :invoice_items
|
accepts_nested_attributes_for :invoice_items
|
||||||
|
|
||||||
validates :invoice_type, :due_date, :currency, :seller_name,
|
validates :invoice_type, :due_date, :currency, :seller_name,
|
||||||
:seller_iban, :buyer_name, :invoice_items, :vat_prc, presence: true
|
:seller_iban, :buyer_name, :invoice_items, :vat_prc, presence: true
|
||||||
|
|
||||||
|
def binded?
|
||||||
|
account_activity.present?
|
||||||
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
I18n.t('invoice_no', no: id)
|
I18n.t('invoice_no', no: id)
|
||||||
end
|
end
|
||||||
|
|
|
@ -50,7 +50,7 @@ describe BankStatement do
|
||||||
description: 'Invoice no. 1'
|
description: 'Invoice no. 1'
|
||||||
}),
|
}),
|
||||||
Fabricate(:bank_transaction, {
|
Fabricate(:bank_transaction, {
|
||||||
sum: 120.0,
|
sum: 240.0,
|
||||||
reference_no: 'RF7086666663',
|
reference_no: 'RF7086666663',
|
||||||
description: 'Invoice no. 1'
|
description: 'Invoice no. 1'
|
||||||
})
|
})
|
||||||
|
@ -66,6 +66,7 @@ describe BankStatement do
|
||||||
r.cash_account.balance.should == 240.0
|
r.cash_account.balance.should == 240.0
|
||||||
|
|
||||||
bs.bank_transactions.unbinded.count.should == 1
|
bs.bank_transactions.unbinded.count.should == 1
|
||||||
|
bs.partially_binded?.should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
# it 'should have one version' do
|
# it 'should have one version' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue