From 0246887f7b51c8bb501f41df35b3c8a40d04b22d Mon Sep 17 00:00:00 2001 From: Wolfgang Taferner Date: Tue, 13 Nov 2018 13:37:22 +0000 Subject: [PATCH] [FIX] account: wrong default journal based on type available in vals As the journal is mostly set in the Odoo world the _default_journal method is not needed during create, but in case you only have partner_id, account_id and type in vals you will have retrieved a wrong journal in case you have an incoming invoice. closes odoo/odoo#28635 --- addons/account/models/account_invoice.py | 3 +++ addons/account/tests/test_account_supplier_invoice.py | 2 ++ 2 files changed, 5 insertions(+) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 1bb091cd849..0da8e8c51e8 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -447,6 +447,9 @@ class AccountInvoice(models.Model): @api.model def create(self, vals): + if not vals.get('journal_id') and vals.get('type'): + vals['journal_id'] = self.with_context(type=vals.get('type'))._default_journal().id + onchanges = { '_onchange_partner_id': ['account_id', 'payment_term_id', 'fiscal_position_id', 'partner_bank_id'], '_onchange_journal_id': ['currency_id'], diff --git a/addons/account/tests/test_account_supplier_invoice.py b/addons/account/tests/test_account_supplier_invoice.py index 357ac04f8f2..e28a4b4f893 100644 --- a/addons/account/tests/test_account_supplier_invoice.py +++ b/addons/account/tests/test_account_supplier_invoice.py @@ -21,6 +21,7 @@ class TestAccountSupplierInvoice(AccountingTestCase): 'account_id': invoice_account, 'type': 'in_invoice', }) + self.assertEquals(invoice.journal_id.type, 'purchase') self.env['account.invoice.line'].create({'product_id': self.env.ref('product.product_product_4').id, 'quantity': 1.0, @@ -76,6 +77,7 @@ class TestAccountSupplierInvoice(AccountingTestCase): 'account_id': invoice_account, 'type': 'in_invoice', }) + self.assertEquals(invoice.journal_id.type, 'purchase') invoice_line = self.env['account.invoice.line'].create({'product_id': self.env.ref('product.product_product_4').id, 'quantity': 5.0,