mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 00:12:03 +02:00
refactoring: separate methods from bank_transaction model to concern
This commit is contained in:
parent
28d1560555
commit
1294a05870
3 changed files with 54 additions and 20 deletions
|
@ -1,5 +1,6 @@
|
|||
class BankTransaction < ApplicationRecord
|
||||
include Versions
|
||||
include TransactionPaidInvoices
|
||||
belongs_to :bank_statement
|
||||
has_one :account_activity
|
||||
|
||||
|
@ -17,24 +18,6 @@ class BankTransaction < ApplicationRecord
|
|||
account_activity.invoice
|
||||
end
|
||||
|
||||
def invoice
|
||||
return unless registrar
|
||||
|
||||
@invoice ||= registrar.invoices
|
||||
.order(created_at: :asc)
|
||||
.unpaid
|
||||
.non_cancelled
|
||||
.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?)
|
||||
end
|
||||
|
||||
def registrar
|
||||
@registrar ||= Invoice.find_by(reference_no: parsed_ref_number)&.buyer
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue