mirror of
https://github.com/internetee/registry.git
synced 2025-06-08 05:34:46 +02:00
Add autobind fix if invoice with this sum is already present
This commit is contained in:
parent
3821c76d36
commit
19cd5ecd95
2 changed files with 52 additions and 1 deletions
|
@ -17,7 +17,7 @@ class BankTransaction < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def invoice
|
def invoice
|
||||||
@invoice ||= registrar.invoices.find_by(total: sum) if registrar
|
@invoice ||= registrar.invoices.order(created_at: :asc).unpaid.find_by(total: sum) if registrar
|
||||||
end
|
end
|
||||||
|
|
||||||
def registrar
|
def registrar
|
||||||
|
|
|
@ -15,6 +15,57 @@ class BankTransactionTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_binds_if_this_sum_invoice_already_present
|
||||||
|
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
|
||||||
|
another_invoice = @invoice.dup
|
||||||
|
another_invoice.save(validate: false)
|
||||||
|
another_invoice.update(reference_no: '7654321', number: '2221')
|
||||||
|
|
||||||
|
another_item = @invoice.items.first.dup
|
||||||
|
another_item.invoice = another_invoice
|
||||||
|
another_item.save
|
||||||
|
another_invoice.reload
|
||||||
|
|
||||||
|
first_transaction = BankTransaction.new(description: 'invoice #2221',
|
||||||
|
sum: 10,
|
||||||
|
description: 'Order nr 1 from registrar 1234567 second number 2345678')
|
||||||
|
|
||||||
|
first_transaction.create_activity(another_invoice.buyer, another_invoice)
|
||||||
|
|
||||||
|
transaction = BankTransaction.new(description: 'invoice #2222',
|
||||||
|
sum: 10,
|
||||||
|
description: 'Order nr 1 from registrar 1234567 second number 2345678')
|
||||||
|
|
||||||
|
assert_difference 'AccountActivity.count' do
|
||||||
|
transaction.autobind_invoice
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_marks_the_first_one_as_paid_if_same_sum
|
||||||
|
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
|
||||||
|
another_invoice = @invoice.dup
|
||||||
|
another_invoice.save(validate: false)
|
||||||
|
another_invoice.update(reference_no: '7654321', number: '2221')
|
||||||
|
|
||||||
|
another_item = @invoice.items.first.dup
|
||||||
|
another_item.invoice = another_invoice
|
||||||
|
another_item.save
|
||||||
|
another_invoice.reload
|
||||||
|
|
||||||
|
transaction = BankTransaction.new(description: 'invoice #2222',
|
||||||
|
sum: 10,
|
||||||
|
description: 'Order nr 1 from registrar 1234567 second number 2345678')
|
||||||
|
|
||||||
|
assert_difference 'AccountActivity.count' do
|
||||||
|
transaction.autobind_invoice
|
||||||
|
end
|
||||||
|
|
||||||
|
@invoice.reload
|
||||||
|
another_invoice.reload
|
||||||
|
assert(@invoice.paid?)
|
||||||
|
assert_not(another_invoice.paid?)
|
||||||
|
end
|
||||||
|
|
||||||
def test_matches_against_invoice_nubmber_and_reference_number_in_description
|
def test_matches_against_invoice_nubmber_and_reference_number_in_description
|
||||||
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
|
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
|
||||||
transaction = BankTransaction.new(description: 'invoice #2222',
|
transaction = BankTransaction.new(description: 'invoice #2222',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue