Commit 30cbc62b authored by Dorian ROLY's avatar Dorian ROLY Committed by Vincent A

[cmso] Change the way we handle duplicates

Previously we were filtering the transactions by id "ClefDomirama". But since some transactions got no ids,
we were filtering all the transactions with no ids too. Now with "OperationId" we can filter each transactions on a unique
session ("OperationID" change between two sessions).
parent e4468ca6
......@@ -343,29 +343,30 @@ class CmsoParBrowser(TwoFactorBrowser):
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
......
......@@ -392,9 +392,9 @@ class HistoryPage(LoggedPage, JsonPage):
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 @@ class HistoryPage(LoggedPage, JsonPage):
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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment