diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 46340b49d26..335726863d5 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -441,6 +441,8 @@ class AccountMove(models.Model): if accounting_date != self.date: self.date = accounting_date self._onchange_currency() + else: + self._onchange_recompute_dynamic_lines() @api.onchange('journal_id') def _onchange_journal(self): diff --git a/addons/account/tests/test_account_move_in_invoice.py b/addons/account/tests/test_account_move_in_invoice.py index 8c596de1ec4..a7d1da55164 100644 --- a/addons/account/tests/test_account_move_in_invoice.py +++ b/addons/account/tests/test_account_move_in_invoice.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # pylint: disable=bad-whitespace +from freezegun import freeze_time from odoo.addons.account.tests.common import AccountTestInvoicingCommon from odoo.tests.common import Form from odoo.tests import tagged @@ -145,6 +146,22 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): move_form.invoice_date = invoice_date self.assertEqual(self.invoice.date, fields.Date.to_date(accounting_date)) + @freeze_time('2021-09-16') + def test_in_invoice_onchange_invoice_date_2(self): + invoice_form = Form(self.env['account.move'].with_context(default_move_type='in_invoice', account_predictive_bills_disable_prediction=True)) + invoice_form.partner_id = self.partner_a + invoice_form.invoice_payment_term_id = self.env.ref('account.account_payment_term_30days') + with invoice_form.invoice_line_ids.new() as line_form: + line_form.product_id = self.product_a + invoice_form.invoice_date = fields.Date.from_string('2021-09-01') + invoice = invoice_form.save() + + self.assertRecordValues(invoice, [{ + 'date': fields.Date.from_string('2021-09-16'), + 'invoice_date': fields.Date.from_string('2021-09-01'), + 'invoice_date_due': fields.Date.from_string('2021-10-01'), + }]) + def test_in_invoice_line_onchange_product_1(self): move_form = Form(self.invoice) with move_form.invoice_line_ids.edit(0) as line_form: