mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +02:00
Merge pull request #2075 from internetee/1788-undefined-method-for-invoice-binding
fix bind_invoice method
This commit is contained in:
commit
ed65989dbe
2 changed files with 11 additions and 1 deletions
|
@ -59,7 +59,6 @@ class BankTransaction < ApplicationRecord
|
|||
end
|
||||
|
||||
invoice = Invoice.find_by(number: invoice_no)
|
||||
errors.add(:base, I18n.t('invoice_was_not_found')) unless invoice
|
||||
validate_invoice_data(invoice)
|
||||
return if errors.any?
|
||||
|
||||
|
@ -68,6 +67,11 @@ class BankTransaction < ApplicationRecord
|
|||
end
|
||||
|
||||
def validate_invoice_data(invoice)
|
||||
unless invoice
|
||||
errors.add(:base, I18n.t('invoice_was_not_found'))
|
||||
return
|
||||
end
|
||||
|
||||
if invoice.paid?
|
||||
errors.add(:base, I18n.t('invoice_is_already_binded'))
|
||||
return
|
||||
|
|
|
@ -136,6 +136,12 @@ class BankTransactionTest < ActiveSupport::TestCase
|
|||
assert transaction.errors.full_messages.include?('Invoice and transaction sums do not match')
|
||||
end
|
||||
|
||||
def test_binds_without_invoice_no
|
||||
transaction = BankTransaction.new(sum: 9)
|
||||
transaction.bind_invoice('')
|
||||
assert transaction.errors.full_messages.include?('Invoice was not found')
|
||||
end
|
||||
|
||||
def test_overpayment_is_not_matched_with_invoice
|
||||
create_payable_invoice(number: '2222', total: 10)
|
||||
transaction = BankTransaction.new(sum: 11)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue