mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 06:34:46 +02:00
added non canceled method for check paid invoices
This commit is contained in:
parent
8f3f5f7302
commit
40368aaa62
3 changed files with 23 additions and 5 deletions
|
@ -27,6 +27,16 @@ class BankTransaction < ApplicationRecord
|
|||
.find_by(total: sum)
|
||||
end
|
||||
|
||||
def non_canceled?
|
||||
paid_invoices = registrar.invoices
|
||||
.order(created_at: :asc)
|
||||
.non_cancelled
|
||||
.where(total: sum)
|
||||
return true if paid_invoices.any?(&:paid?)
|
||||
|
||||
false
|
||||
end
|
||||
|
||||
def registrar
|
||||
@registrar ||= Invoice.find_by(reference_no: parsed_ref_number)&.buyer
|
||||
end
|
||||
|
|
|
@ -39,9 +39,11 @@ namespace :invoices do
|
|||
reference_no: incoming_transaction.payment_reference_number,
|
||||
description: incoming_transaction.payment_description }
|
||||
transaction = bank_statement.bank_transactions.create!(transaction_attributes)
|
||||
Invoice.create_from_transaction!(transaction) unless transaction.autobindable?
|
||||
|
||||
transaction.autobind_invoice
|
||||
unless transaction.non_canceled?
|
||||
Invoice.create_from_transaction!(transaction) unless transaction.autobindable?
|
||||
transaction.autobind_invoice
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
|
|
|
@ -14,6 +14,7 @@ class ProcessPaymentsTaskTest < ActiveSupport::TestCase
|
|||
currency: @payment_currency,
|
||||
reference_no: @payment_reference_number)
|
||||
@account_activity = account_activities(:one)
|
||||
@account = accounts(:cash)
|
||||
|
||||
Setting.registry_iban = beneficiary_iban
|
||||
|
||||
|
@ -48,8 +49,13 @@ class ProcessPaymentsTaskTest < ActiveSupport::TestCase
|
|||
|
||||
assert_no_difference 'AccountActivity.count' do
|
||||
assert_no_difference 'Invoice.count' do
|
||||
Invoice.create_from_transaction!(transaction) unless transaction.autobindable?
|
||||
transaction.autobind_invoice
|
||||
assert_no_difference -> {@account.balance} do
|
||||
unless transaction.non_canceled?
|
||||
Invoice.create_from_transaction!(transaction) unless transaction.autobindable?
|
||||
transaction.autobind_invoice
|
||||
@account.reload
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -114,7 +120,7 @@ class ProcessPaymentsTaskTest < ActiveSupport::TestCase
|
|||
run_task
|
||||
end
|
||||
|
||||
assert_changes -> { registrar.invoices.count } do
|
||||
assert_no_changes -> { registrar.invoices.count } do
|
||||
run_task
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue