mirror of
https://github.com/internetee/registry.git
synced 2025-06-08 05:34:46 +02:00
Reduce complexity of autobindable?() conditional
This commit is contained in:
parent
be960457e6
commit
5991ea6be7
2 changed files with 8 additions and 11 deletions
|
@ -32,12 +32,9 @@ class BankTransaction < ApplicationRecord
|
|||
end
|
||||
|
||||
def autobindable?
|
||||
return false if binded?
|
||||
return false unless registrar
|
||||
return false unless invoice
|
||||
return false unless invoice.payable?
|
||||
|
||||
true
|
||||
binded? && registrar.present && invoice.payable? ? true : false
|
||||
rescue NoMethodError
|
||||
false
|
||||
end
|
||||
|
||||
# For successful binding, reference number, invoice id and sum must match with the invoice
|
||||
|
@ -113,6 +110,10 @@ class BankTransaction < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def parsed_ref_number
|
||||
reference_no || ref_number_from_description
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def reset_pending_registrar_balance_reload
|
||||
|
@ -122,10 +123,6 @@ class BankTransaction < ApplicationRecord
|
|||
registrar.save!
|
||||
end
|
||||
|
||||
def parsed_ref_number
|
||||
reference_no || ref_number_from_description
|
||||
end
|
||||
|
||||
def ref_number_from_description
|
||||
/(\d{7})/.match(description)[0]
|
||||
end
|
||||
|
|
|
@ -113,7 +113,7 @@ class Invoice < ApplicationRecord
|
|||
end
|
||||
|
||||
def self.create_from_transaction!(transaction)
|
||||
registrar_user = Registrar.find_by(reference_no: transasction.parsed_ref_number)
|
||||
registrar_user = Registrar.find_by(reference_no: transaction.parsed_ref_number)
|
||||
return unless registrar_user
|
||||
|
||||
registrar_user.issue_prepayment_invoice(amount: transaction.sum,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue