Skip to content

Commit

Permalink
[FIX] if a transaction_id is set on an invoice, propagate it to the p…
Browse files Browse the repository at this point in the history
…ayment move line
  • Loading branch information
Cedric-Pigeon committed Sep 30, 2019
1 parent 7467675 commit bd43501
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
11 changes: 11 additions & 0 deletions base_transaction_id/models/account_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,22 @@ class AccountPayment(models.Model):
help="Transaction id from the financial institute"
)

invoice_ids = fields.Many2many(inverse='_inverse_invoice_ids')

@api.multi
def _get_liquidity_move_line_vals(self, amount):
self.ensure_one()
vals = super(AccountPayment, self)._get_liquidity_move_line_vals(
amount)
if self.transaction_id:
vals['name'] = self.transaction_id
vals['transaction_ref'] = self.transaction_id
return vals

@api.multi
def _inverse_invoice_ids(self):
for rec in self:
invoices = rec.invoice_ids.filtered(lambda x: x.transaction_id)
if not rec.transaction_id and invoices:
rec.transaction_id = ", ".join(invoices.mapped(
'transaction_id'))
64 changes: 64 additions & 0 deletions base_transaction_id/tests/test_account_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import odoo.tests.common as common
from odoo import fields


class TestAccountPayment(common.TransactionCase):
Expand All @@ -24,3 +25,66 @@ def test_transaction_id_on_move_line(self):
'transaction id',
'The name of the move line is the transaction if of the payment '
'if specified on the payment')
self.assertEqual(
vals.get('transaction_ref'),
'transaction id',
'The transaction reference of the move line is the transaction if '
'of the payment '
'if specified on the payment')

def test_transaction_id_from_invoice(self):
transaction_ref = '1234568787'
tax = self.env['account.tax'].create({
'name': 'Tax 10.0',
'amount': 10.0,
'amount_type': 'fixed',
})

# Should be changed by automatic on_change later
invoice_account = self.env['account.account'].search(
[('user_type_id', '=',
self.env.ref('account.data_account_type_receivable').id)],
limit=1).id
invoice_line_account = self.env['account.account'].search(
[('user_type_id', '=',
self.env.ref('account.data_account_type_expenses').id)],
limit=1).id

invoice = self.env['account.invoice'].create(
{'partner_id': self.env.ref('base.res_partner_2').id,
'account_id': invoice_account,
'type': 'out_invoice',
'transaction_id': transaction_ref})

self.env['account.invoice.line'].create(
{'product_id': self.env.ref('product.product_product_4').id,
'quantity': 1.0,
'price_unit': 100.0,
'invoice_id': invoice.id,
'name': 'product that cost 100',
'account_id': invoice_line_account,
'invoice_line_tax_ids': [(6, 0, [tax.id])]})

# change the state of invoice to open by clicking Validate button
invoice.action_invoice_open()

journal = self.env['account.journal'].search([('type', '=', 'bank')],
limit=1)
payment = self.env['account.payment'].create({
'invoice_ids': [(6, 0, invoice.ids)],
'amount': invoice.residual,
'payment_date': fields.Date.today(),
'communication': invoice.reference or invoice.number,
'partner_id': invoice.partner_id.id,
'partner_type': 'customer',
'journal_id': journal.id,
'payment_method_id': self.env.ref(
'account.account_payment_method_manual_in').id,
'payment_type': 'inbound'})
payment.post()

self.assertEqual(invoice.state, 'paid')

move_line = invoice.payment_ids.move_line_ids.filtered(
lambda x: x.account_id.internal_type == 'liquidity')
self.assertEqual(move_line.transaction_ref, transaction_ref)

0 comments on commit bd43501

Please sign in to comment.