Commit 132b76a5 authored by Augustin Bouverot's avatar Augustin Bouverot Committed by Vincent A

[bnpcards] Fetch data from corporate and business

We had a distinction between corporate and business cards, but there are
some connections that can have both type of cards.
We now will instanciate the corporate browser if we detect that, and
will fetch the data from both "sources" if possible
parent 486794c3
......@@ -24,6 +24,8 @@ from weboob.browser.switch import SiteSwitch
from weboob.tools.capabilities.bank.transactions import sorted_transactions
from weboob.tools.compat import basestring
from .corporate.browser import BnpcartesentrepriseCorporateBrowser
from .pages import (
LoginPage, ErrorPage, AccountsPage, TransactionsPage,
TiCardPage, TiHistoPage, ComingPage, HistoPage, HomePage,
......@@ -70,6 +72,8 @@ class BnpcartesentrepriseBrowser(LoginBrowser):
self.is_corporate = False
self.transactions_dict = {}
self.corporate_browser = None
def do_login(self):
assert isinstance(self.username, basestring)
assert isinstance(self.password, basestring)
......@@ -87,7 +91,9 @@ class BnpcartesentrepriseBrowser(LoginBrowser):
raise BrowserPasswordExpired(self.page.get_error_msg())
if self.type == '2' and self.page.is_corporate():
self.logger.info('Manager corporate connection')
raise SiteSwitch('corporate')
# Even if we are are on a manager corporate connection, we may still have business cards.
# For that case we need to fetch data from both the corporate browser and the default one.
self.corporate_browser = BnpcartesentrepriseCorporateBrowser(self.type, self.username, self.password)
# ti corporate and ge corporate are not detected the same way ..
if 'corporate' in self.page.url:
self.logger.info('Carholder corporate connection')
......
......@@ -65,6 +65,7 @@ class AccountsPage(LoggedPage, HTMLPage):
obj_currency = 'EUR'
obj_url = Link('./td[2]/a')
obj__company = Env('company', default=None) # this field is something used to make the module work, not something meant to be displayed to end users
obj__is_corporate = True
@pagination
def get_link(self, account_id, owner):
......
......@@ -65,13 +65,29 @@ class BnpcartesentrepriseModule(Module, CapBank):
for acc in self.browser.iter_accounts():
acc._bisoftcap = {'all': {'softcap_day':5,'day_for_softcap':100}}
yield acc
def iter_coming(self, account):
for tr in self.browser.get_transactions(account):
if tr._coming:
yield tr
# If this browser exists we have corporate cards, that we also need to fetch
if self.browser.corporate_browser:
for acc in self.browser.corporate_browser.iter_accounts():
acc._bisoftcap = {'all': {'softcap_day': 5, 'day_for_softcap': 100}}
yield acc
def iter_history(self, account):
for tr in self.browser.get_transactions(account):
if getattr(account, '_is_corporate', False):
get_transactions = self.browser.corporate_browser.get_transactions
else:
get_transactions = self.browser.get_transactions
for tr in get_transactions(account):
if not tr._coming:
yield tr
def iter_coming(self, account):
if getattr(account, '_is_corporate', False):
get_transactions = self.browser.corporate_browser.get_transactions
else:
get_transactions = self.browser.get_transactions
for tr in get_transactions(account):
if not tr._coming:
break
yield tr
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