Reduce complexity of autobindable?() conditional

This commit is contained in:
Karl Erik Õunapuu 2020-09-07 17:06:36 +03:00
parent be960457e6
commit 5991ea6be7
No known key found for this signature in database
GPG key ID: C9DD647298A34764
2 changed files with 8 additions and 11 deletions

View file

@ -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

View file

@ -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,