From 4d11b8706bba8b54ad11fb2a245e9a9e42659104 Mon Sep 17 00:00:00 2001 From: Christophe Francois Date: Wed, 26 Aug 2020 16:45:53 +0200 Subject: [PATCH] [caissedepargne] Fix fetching of wealth accounts and investments Fixing some issues introduced by fetching accounts on the wealth accounts page, and some others: - error 500 while going on the new page, - a json field that needs to be optional, - a fix for the matching of accounts from the synthesis and wealth pages. --- modules/caissedepargne/browser.py | 17 +++++++------ modules/caissedepargne/pages.py | 40 +++++++++++++++++-------------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/modules/caissedepargne/browser.py b/modules/caissedepargne/browser.py index 5a50c97667..99dd318600 100644 --- a/modules/caissedepargne/browser.py +++ b/modules/caissedepargne/browser.py @@ -1011,13 +1011,16 @@ def add_owner_accounts(self): self.accounts = list(self.page.get_list(owner_name)) - # Get wealth accounts that are not on the summary page - self.home_tache.go(tache='EPASYNT0') - # If there are no wealth accounts we are redirected to the "garbage page" - if self.home.is_here(): - for account in self.page.get_list(owner_name): - if account.id not in [acc.id for acc in self.accounts]: - self.accounts.append(account) + try: + # Get wealth accounts that are not on the summary page + self.home_tache.go(tache='EPASYNT0') + # If there are no wealth accounts we are redirected to the "garbage page" + if self.home.is_here(): + for account in self.page.get_list(owner_name): + if account.id not in [acc.id for acc in self.accounts]: + self.accounts.append(account) + except ServerError: + self.logger.warning("Could not access wealth accounts page") self.add_linebourse_accounts_data() self.add_card_accounts() diff --git a/modules/caissedepargne/pages.py b/modules/caissedepargne/pages.py index b62afcae8b..c5a96b9012 100644 --- a/modules/caissedepargne/pages.py +++ b/modules/caissedepargne/pages.py @@ -50,7 +50,7 @@ ) from weboob.capabilities.wealth import Investment from weboob.capabilities.bill import DocumentTypes, Subscription, Document -from weboob.tools.capabilities.bank.investments import is_isin_valid +from weboob.tools.capabilities.bank.investments import is_isin_valid, IsinCode, IsinType from weboob.tools.capabilities.bank.transactions import FrenchTransaction from weboob.tools.capabilities.bank.iban import is_rib_valid, rib2iban, is_iban_valid from weboob.tools.captcha.virtkeyboard import SplitKeyboard, GridVirtKeyboard @@ -433,6 +433,16 @@ class IndexPage(LoggedPage, BasePage): 'PEA': Account.TYPE_PEA, } + ACCOUNT_TYPES_LINK = { + 'SYNTHESE_ASSURANCE_CNP': Account.TYPE_LIFE_INSURANCE, + 'REDIR_ASS_VIE': Account.TYPE_LIFE_INSURANCE, + 'SYNTHESE_EPARGNE': Account.TYPE_LIFE_INSURANCE, + 'ASSURANCE_VIE': Account.TYPE_LIFE_INSURANCE, + 'NA_WEB': Account.TYPE_LIFE_INSURANCE, + 'BOURSE': Account.TYPE_MARKET, + 'COMPTE_TITRE': Account.TYPE_MARKET, + } + def on_load(self): # For now, we have to handle this because after this warning message, @@ -519,8 +529,8 @@ def _get_account_info(self, a, accounts): id = re.search(r"([\d]+)", a.attrib.get('title', '')) if len(parts) > 1: info['type'] = parts[0] - if info['type'] == 'REDIR_ASS_VIE': - # The link format for this account type has an additional parameter + if info['type'] in ('REDIR_ASS_VIE', 'NA_WEB'): + # The link format for these account types has an additional parameter info['id'] = info['_id'] = parts[2] else: info['id'] = info['_id'] = parts[1] @@ -532,12 +542,13 @@ def _get_account_info(self, a, accounts): _id = list(unique_ids)[0] self.find_and_replace(info, _id) else: + if id is None: + return None info['type'] = link info['id'] = info['_id'] = id.group(1) - if info['type'] in ('SYNTHESE_ASSURANCE_CNP', 'REDIR_ASS_VIE', 'SYNTHESE_EPARGNE', 'ASSURANCE_VIE'): - info['acc_type'] = Account.TYPE_LIFE_INSURANCE - if info['type'] in ('BOURSE', 'COMPTE_TITRE'): - info['acc_type'] = Account.TYPE_MARKET + account_type = self.ACCOUNT_TYPES_LINK.get(info['type']) + if account_type: + info['acc_type'] = account_type return info def is_account_inactive(self, account_id): @@ -1730,16 +1741,8 @@ def obj_unitvalue(self): return Eval(float_to_decimal, Dict('cotation/montant/valeur'))(self) return NotAvailable - def obj_code(self): - code = Dict('codeISIN')(self) - if is_isin_valid(code): - return code - return NotAvailable - - def obj_code_type(self): - if Field('code')(self) == NotAvailable: - return NotAvailable - return Investment.CODE_TYPE_ISIN + obj_code = IsinCode(CleanText(Dict('codeIsin', default='')), default=NotAvailable) + obj_code_type = IsinType(CleanText(Dict('codeIsin', default=''))) class NatixisLIHis(LoggedPage, JsonPage): @@ -1770,7 +1773,8 @@ class item(ItemElement): klass = Investment obj_label = CleanText(Dict('nom')) - obj_code = CleanText(Dict('codeIsin')) + obj_code = IsinCode(CleanText(Dict('codeIsin', default='')), default=NotAvailable) + obj_code_type = IsinType(CleanText(Dict('codeIsin', default=''))) def obj_vdate(self): dt = Dict('dateValeurUniteCompte', default=None)(self) -- GitLab