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) 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 + )