diff --git a/modules/cmso/par/browser.py b/modules/cmso/par/browser.py index ca67bec0afa0c1b266f353af6c2a3ac149a75a84..e4fd008db957b046af6b6769d7c5286147ed56de 100644 --- a/modules/cmso/par/browser.py +++ b/modules/cmso/par/browser.py @@ -432,16 +432,25 @@ def iter_history(self, account): finally: self._return_from_market() - # Getting a year of history - # 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(json={"index": account._index}, page="pendingListOperations") - has_deferred_cards = self.page.has_deferred_cards() + # 1.fetch the last 6 weeks transactions but keep only the current month ones + # those don't have any id and include 'hier' and 'Plus tôt dans la semaine' + trs = [] + self.history.go( + json={ + 'index': account._index, + 'filtreOperationsComptabilisees': "SIX_DERNIERES_SEMAINES", + }, + page="detailcompte" + ) + for tr in self.page.iter_history(index=account._index, last_trs=True): + trs.append(tr) + + # 2. get the month by month transactions + # and avoid duplicates based on ids + nbs = ["DEUX", "TROIS", "QUATRE", "CINQ", "SIX", "SEPT", "HUIT", "NEUF", "DIX", "ONZE", "DOUZE"] self.history.go( json={ 'index': account._index, @@ -450,7 +459,6 @@ def iter_history(self, account): page="detailcompte" ) self.trs = set() - for tr in self.page.iter_history(index=account._index, nbs=nbs): # Check for duplicates if tr._operationid in self.trs or (tr.id and tr.id in self.trs): diff --git a/modules/cmso/par/pages.py b/modules/cmso/par/pages.py index ce62ecf8e1cd075ee51926446722e0476b63c200..b4a955fa078f97bd313a7a443a6a037db29dc164 100644 --- a/modules/cmso/par/pages.py +++ b/modules/cmso/par/pages.py @@ -409,9 +409,8 @@ class iter_history(DictElement): def next_page(self): if len(Env('nbs', default=[])(self)): 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) + next_month = Env('nbs')(self).pop(0) + data.update({'filtreOperationsComptabilisees': "MOIS_MOINS_%s" % next_month}) return requests.Request('POST', data=json.dumps(data)) def parse(self, el): @@ -462,6 +461,12 @@ def parse(self, el): break self.obj._deferred_date = self.FromTimestamp().filter(deferred_date) + def validate(self, obj): + if Env('last_trs', default=None)(self): + # keep only current month transactions + return obj.date.month >= datetime.date.today().month + return True + class RedirectInsurancePage(LoggedPage, JsonPage): def get_url(self):