[FIX] payment_sips: datetime parsing

SIPS date format can be somewhat variable, some sanitation is required
before using the data raw for the ORM.

opw-2224926

X-original-commit: 620e987f326d6da7c3a9b2c1aca7bff16d9ce6c4
Co-authored-by: Nicolas Martinelli <nim@odoo.com>
This commit is contained in:
Damien Bouvy
2020-04-09 14:07:06 +00:00
co-authored by Nicolas Martinelli
parent ed38c2adb8
commit 43caac96ff
+17 -2
View File
@@ -2,8 +2,11 @@
# Copyright 2015 Eezee-It
import datetime
from dateutil import parser
import json
import logging
import pytz
import re
import time
from hashlib import sha256
@@ -182,10 +185,22 @@ class TxSips(models.Model):
def _sips_form_validate(self, data):
data = self._sips_data_to_object(data.get('Data'))
status = data.get('responseCode')
date = data.get('transactionDateTime')
if date:
try:
# dateutil.parser 2.5.3 and up should handle dates formatted as
# '2020-04-08T05:54:18+02:00', which strptime does not
# (+02:00 does not work as %z expects +0200 before Python 3.7)
# See odoo/odoo#49160
date = parser.parse(date).astimezone(pytz.utc).replace(tzinfo=None)
except:
# will fallback on now in the write to avoid failing to
# register the payment because a provider formats their
# dates badly or because some local library is not behaving
date = False
data = {
'acquirer_reference': data.get('transactionReference'),
'date': data.get('transactionDateTime',
fields.Datetime.now())
'date': date or fields.Datetime.now(),
}
res = False
if status in self._sips_valid_tx_status: