[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
This commit is contained in:
Wolfgang Taferner
2018-11-13 16:20:42 +00:00
parent 4e37ce8855
commit 0246887f7b
2 changed files with 5 additions and 0 deletions
+3
View File
@@ -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'],
@@ -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,