account_usability: change the behavior of 'date' on in_invoice/in_refund when the 'invoice_date' is changed

This commit is contained in:
Alexis de Lattre
2022-03-08 21:02:55 +01:00
parent f9a7983d71
commit 447b0107be

View File

@@ -6,6 +6,7 @@ from odoo import api, fields, models
from odoo.tools import float_is_zero
from odoo.tools.misc import format_date
from odoo.osv import expression
from datetime import timedelta
class AccountMove(models.Model):
@@ -207,6 +208,18 @@ class AccountMove(models.Model):
self.ensure_one()
return '%s.pdf' % (self.name and self.name.replace('/', '_') or 'INV')
def _get_accounting_date(self, invoice_date, has_tax):
# On vendor bills/refunds, we want date = invoice_date unless
# we have a company tax_lock_date and the invoice has taxes
# and invoice_date <= tax_lock_date
date = super()._get_accounting_date(invoice_date, has_tax)
if self.is_purchase_document(include_receipts=True):
tax_lock_date = self.company_id.tax_lock_date
if invoice_date and tax_lock_date and has_tax and invoice_date <= tax_lock_date:
invoice_date = tax_lock_date + timedelta(days=1)
date = invoice_date
return date
class AccountMoveLine(models.Model):
_inherit = 'account.move.line'