From 85ced0e14f7a3f73eb4e5b996e2fd110feb08111 Mon Sep 17 00:00:00 2001 From: eLBati Date: Mon, 2 May 2022 11:57:40 +0200 Subject: [PATCH] FIX l10n_it_fatturapa_in, Setting Italian timezone by default, otherwise e_invoice_received_date could be set the day before of the actual date Example: receiving date = 2022-04-01 00:16 saved in DB, UTC format, as 2022-03-31 22:16:03 converted to date = 2022-03-31 In this case, the invoice would be registered in the wrong period (month) --- .../wizard/wizard_import_fatturapa.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py b/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py index bad3b4a7fccb..68e5ae86c105 100644 --- a/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py +++ b/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py @@ -1156,7 +1156,22 @@ def _prepare_invoice_values(self, fatt, fatturapa_attachment, FatturaBody, partn if causLst: for rel_doc in causLst: comment += rel_doc + "\n" - e_invoice_received_date = self._get_received_date(fatturapa_attachment) + + if ( + not fatturapa_attachment.env.context.get("tz") + and not fatturapa_attachment.env.user.tz + ): + # Setting Italian timezone, otherwise e_invoice_received_date + # could be set the day before of the actual date. + fatturapa_attachment = fatturapa_attachment.with_context(tz="Europe/Rome") + if fatturapa_attachment.e_invoice_received_date: + e_invoice_received_date = fields.Datetime.context_timestamp( + fatturapa_attachment, fatturapa_attachment.e_invoice_received_date + ).date() + else: + e_invoice_received_date = fields.Datetime.context_timestamp( + fatturapa_attachment, fatturapa_attachment.create_date + ).date() e_invoice_date = datetime.strptime( FatturaBody.DatiGenerali.DatiGeneraliDocumento.Data, "%Y-%m-%d" ).date()