-
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
Actually, validation dates on transactions are stored in the French timezone but in Odoo the timezone attended is UTC. A minor fix is needed in the _payfip_evaluate_data method for passing the timezone into a UTC one. Migrate all previous validation dates to fix the timezone issue. All transactions are processed in chunk of one hundred. Signed-off-by: Logan Gonet <logan.gonet@horanet.com>
- Loading branch information
1 parent
8a8cccd
commit fb6161a
Showing
3 changed files
with
40 additions
and
3 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
36 changes: 36 additions & 0 deletions
36
payment_payfip/migrations/11.0.22.08.16/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,36 @@ | ||
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 tu 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) | ||
# Set UTC value into datetime | ||
payfip_transaction.date_validate = fields.Datetime.to_string(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