From 67f3814a06d0c17b3dbcd7e50ccaaaef106a21e4 Mon Sep 17 00:00:00 2001 From: Eric Antones Date: Sun, 22 Mar 2026 23:57:20 +0100 Subject: [PATCH 1/2] [FIX] account_invoice_same_accounting_date: override _get_accounting_date Override _get_accounting_date instead of adding a separate onchange handler. For purchase documents, route through super's sale document branch (via a scoped context flag on is_sale_document) which applies the tax lock date check and returns invoice_date directly, without the max(invoice_date, today) logic that prevents proper currency recomputation. This lets the core _onchange_invoice_date detect the date change and call _onchange_currency, which recomputes all line debit/credit at the correct exchange rate. The previous _onchange_invoice_date_accounting set date = invoice_date without triggering line recomputations, causing base and tax lines to use different exchange rates on multi-currency invoices. --- .../models/account_move.py | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/account_invoice_same_accounting_date/models/account_move.py b/account_invoice_same_accounting_date/models/account_move.py index 786778705..17743e846 100644 --- a/account_invoice_same_accounting_date/models/account_move.py +++ b/account_invoice_same_accounting_date/models/account_move.py @@ -2,13 +2,27 @@ # Eric Antones # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) - -from odoo import api, models +from odoo import models class AccountMove(models.Model): _inherit = "account.move" - @api.onchange("invoice_date") - def _onchange_invoice_date_accounting(self): - self.date = self.invoice_date + def _get_accounting_date(self, invoice_date, has_tax): + # For purchase documents, we want the same behavior as sale documents + # in super: apply the tax lock date check and return invoice_date + # (instead of max(invoice_date, today) which is the purchase default). + # The simpler approach would be to duplicate the tax lock date check + # from super, but we prefer not to duplicate code. Instead, we + # temporarily flag the context so is_sale_document() returns True + # during this specific super call, making it take the sale branch + # which does exactly what we need. The flag is scoped to this call + # only and does not affect any other use of is_sale_document(). + if self.is_purchase_document(include_receipts=True) and invoice_date: + self = self.with_context(_force_invoice_accounting_date=True) + return super(AccountMove, self)._get_accounting_date(invoice_date, has_tax) + + def is_sale_document(self, include_receipts=False): + if self._context.get("_force_invoice_accounting_date"): + return True + return super().is_sale_document(include_receipts=include_receipts) From 93f60bfc110f9373ed7b84580397b24b33472412 Mon Sep 17 00:00:00 2001 From: Eric Antones Date: Sun, 22 Mar 2026 23:57:26 +0100 Subject: [PATCH 2/2] [FIX] account_invoice_same_accounting_date_prorate: override _onchange_invoice_date Override _onchange_invoice_date via super instead of adding a separate onchange handler. This guarantees execution order: core runs first (setting the correct date and recomputing currency), then prorate recomputes taxes if needed. The previous separate onchange had no guaranteed execution order relative to the core handler. Also add a guard to only run the full tax recomputation when the invoice has taxes with prorate=True. Previously this ran unconditionally on every invoice. --- .../models/account_move.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/account_invoice_same_accounting_date_prorate/models/account_move.py b/account_invoice_same_accounting_date_prorate/models/account_move.py index 59b80a6e6..3a6497ef5 100644 --- a/account_invoice_same_accounting_date_prorate/models/account_move.py +++ b/account_invoice_same_accounting_date_prorate/models/account_move.py @@ -2,16 +2,16 @@ # Eric Antones # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) - from odoo import api, models class AccountMove(models.Model): _inherit = "account.move" - @api.onchange("invoice_date") - def _onchange_invoice_date_accounting(self): - super()._onchange_invoice_date_accounting() - self._recompute_dynamic_lines( - recompute_all_taxes=True, recompute_tax_base_amount=True - ) + @api.onchange("invoice_date", "highest_name", "company_id") + def _onchange_invoice_date(self): + super()._onchange_invoice_date() + if self.line_ids.tax_ids.filtered("prorate"): + self._recompute_dynamic_lines( + recompute_all_taxes=True, recompute_tax_base_amount=True + )