Verify ref_number_from_description return correct match

This commit is contained in:
Karl Erik Õunapuu 2020-09-10 10:44:18 +03:00
parent 166ff44491
commit dd48bb61d9
No known key found for this signature in database
GPG key ID: C9DD647298A34764

View file

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