mirror of
https://github.com/internetee/registry.git
synced 2025-06-08 13:44:47 +02:00
Merge pull request #1450 from internetee/1415-improve-bank-proceeeds-autocheck
Add autocheck by reference number in field or in description
This commit is contained in:
commit
704c331f03
5 changed files with 30 additions and 22 deletions
|
@ -16,22 +16,12 @@ class BankTransaction < ApplicationRecord
|
||||||
account_activity.invoice
|
account_activity.invoice
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def invoice_num
|
|
||||||
return @invoice_no if defined?(@invoice_no)
|
|
||||||
|
|
||||||
match = description.match(/^[^\d]*(\d+)/)
|
|
||||||
return unless match
|
|
||||||
|
|
||||||
@invoice_no = match[1].try(:to_i)
|
|
||||||
end
|
|
||||||
|
|
||||||
def invoice
|
def invoice
|
||||||
@invoice ||= registrar.invoices.find_by(number: invoice_num) if registrar
|
@invoice ||= registrar.invoices.find_by(total: sum) if registrar
|
||||||
end
|
end
|
||||||
|
|
||||||
def registrar
|
def registrar
|
||||||
@registrar ||= Invoice.find_by(reference_no: reference_no)&.buyer
|
@registrar ||= Invoice.find_by(reference_no: parsed_ref_number)&.buyer
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,11 +29,9 @@ class BankTransaction < ApplicationRecord
|
||||||
def autobind_invoice
|
def autobind_invoice
|
||||||
return if binded?
|
return if binded?
|
||||||
return unless registrar
|
return unless registrar
|
||||||
return unless invoice_num
|
|
||||||
return unless invoice
|
return unless invoice
|
||||||
return unless invoice.payable?
|
return unless invoice.payable?
|
||||||
|
|
||||||
return if invoice.total != sum
|
|
||||||
create_activity(registrar, invoice)
|
create_activity(registrar, invoice)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -98,4 +86,12 @@ class BankTransaction < ApplicationRecord
|
||||||
registrar.settings['balance_auto_reload'].delete('pending')
|
registrar.settings['balance_auto_reload'].delete('pending')
|
||||||
registrar.save!
|
registrar.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def parsed_ref_number
|
||||||
|
reference_no || ref_number_from_description
|
||||||
|
end
|
||||||
|
|
||||||
|
def ref_number_from_description
|
||||||
|
/(\d{7})/.match(description)[0]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
2
test/fixtures/bank_transactions.yml
vendored
2
test/fixtures/bank_transactions.yml
vendored
|
@ -1,5 +1,5 @@
|
||||||
one:
|
one:
|
||||||
sum: 1
|
sum: 1
|
||||||
currency: EUR
|
currency: EUR
|
||||||
description: Order nr. 1
|
description: Order nr 1 from registrar 1234567 second number 2345678
|
||||||
iban: US75512108001245126199
|
iban: US75512108001245126199
|
1
test/fixtures/invoices.yml
vendored
1
test/fixtures/invoices.yml
vendored
|
@ -23,3 +23,4 @@ one:
|
||||||
total: 16.50
|
total: 16.50
|
||||||
reference_no: 13
|
reference_no: 13
|
||||||
number: 1
|
number: 1
|
||||||
|
description: Order nr 1 from registrar 1234567 second number 2345678
|
||||||
|
|
|
@ -28,7 +28,7 @@ class PaymentCallbackTest < ApplicationIntegrationTest
|
||||||
|
|
||||||
def assert_matching_bank_transaction_exists(invoice)
|
def assert_matching_bank_transaction_exists(invoice)
|
||||||
assert BankTransaction.find_by(
|
assert BankTransaction.find_by(
|
||||||
description: invoice.order,
|
description: invoice.description,
|
||||||
currency: invoice.currency,
|
currency: invoice.currency,
|
||||||
iban: invoice.seller_iban
|
iban: invoice.seller_iban
|
||||||
), 'Matching bank transaction should exist'
|
), 'Matching bank transaction should exist'
|
||||||
|
|
|
@ -6,9 +6,20 @@ class BankTransactionTest < ActiveSupport::TestCase
|
||||||
@invoice = invoices(:one)
|
@invoice = invoices(:one)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_matches_against_invoice_number_and_reference_number
|
def test_matches_against_invoice_nubmber_and_reference_number
|
||||||
create_payable_invoice(number: '2222', total: 10, reference_no: '1111')
|
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
|
||||||
transaction = BankTransaction.new(description: 'invoice #2222', sum: 10, reference_no: '1111')
|
transaction = BankTransaction.new(description: 'invoice #2222', sum: 10, reference_no: '1234567')
|
||||||
|
|
||||||
|
assert_difference 'AccountActivity.count' do
|
||||||
|
transaction.autobind_invoice
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_matches_against_invoice_nubmber_and_reference_number_in_description
|
||||||
|
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
|
||||||
|
transaction = BankTransaction.new(description: 'invoice #2222',
|
||||||
|
sum: 10,
|
||||||
|
description: 'Order nr 1 from registrar 1234567 second number 2345678')
|
||||||
|
|
||||||
assert_difference 'AccountActivity.count' do
|
assert_difference 'AccountActivity.count' do
|
||||||
transaction.autobind_invoice
|
transaction.autobind_invoice
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue