Fix parsing from ref number

This commit is contained in:
Karl Erik Õunapuu 2020-09-10 16:38:27 +03:00
parent 18aa7e3d63
commit 8a5208057a
No known key found for this signature in database
GPG key ID: C9DD647298A34764
2 changed files with 6 additions and 7 deletions

View file

@ -118,12 +118,11 @@ class BankTransaction < ApplicationRecord
end end
def ref_number_from_description def ref_number_from_description
(Billing::ReferenceNo::MULTI_REGEXP.match(description) || []).captures.each do |match| matches = description.to_s.scan(Billing::ReferenceNo::MULTI_REGEXP).flatten
break match if match.length == 7 || valid_ref_no?(match) matches.detect { |m| break m if m.length == 7 || valid_ref_no?(m) }
end
end end
def valid_ref_no?(match) def valid_ref_no?(match)
return true if Billing::ReferenceNo.valid?(match) && Registrar.find_by(reference_no: match).any? return true if Billing::ReferenceNo.valid?(match) && Registrar.find_by(reference_no: match)
end end
end end

View file

@ -136,8 +136,8 @@ class InvoiceTest < ActiveSupport::TestCase
transaction.reference_no = registrar.reference_no transaction.reference_no = registrar.reference_no
transaction.sum = 250 transaction.sum = 250
assert_emails 1 do
Invoice.create_from_transaction!(transaction) Invoice.create_from_transaction!(transaction)
end
assert_emails 1
end end
end end