From 54d19c5866eb625fce5e62102416c8a786465533 Mon Sep 17 00:00:00 2001 From: sinopsysHK Date: Sun, 8 Dec 2019 19:01:59 +0000 Subject: [PATCH] [hsbc] fix history issue when multiple credit cards when two (or more) credit cards are linked to a same parent account, as card numbers are close to each others it can mess'up the fetch of history providing the transactions from the other card. fixing in a row a side effect of the same issue preventing to revert CB payment record from parent account to card account to perform monthly reset. fixing also an issue in the history which was missing some transactions: if history is being called when no new transaction has been recorded since last credit card payement then history tab will have only last period and before last period shown. But currently hsbc module assume that first tab always contains "coming" entries (which are due in the future) so it is always skipped for fetching history. So past entries of the last period are not fetched from history and neither form coming as they are filtered out due to past date. Add new mapping for transaction types related to Global Transferts (with own foreign accounts). --- modules/hsbc/browser.py | 11 +++++++---- modules/hsbc/pages/account_pages.py | 6 ++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/modules/hsbc/browser.py b/modules/hsbc/browser.py index cae5eecabf..f8eafdb8b5 100644 --- a/modules/hsbc/browser.py +++ b/modules/hsbc/browser.py @@ -475,10 +475,13 @@ def get_history(self, account, coming=False, retry_li=True): history_tabs_urls = self.page.history_tabs_urls() guesser = LinearDateGuesser(date_max_bump=timedelta(45)) history = [] - if coming: - self.location(history_tabs_urls[0]) # fetch only first tab coming transactions - history += list(self.page.get_history(date_guesser=guesser)) - else: + # gather coming anyway + # in case no new transaction has been recorded since last (past) payement + self.location(history_tabs_urls[0]) # fetch only first tab coming transactions + history.extend(list(self.page.get_history(date_guesser=guesser))) + if not coming: + # get further history + self.logger.debug("get history") for tab in history_tabs_urls[1:]: self.location(tab) # fetch all tab but first of past transactions history += list(self.page.get_history(date_guesser=guesser)) diff --git a/modules/hsbc/pages/account_pages.py b/modules/hsbc/pages/account_pages.py index 13fc97a4bd..5a6de6d554 100644 --- a/modules/hsbc/pages/account_pages.py +++ b/modules/hsbc/pages/account_pages.py @@ -41,6 +41,7 @@ class Transaction(FrenchTransaction): PATTERNS = [ (re.compile(r'^VIR(EMENT)? (?P.*)'), FrenchTransaction.TYPE_TRANSFER), + (re.compile(r'^TRANSFERT? (?P.*)'), FrenchTransaction.TYPE_TRANSFER), (re.compile(r'^(PRLV|OPERATION|(TVA )?FACT ABONNEMENTS) (?P.*)'), FrenchTransaction.TYPE_ORDER), (re.compile(r'^CB (?P.*?)\s+(?P
\d+)/(?P[01]\d)'), FrenchTransaction.TYPE_CARD), (re.compile(r'^DAB (?P
\d{2})/(?P\d{2}) ((?P\d{2})H(?P\d{2}) )?(?P.*?)( CB N°.*)?$'), FrenchTransaction.TYPE_WITHDRAWAL), @@ -50,6 +51,7 @@ class Transaction(FrenchTransaction): (re.compile(r'^ARRETE DE COMPTE.*'), FrenchTransaction.TYPE_BANK), (re.compile(r'^REMISE (?P.*)'), FrenchTransaction.TYPE_DEPOSIT), (re.compile(r'^FACTURES CB (?P.*)'), FrenchTransaction.TYPE_CARD_SUMMARY), + (re.compile(r'^REJET VIR (?P.*)'), FrenchTransaction.TYPE_BANK), ] @@ -163,8 +165,8 @@ def go_history_page(self, account): for form in self.doc.xpath('//form[@id]'): value = Attr('.//input[@name="CPT_IdPrestation" or @name="CB_IdPrestation"]', 'value')(form) # * if needed, all the card numbers could be fetched at that point to replace 'XXXX' as they appear in 'value' - match = (re.match(r'^(.*)?(\d{11}(\w{3}))$', account.id) or re.match(r'^(.*)?(\d{6})(X{6})(\d{4})(.*)?$', account.id)) - if (match.group(2) or (match.group(4) and match.group(2))) in value: + pattern = ".*{}.*".format(account.id.replace('XXXXXX', '\\d{6}')) + if re.match(pattern, value): # certain forms have the same id atribute, we must submit the one with the same input 'value' attribute self.get_form(xpath='//form[@id][input[@value="%s"]]' % value).submit() return -- GitLab