diff --git a/modules/cmso/par/browser.py b/modules/cmso/par/browser.py index 334dac567427f5b5e1495c745e97dd9957a09557..868675f94941f857dca3574e27beda323bbe9966 100644 --- a/modules/cmso/par/browser.py +++ b/modules/cmso/par/browser.py @@ -343,29 +343,30 @@ def iter_history(self, account): return sorted_transactions(self.page.iter_history()) # Getting a year of history - nbs = ["UN", "DEUX", "TROIS", "QUATRE", "CINQ", "SIX", "SEPT", "HUIT", "NEUF", "DIX", "ONZE", "DOUZE"] + # We have to finish by "SIX_DERNIERES_SEMAINES" to get in priority the transactions with ids. + # In "SIX_DERNIERES_SEMAINES" you can have duplicates transactions without ids of the previous two months. + nbs = ["DEUX", "TROIS", "QUATRE", "CINQ", "SIX", "SEPT", "HUIT", "NEUF", "DIX", "ONZE", "DOUZE", "SIX_DERNIERES_SEMAINES"] trs = [] self.history.go(data=json.dumps({"index": account._index}), page="pendingListOperations", headers=self.json_headers) has_deferred_cards = self.page.has_deferred_cards() - self.history.go(data=json.dumps({'index': account._index}), page="detailcompte", headers=self.json_headers) - + self.history.go(data=json.dumps({'index': account._index, 'filtreOperationsComptabilisees': "MOIS_MOINS_UN"}), page="detailcompte", headers=self.json_headers) self.trs = set() for tr in self.page.iter_history(index=account._index, nbs=nbs): # Check for duplicates - if tr.id in self.trs: + if tr._operationid in self.trs: continue - self.trs.add(tr.id) + self.trs.add(tr._operationid) if has_deferred_cards and tr.type == Transaction.TYPE_CARD: tr.type = Transaction.TYPE_DEFERRED_CARD tr.bdate = tr.rdate trs.append(tr) - return trs + return sorted_transactions(trs) @retry((ClientError, ServerError)) @need_login diff --git a/modules/cmso/par/pages.py b/modules/cmso/par/pages.py index 9edf44c6cc14d3a30ada8c25006a983c21d02ef9..e6deabc79ac1196f04e435aebe7ee1ff91258c59 100644 --- a/modules/cmso/par/pages.py +++ b/modules/cmso/par/pages.py @@ -392,9 +392,9 @@ def get_keys(self): class iter_history(DictElement): def next_page(self): if len(Env('nbs', default=[])(self)): - data = {'index': Env('index')(self), - 'filtreOperationsComptabilisees': "MOIS_MOINS_%s" % Env('nbs')(self)[0] - } + data = {'index': Env('index')(self)} + if Env('nbs')(self)[0] != "SIX_DERNIERES_SEMAINES": + data.update({'filtreOperationsComptabilisees': "MOIS_MOINS_%s" % Env('nbs')(self)[0]}) Env('nbs')(self).pop(0) return requests.Request('POST', data=json.dumps(data), headers={'Content-Type': 'application/json'}) @@ -432,9 +432,10 @@ def filter(self, timestamp): obj_raw = Transaction.Raw(Dict('libelleCourt')) obj_vdate = Date(Dict('dateValeur', NotAvailable), dayfirst=True, default=NotAvailable) obj_amount = CleanDecimal(Dict('montantEnEuro'), default=NotAvailable) - # DO NOT USE `OperationID` the ids aren't constant after 1 month. `clefDomirama` seems - # to be constant forever. Must be kept under watch though obj_id = Dict('clefDomirama', default='') + # 'operationId' is different between each session, we use it to avoid duplicates on a unique + # session + obj__operationid = Dict('operationId', default='') def parse(self, el): key = Env('key', default=None)(self)