-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix #25] Fixing validation date offset
Currently, validation dates on transactions are stored in the French timezone, but in Odoo the timezone is expected to be in UTC. A minor fix is needed in the _payfip_evaluate_data method to convert the timezone into a UTC one. Migrate all previous dates validations to fix the timezone issue. All transactions are processed in chunk of one hundred. Signed-off-by: Logan Gonet <[email protected]>
- Loading branch information
1 parent
f69ca67
commit 368d37e
Showing
3 changed files
with
92 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...yfip/controllers/migrations/13.0.24.12.31/pre-french-tz-to-utc-payfip-transaction-date.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import logging | ||
import pytz | ||
|
||
from openupgradelib import openupgrade | ||
|
||
from odoo import fields | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
@openupgrade.migrate(use_env=True) | ||
def migrate(env, version): | ||
"""Migrate Payfip transaction confirmation date to UTC date instead of french timezone.""" | ||
# Payfip timezone | ||
payfip_tz = pytz.timezone('Europe/Paris') | ||
# Retreive all payfip transaction with a confirmation date | ||
payfip_transactions = env['payment.transaction'].search( | ||
[ | ||
('acquirer_id.provider', '=', 'payfip'), | ||
('date_validate', '!=', False), | ||
] | ||
) | ||
|
||
_logger.info(f"Number of Payfip transaction to migrate : {len(payfip_transactions)}") | ||
chunk_size = 100 | ||
# Chunk transactions for processing | ||
payfip_transactions_chunked = [ | ||
payfip_transactions[i : i + chunk_size] for i in range(0, len(payfip_transactions), chunk_size) | ||
] | ||
|
||
for idx, payfip_transaction_chunk in enumerate(payfip_transactions_chunked, start=1): | ||
_logger.info(f"Payfip transaction processing chunk : {idx}/{len(payfip_transactions_chunked)}") | ||
for payfip_transaction in payfip_transaction_chunk: | ||
# Validate date to datetime object | ||
date_validate = fields.Datetime.from_string(payfip_transaction.date_validate) | ||
# Localize datetime and transform into an UTC one | ||
utc_date_validate = payfip_tz.localize(date_validate).astimezone(pytz.UTC).replace(tzinfo=None) | ||
# Set UTC value into datetime | ||
payfip_transaction.date_validate = utc_date_validate | ||
_logger.info(f"Payfip transaction all chunks have been processed.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters