mirror of
https://github.com/internetee/registry.git
synced 2025-08-02 16:02:03 +02:00
Some tests for invoice binding
This commit is contained in:
parent
e678e655da
commit
57d23976c7
19 changed files with 206 additions and 25 deletions
|
@ -1,3 +1,38 @@
|
|||
class BankTransaction < ActiveRecord::Base
|
||||
belongs_to :bank_statement
|
||||
has_one :account_activity
|
||||
|
||||
scope :unbinded, -> { where('id NOT IN (SELECT bank_transaction_id FROM account_activities)') }
|
||||
|
||||
def binded?
|
||||
account_activity.present?
|
||||
end
|
||||
|
||||
# For successful binding, reference number, invoice id and sum must match with the invoice
|
||||
# rubocop: disable Metrics/PerceivedComplexity
|
||||
# rubocop: disable Metrics/CyclomaticComplexity
|
||||
def bind_with_invoice
|
||||
return if binded?
|
||||
registrar = Registrar.find_by(reference_no: reference_no)
|
||||
return unless registrar
|
||||
|
||||
match = description.match(/^[^\d]*(\d+)/)
|
||||
return unless match
|
||||
|
||||
invoice_id = match[1].to_i
|
||||
return unless invoice_id
|
||||
|
||||
invoice = registrar.invoices.find_by(id: invoice_id)
|
||||
return unless invoice
|
||||
|
||||
return if invoice.sum != sum
|
||||
create_account_activity(
|
||||
account: registrar.cash_account,
|
||||
invoice: invoice,
|
||||
sum: sum,
|
||||
currency: currency
|
||||
)
|
||||
end
|
||||
# rubocop: enable Metrics/PerceivedComplexity
|
||||
# rubocop: enable Metrics/CyclomaticComplexity
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue