From e2c819351f519bd6fea1e6f942aa13373b69991c Mon Sep 17 00:00:00 2001 From: "Nathan Marotte (nama)" Date: Tue, 7 Sep 2021 09:40:36 +0000 Subject: [PATCH] [FIX] account move: Due date not updated when invoice_date changed Issue: When changing the bill date (invoice_date) of a vendor bill, the due date (invoice_payment_term_id) is not updated correctly Steps to reproduce : 1) Install Accounting, Purchase 2) Create a vendor bill 3) (debug) Edit the view, remove the invisible attr for the div with label invoice_payment_term_id 4) For the vendor bill, in that order, set the Vendor, then the due date to 30 days, then bill date, then add a product 5) Due date is now set to 30 days after the bill date 6) Change the Bill Date -> Due Date stays unchanged Thanks to @smetl for writing the test ! opw-2627686 closes odoo/odoo#76736 X-original-commit: d15e0a678b021d842b96bce9c8880ed28f7fff77 Signed-off-by: Laurent Smet Signed-off-by: Nathan Marotte --- addons/account/models/account_move.py | 2 ++ .../tests/test_account_move_in_invoice.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) 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: