diff options
| author | Damien Bouvy <dbo@odoo.com> | 2020-04-07 14:31:17 +0000 |
|---|---|---|
| committer | Damien Bouvy <dbo@odoo.com> | 2020-04-09 14:07:06 +0000 |
| commit | 43caac96ffbe77ee6b726d2bdaca917dc38e9128 (patch) | |
| tree | 8dd68f69833de59d00e84de8b793a357e415a5d6 | |
| parent | ed38c2adb85a7cb62fda4c2db21a3cad9d84a420 (diff) | |
[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>
| -rw-r--r-- | addons/payment_sips/models/payment.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/addons/payment_sips/models/payment.py b/addons/payment_sips/models/payment.py index 4c49c2a4f33..bc44b5c68b0 100644 --- a/addons/payment_sips/models/payment.py +++ b/addons/payment_sips/models/payment.py @@ -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: |
