Commit d9a54cf8 authored by Lucas Ficheux's avatar Lucas Ficheux Committed by Romain Bignon

[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
parent 872f3fff
......@@ -109,26 +109,28 @@ class BnpcartesentrepriseBrowser(LoginBrowser):
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
......
......@@ -49,12 +49,14 @@ class LoginPage(HTMLPage):
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 @@ class PeriodsPage(LoggedPage, HTMLPage):
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 AccountsPage(ExpandablePage, GetableLinksPage):
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 AccountsPage(ExpandablePage, GetableLinksPage):
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):
......
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