Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions account_invoice_same_accounting_date/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,27 @@
# Eric Antones <eantones@nuobit.com>
# 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)
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
# Eric Antones <eantones@nuobit.com>
# 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
)
Loading