From d9a54cf8cf32576d9210041c2e6a160d4eca6234 Mon Sep 17 00:00:00 2001 From: Lucas Ficheux Date: Tue, 23 Jul 2019 11:20:02 +0200 Subject: [PATCH] [bnpcards] Fix iter accounts for multiple accounts for non corporate connections Added a method to fetch all companies and added the '_company' attribute to Account objects so that they can use their company identifier when filling forms. Closes: 12440@zendesk --- modules/bnpcards/browser.py | 40 +++++++++++++++++++------------------ modules/bnpcards/pages.py | 12 +++++++++-- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/modules/bnpcards/browser.py b/modules/bnpcards/browser.py index 92e680c76f..18c27be102 100644 --- a/modules/bnpcards/browser.py +++ b/modules/bnpcards/browser.py @@ -109,26 +109,28 @@ def iter_accounts(self): account.coming = self.page.get_balance() yield account if self.type == '2': - for rib in self.page.get_rib_list(): + for company in self.page.get_companies(): self.accounts.stay_or_go() - self.page.expand(rib=rib) - - accounts = list(self.page.iter_accounts(rib=rib)) - ids = {} - prev_rib = None - for account in accounts: - if account.id in ids: - self.logger.warning('duplicate account %r', account.id) - account.id += '_%s' % ''.join(account.label.split()) - - if prev_rib != account._rib: - self.coming.go() - self.page.expand(rib=account._rib) - account.coming = self.page.get_balance(account) - prev_rib = account._rib - - ids[account.id] = account - yield account + self.page.expand(company=company) + for rib in self.page.get_rib_list(): + self.page.expand(rib=rib, company=company) + + accounts = list(self.page.iter_accounts(rib=rib, company=company)) + ids = {} + prev_rib = None + for account in accounts: + if account.id in ids: + self.logger.warning('duplicate account %r', account.id) + account.id += '_%s' % ''.join(account.label.split()) + + if prev_rib != account._rib: + self.coming.go() + self.page.expand(rib=account._rib, company=account._company) + account.coming = self.page.get_balance(account) + prev_rib = account._rib + + ids[account.id] = account + yield account # Could be the very same as non corporate but this shitty website seems # completely bugged diff --git a/modules/bnpcards/pages.py b/modules/bnpcards/pages.py index 5434f42c81..a08895dd9a 100644 --- a/modules/bnpcards/pages.py +++ b/modules/bnpcards/pages.py @@ -49,12 +49,14 @@ def login(self, type, username, password): class ExpandablePage(LoggedPage, HTMLPage): - def expand(self, account=None, rib=None): + def expand(self, account=None, rib=None, company=None): form = self.get_form() if rib is not None: form['ribSaisi'] = rib if account is not None: form['numCarteSaisi'] = account._nav_num + if company is not None: + form['entrepriseSaisie'] = company # needed if coporate titulaire form.url = form.url.replace('Appliquer', 'Afficher') form.submit() @@ -80,13 +82,15 @@ def get_periods(self): periods.append(period) return periods - def expand(self, period, account=None, rib=None): + def expand(self, period, account=None, rib=None, company=None): form = self.get_form(submit='//input[@value="Display"]') if account is not None: form['numCarteSaisi'] = account._nav_num form['periodeSaisie'] = period if rib is not None: form['ribSaisi'] = rib + if company is not None: + form['entrepriseSaisie'] = company # needed if coporate titulaire form.url = form.url.replace('Appliquer', 'Afficher') form.submit() @@ -109,6 +113,7 @@ class item(ItemElement): obj_label = CleanText('./td[1]') obj_type = Account.TYPE_CARD obj__rib = Env('rib') + obj__company = Env('company') obj_currency = u'EUR' obj_number = CleanText('./td[2]', replace=[(' ', '')]) obj_url = AbsoluteLink('./td[2]/a') @@ -118,6 +123,9 @@ class item(ItemElement): def store(self, obj): return obj + def get_companies(self): + return self.doc.xpath('//select[@name="entrepriseSaisie"]/option/@value') + class ComingPage(ExpandablePage): def get_link(self, account): -- GitLab