diff --git a/modules/societegenerale/browser.py b/modules/societegenerale/browser.py index 91088ec751bff8af703a644892273cfbeab19cfa..005fd5762212e58797e3027a5382d8df8ba14ea7 100644 --- a/modules/societegenerale/browser.py +++ b/modules/societegenerale/browser.py @@ -177,8 +177,16 @@ def get_accounts_list(self): else: account_ibans = self.page.get_account_ibans_dict() - # get accounts coming self.accounts_syntheses.go() + + if not self.page.is_new_website_available(): + # return in old pages to get accounts + self.accounts_main_page.go(params={'NoRedirect': True}) + for acc in self.page.iter_accounts(): + yield acc + return + + # get accounts coming account_comings = self.page.get_account_comings() self.accounts.go() @@ -211,6 +219,9 @@ def iter_history(self, account): if account.type == Account.TYPE_PEA and not ('Espèces' in account.label or 'ESPECE' in account.label): return + if not account._internal_id: + raise BrowserUnavailable() + if account.type in (account.TYPE_LIFE_INSURANCE, account.TYPE_PERP, ): # request to get json is not available yet, old request to get html response self.account_details_page.go(params={'idprest': account._prestation_id}) @@ -254,6 +265,9 @@ def iter_coming(self, account): account.TYPE_CONSUMER_CREDIT, Account.TYPE_PERP, ): return + if not account._internal_id: + raise BrowserUnavailable() + internal_id = account._internal_id if account.type == account.TYPE_CARD: internal_id = account.parent._internal_id diff --git a/modules/societegenerale/pages/accounts_list.py b/modules/societegenerale/pages/accounts_list.py index 0a95b26130326caaf90177f49444f39f3dcd0ff3..388f04482c4ee044e9fc245c1a16d047c9363145 100644 --- a/modules/societegenerale/pages/accounts_list.py +++ b/modules/societegenerale/pages/accounts_list.py @@ -59,13 +59,15 @@ def on_load(self): if action and 'BLOCAGE' in action: raise ActionNeeded() - if 'le service est momentanement indisponible' in reason: - # TODO: iter account on old website - # can't access new website + if ('le service est momentanement indisponible' in reason and + Dict('commun/origine')(self.doc) != 'cbo'): raise BrowserUnavailable() - assert 'pas encore géré' in reason, 'Error %s is not handled yet' % reason - self.browser.logger.warning('This page is not handled yet by SG') + conditions = ( + 'pas encore géré' in reason, # this page is not handled by SG api website + 'le service est momentanement indisponible' in reason, # can't access new website + ) + assert any(conditions), 'Error %s is not handled yet' % reason class AccountsMainPage(LoggedPage, HTMLPage): @@ -77,6 +79,36 @@ def is_accounts(self): if 'Vous ne disposez pas de compte consultable' in error_msg: raise NoAccountsException(error_msg) + @method + class iter_accounts(TableElement): + """iter account on old website""" + head_xpath = '//table[@class="LGNTableA ListePrestation"]//tr[@class="LGNTableHead"]/th' + item_xpath = '//table[@class="LGNTableA ListePrestation"]//tr[has-class("LGNTableRow")]' + + col_id = 'Numéro de Compte' + col_type = 'Type de Compte' + col_label = 'Libellé' + col_balance = 'Solde' + + class item(ItemElement): + klass = Account + + TYPES = { + 'LIVRET': Account.TYPE_SAVINGS, + } + + obj_id = obj_number = CleanText(TableCell('id'), replace=[(' ', '')]) + obj_label = CleanText('.//span[@class="TypeCompte"]') + obj_balance = MyDecimal(TableCell('balance')) + obj_currency = Currency(CleanText(TableCell('balance'))) + obj__internal_id = None + + def obj_type(self): + for acc_type in self.TYPES: + if acc_type in Field('label')(self).upper(): + return self.TYPES[acc_type] + return Account.TYPE_UNKNOWN + class AccountDetailsPage(LoggedPage, HTMLPage): pass @@ -155,6 +187,14 @@ def obj__is_json_histo(self): return True class AccountsSynthesesPage(JsonBasePage): + def is_new_website_available(self): + if not Dict('commun/raison')(self.doc): + return True + elif not 'le service est momentanement indisponible' in Dict('commun/raison')(self.doc): + return True + self.logger.warning("SG new website is not available yet for this user") + return False + def get_account_comings(self): account_comings = {}