From c3a91730484693b3a7a6bc718397abe37bd5fb54 Mon Sep 17 00:00:00 2001 From: mebe-odoo Date: Thu, 29 Feb 2024 06:35:47 +0000 Subject: [PATCH] [FIX] l10n_sa_edi: fix discrepencies in invoice date checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When trying to process invoices at a time close to Midnight, and the user is using the system from a location different from the hosting location of Odoo, the system tries to check that the date of the invoice is the same as the current date of the system. This creates problems when the hosting server's timezone is different than that of the user. For example: If the hosting location is in Middle East (India), and the user is using Odoo from Saudi Arabia, there is a difference of 2.5 hours due to the timezone, so when the system creates the Invoice at 11 PM and tries to check the date, the date of the server is actually 29th of February, 11 PM while the date on the user's machine is 1st of March, 01:30 AM, which triggers a UserError from the _check_move_configuration function. closes odoo/odoo#157144 X-original-commit: 601c8b8a0b4aff44811fd37f365cc62205cf96f0 Signed-off-by: William André (wan) Signed-off-by: Florian Gilbert (flg) Signed-off-by: Josse Colpaert --- addons/l10n_sa_edi/models/account_edi_format.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/l10n_sa_edi/models/account_edi_format.py b/addons/l10n_sa_edi/models/account_edi_format.py index 5ca2c3186aa..8a9bb08006c 100644 --- a/addons/l10n_sa_edi/models/account_edi_format.py +++ b/addons/l10n_sa_edi/models/account_edi_format.py @@ -2,7 +2,7 @@ import json from hashlib import sha256 from base64 import b64decode, b64encode from lxml import etree -from datetime import date, datetime +from datetime import datetime from odoo import models, fields, _, api from odoo.exceptions import UserError from cryptography.hazmat.primitives.serialization import load_pem_private_key @@ -435,7 +435,7 @@ class AccountEdiFormat(models.Model): errors.append(_set_missing_partner_fields(supplier_missing_info, _("Supplier"))) if customer_missing_info: errors.append(_set_missing_partner_fields(customer_missing_info, _("Customer"))) - if invoice.invoice_date > date.today(): + if invoice.invoice_date > fields.Date.context_today(self.with_context(tz='Asia/Riyadh')): errors.append(_("- Please, make sure the invoice date is set to either the same as or before Today.")) if invoice.move_type in ('in_refund', 'out_refund') and not invoice._l10n_sa_check_refund_reason(): errors.append(