[FIX] l10n_sa_edi: comparing invoice date to be aware with timezone
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
@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.
Merge method set to rebase and fast-forward.
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 @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
@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
@kerbrose I did it for you here: https://github.com/odoo/odoo/pull/157010
FYI: https://github.com/odoo/odoo/pull/156991
