From db85eaab14680eaca6ec1d3fd9bcf9bb66d97729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9lande=20Adrien?= Date: Thu, 7 Mar 2019 15:29:26 +0100 Subject: [PATCH] [caissedepargne/cenet] rectified transaction type The transaction types are retrieved according to the `TypeMouvement` key given by the API. But this key return the same value for card, check and other transactions. So the `TypeOperationDisplay` key is more precise. But sometimes it sents the same value for order and transfer despite the label telling the opposite. So now, the label is looked at first to determine the type, then if nothing is found, the API key is used. Closes: 9744@zendesk --- modules/caissedepargne/cenet/pages.py | 34 ++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/modules/caissedepargne/cenet/pages.py b/modules/caissedepargne/cenet/pages.py index 145dcf0451..def03cdd2c 100644 --- a/modules/caissedepargne/cenet/pages.py +++ b/modules/caissedepargne/cenet/pages.py @@ -168,11 +168,22 @@ def reword_dates(card): return cards class CenetAccountHistoryPage(LoggedPage, CenetJsonPage): - TR_TYPES = {8: Transaction.TYPE_TRANSFER, # VIR - 7: Transaction.TYPE_TRANSFER, # VIR COMPTE A COMPTE - 6: Transaction.TYPE_CASH_DEPOSIT, # REMISE CHEQUE(s) - 4: Transaction.TYPE_ORDER # PRELV - } + TR_TYPES_LABEL = { + 'VIR': Transaction.TYPE_TRANSFER, + 'CHEQUE': Transaction.TYPE_CHECK, + 'REMISE CHEQUE': Transaction.TYPE_CASH_DEPOSIT, + 'PRLV': Transaction.TYPE_ORDER, + 'CB': Transaction.TYPE_CARD + } + + TR_TYPES_API = { + 'VIR': Transaction.TYPE_TRANSFER, + 'PE': Transaction.TYPE_ORDER, # PRLV + 'CE': Transaction.TYPE_CHECK, # CHEQUE + 'CB': Transaction.TYPE_CARD, + 'DE': Transaction.TYPE_CASH_DEPOSIT, # APPRO + 'PI': Transaction.TYPE_CASH_DEPOSIT, # REMISE CHEQUE + } @method class get_history(DictElement): @@ -187,7 +198,18 @@ class item(ItemElement): obj_rdate = Date(Dict('DateGroupReglement'), dayfirst=True) def obj_type(self): - ret = self.page.TR_TYPES.get(Dict('TypeMouvement')(self), Transaction.TYPE_UNKNOWN) + ret = Transaction.TYPE_UNKNOWN + + # The API may send the same key for 'PRLV' and 'VIR' transactions + # So the label is checked first, then the API key + for k, v in self.page.TR_TYPES_LABEL.items(): + if Field('label')(self).startswith(k): + ret = v + break + + if ret == Transaction.TYPE_UNKNOWN: + ret = self.page.TR_TYPES_API.get(Dict('TypeOperationDisplay')(self), Transaction.TYPE_UNKNOWN) + if ret != Transaction.TYPE_UNKNOWN: return ret -- GitLab