[FIX] l10n_it_stock_ddt: fix comparing date and datetime

Field 'date_done' is a datetime object and field 'invoice_date' is a date
object. They will be considered as different even if the 'date' part is
the same which is the opposite required to check if invoice is direct.

>>> ddt.date_done
datetime.datetime(2023, 7, 11, 10, 2, 56)
>>> invoice.invoice_date
datetime.date(2023, 7, 11)
>>> ddt.date_done != invoice.invoice_date
True

This fix casts 'date_done' into a date object before comparison.

>>> ddt.date_done.date() != invoice.invoice_date
False

opw-3571327

closes odoo/odoo#140538

X-original-commit: 87a6f398e2047b4739e27be28e75399c2ddd717f
Signed-off-by: John Laterre (jol) <jol@odoo.com>
This commit is contained in:
Thomas Beckers
2023-11-07 17:57:13 +00:00
parent 542b3b97ed
commit 1c83d4f41b
@@ -24,7 +24,7 @@ class AccountMove(models.Model):
def _l10n_it_edi_invoice_is_direct(self):
""" An invoice is only direct if the Transport Documents are all done the same day as the invoice. """
for ddt in self.l10n_it_ddt_ids:
if not ddt.date_done or ddt.date_done != self.invoice_date:
if not ddt.date_done or ddt.date_done.date() != self.invoice_date:
return False
return True