diff options
| author | Wolfgang Taferner <wtaferner@users.noreply.github.com> | 2018-11-13 13:37:22 +0000 |
|---|---|---|
| committer | Wolfgang Taferner <wtaferner@users.noreply.github.com> | 2018-11-13 16:20:42 +0000 |
| commit | 0246887f7b51c8bb501f41df35b3c8a40d04b22d (patch) | |
| tree | 49ff706b3b5583bc5d6c28c652ff6316be43a43a | |
| parent | 4e37ce885581a806f1449c874d16b9373b0f4f07 (diff) | |
[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
| -rw-r--r-- | addons/account/models/account_invoice.py | 3 | ||||
| -rw-r--r-- | addons/account/tests/test_account_supplier_invoice.py | 2 |
2 files changed, 5 insertions, 0 deletions
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, |
