odoo icon indicating copy to clipboard operation
odoo copied to clipboard

[FIX] l10n_sa_edi: comparing invoice date to be aware with timezone

Open kerbrose opened this issue 1 year ago • 2 comments

Steps to reproduce

  • install l10n_sa_edi
  • switch to a Saudi company
  • make sure user timezone is Asia/Riyadh
  • create and post an invoice between these time from 12:00 to 3:00

Cause

EDI Invoice could be validated

closes odoo/odoo#155363

Description of the issue/feature this PR addresses:

Current behavior before PR:

Desired behavior after PR is merged:


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

kerbrose avatar Feb 29 '24 13:02 kerbrose

Pull request status dashboard.

robodoo avatar Feb 29 '24 13:02 robodoo

@FlorianGilbert

probably, I did a mistake so I accidentally closed the original pull request (https://github.com/odoo/odoo/pull/155365). so I made a new one.

kerbrose avatar Feb 29 '24 13:02 kerbrose

Merge method set to rebase and fast-forward.

robodoo avatar Mar 04 '24 08:03 robodoo

Hello @FlorianGilbert I did a mistake regarding this code snippet. it should be as following:

# localizing invoice date to utc date
user_timezone = pytz.timezone(self.env.user.tz or "utc")
invoice_datetime = datetime.combine(invoice.invoice_date, datetime.min.time())
user_invoice_datetime = user_timezone.localize(invoice_datetime)
invoice_date_utc = user_invoice_datetime.astimezone(pytz.timezone('utc'))
# We should compare dates instead of datetime. as it will result in inequalities.
if invoice_date_utc.date() > date.today():

I should kept comparing just dates as before however the corrected one instead of using datetime which is comparing seconds as well. so shall I make a new pull request?

kerbrose avatar Mar 05 '24 09:03 kerbrose

Hello @FlorianGilbert I did a mistake regarding this code snippet. it should be as following:

# localizing invoice date to utc date
user_timezone = pytz.timezone(self.env.user.tz or "utc")
invoice_datetime = datetime.combine(invoice.invoice_date, datetime.min.time())
user_invoice_datetime = user_timezone.localize(invoice_datetime)
invoice_date_utc = user_invoice_datetime.astimezone(pytz.timezone('utc'))
# We should compare dates instead of datetime. as it will result in inequalities.
if invoice_date_utc.date() > date.today():

I should kept comparing just dates as before however the corrected one instead of using datetime which is comparing seconds as well. so shall I make a new pull request?

Hello @kerbrose Yes please, we'll merge it in 16.0, I'll do the change in forward port :)

Thank you

FlorianGilbert avatar Mar 05 '24 16:03 FlorianGilbert

@kerbrose @FlorianGilbert this pull request has forward-port PRs awaiting action (not merged or closed):

  • odoo/odoo#156282
  • odoo/odoo#156304
  • odoo/odoo#156322
  • odoo/odoo#156342
  • odoo/odoo#156354

fw-bot avatar Mar 08 '24 05:03 fw-bot

@kerbrose I did it for you here: https://github.com/odoo/odoo/pull/157010

FlorianGilbert avatar Mar 08 '24 06:03 FlorianGilbert

FYI: https://github.com/odoo/odoo/pull/156991

FlorianGilbert avatar Mar 08 '24 09:03 FlorianGilbert