diff --git a/modules/bnpcards/browser.py b/modules/bnpcards/browser.py index 95590af48413433843e3a74bd99d37241d665ebe..e08f25c717940a3efc14355abcad0ca30b0056c8 100644 --- a/modules/bnpcards/browser.py +++ b/modules/bnpcards/browser.py @@ -24,6 +24,8 @@ 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 @@ def __init__(self, type, *args, **kwargs): 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 @@ def do_login(self): 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') diff --git a/modules/bnpcards/corporate/pages.py b/modules/bnpcards/corporate/pages.py index f6d3fa4dbcba7c9a2f020a347ba295c6b2e4bcae..d73d73b7e439323f2c6fef11cd129aab172b6386 100644 --- a/modules/bnpcards/corporate/pages.py +++ b/modules/bnpcards/corporate/pages.py @@ -65,6 +65,7 @@ class item(ItemElement): 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): diff --git a/modules/bnpcards/module.py b/modules/bnpcards/module.py index 794d072c16a6fd8814e64717cfd3b45ba11c2707..b6a65505986e1211aa33ff8f499f158d4e049461 100644 --- a/modules/bnpcards/module.py +++ b/modules/bnpcards/module.py @@ -65,13 +65,29 @@ def iter_accounts(self): 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