mirror of
https://github.com/internetee/registry.git
synced 2025-06-07 21:25:39 +02:00
Merge pull request #1499 from internetee/1496-fix-invoice-autobinding
Add non_cancelled scope to autobind invoices
This commit is contained in:
commit
cbbfbae99e
2 changed files with 29 additions and 1 deletions
|
@ -17,7 +17,13 @@ class BankTransaction < ApplicationRecord
|
|||
end
|
||||
|
||||
def invoice
|
||||
@invoice ||= registrar.invoices.order(created_at: :asc).unpaid.find_by(total: sum) if registrar
|
||||
return unless registrar
|
||||
|
||||
@invoice ||= registrar.invoices
|
||||
.order(created_at: :asc)
|
||||
.unpaid
|
||||
.non_cancelled
|
||||
.find_by(total: sum)
|
||||
end
|
||||
|
||||
def registrar
|
||||
|
|
|
@ -41,6 +41,28 @@ class BankTransactionTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_binds_if_this_sum_cancelled_invoice_already_present
|
||||
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
|
||||
another_invoice = @invoice.dup
|
||||
another_invoice.save(validate: false)
|
||||
|
||||
|
||||
another_item = @invoice.items.first.dup
|
||||
another_item.invoice = another_invoice
|
||||
|
||||
another_item.save
|
||||
another_invoice.reload
|
||||
another_invoice.update(reference_no: '1234567', number: '2221', cancelled_at: Time.zone.now)
|
||||
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue