Skip to content

Commit

Permalink
[Fix #25] Fixing validation date offset
Browse files Browse the repository at this point in the history
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
Warlocklogan committed Dec 6, 2023
1 parent 8a8cccd commit 68b7dc8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion payment_payfip/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
'name': "Intermédiaire de paiement PayFIP",
'version': '11.0.22.02.25',
'version': '11.0.22.08.16',
'summary': """Intermédiaire de paiement : Implémentation de PayFIP""",
'author': "Horanet",
'website': "http://www.horanet.com/",
Expand Down
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 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)
# 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.")
5 changes: 3 additions & 2 deletions payment_payfip/models/inherited_payment_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ def _payfip_evaluate_data(self, data=False):
minute = int(payfip_datetime[2:4])
payfip_tz = pytz.timezone('Europe/Paris')
td_minute = timedelta(minutes=1)
date_validate = fields.Datetime.to_string(
# localize validation datetime into utc datetime string format
date_validate = fields.Datetime.to_string(payfip_tz.localize(
datetime(year, month, day, hour=hour, minute=minute, tzinfo=payfip_tz) + td_minute
)
).astimezone(pytz.UTC))

self.write({
'state': 'done',
Expand Down

0 comments on commit 68b7dc8

Please sign in to comment.