From aef7ad215bfaa5bef8f544bd0155c7cde711734a Mon Sep 17 00:00:00 2001 From: Florent Viard Date: Fri, 28 May 2021 14:51:24 +0200 Subject: [PATCH] [bred] Simplify get_accounts_list and ensure parent matching is done with accounts of all universes Sometimes, the life insurance account will be found in the same univers as the parent account and sometimes it is not the case. In addition to that, the iteration order of the univers for the get_accounts was having an impact on whether the "parent" could be filled or not for a life insurance account. Now, we do the matching only after all the accounts have been retrieved. --- modules/bred/bred/browser.py | 26 +++++++++++++++----------- modules/bred/bred/pages.py | 15 ++++++--------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/modules/bred/bred/browser.py b/modules/bred/bred/browser.py index 3603ad2128..49d802dc2f 100644 --- a/modules/bred/bred/browser.py +++ b/modules/bred/bred/browser.py @@ -340,7 +340,7 @@ def get_accounts_list(self): self.move_to_universe(universe_key) universe_accounts = [] universe_accounts.extend(self.get_list()) - universe_accounts.extend(self.get_life_insurance_list(accounts)) + universe_accounts.extend(self.get_life_insurance_list()) universe_accounts.extend(self.get_loans_list()) linebourse_accounts = self.get_linebourse_accounts(universe_key) for account in universe_accounts: @@ -354,8 +354,17 @@ def get_accounts_list(self): accounts.extend(universe_accounts) # Life insurances are sometimes in multiple universes, we have to remove duplicates - unique_accounts = {account.id: account for account in accounts} - return sorted(unique_accounts.values(), key=operator.attrgetter('_univers')) + unique_accounts = {account.id: account for account in accounts}.values() + + # Fill parents with resulting accounts when relevant: + for account in unique_accounts: + if account.type not in [Account.TYPE_CARD, Account.TYPE_LIFE_INSURANCE]: + continue + account.parent = find_object( + unique_accounts, _number=account._parent_number, type=Account.TYPE_CHECKING + ) + + return sorted(unique_accounts, key=operator.attrgetter('_univers')) @need_login def get_linebourse_accounts(self, universe_key): @@ -387,17 +396,12 @@ def get_loans_list(self): @need_login def get_list(self): self.accounts.go() - for acc in self.page.iter_accounts(accnum=self.accnum, current_univers=self.current_univers): - yield acc + return self.page.iter_accounts(accnum=self.accnum, current_univers=self.current_univers) @need_login - def get_life_insurance_list(self, accounts): - + def get_life_insurance_list(self): self.life_insurances.go() - - for ins in self.page.iter_lifeinsurances(univers=self.current_univers): - ins.parent = find_object(accounts, _number=ins._parent_number, type=Account.TYPE_CHECKING) - yield ins + return self.page.iter_lifeinsurances(univers=self.current_univers) @need_login def _make_api_call(self, account, start_date, end_date, offset, max_length=50): diff --git a/modules/bred/bred/pages.py b/modules/bred/bred/pages.py index fd8fb046ee..b61349eae0 100644 --- a/modules/bred/bred/pages.py +++ b/modules/bred/bred/pages.py @@ -25,7 +25,6 @@ from woob.tools.date import parse_french_date from woob.exceptions import BrowserIncorrectPassword, BrowserUnavailable, ActionNeeded -from woob.capabilities.base import find_object from woob.browser.pages import JsonPage, LoggedPage, HTMLPage from woob.capabilities import NotAvailable from woob.capabilities.bank import Account @@ -176,8 +175,6 @@ class AccountsPage(LoggedPage, MyJsonPage): def iter_accounts(self, accnum, current_univers): seen = set() - accounts_list = [] - for content in self.get_content(): if accnum != '00000000000' and content['numero'] != accnum: continue @@ -188,6 +185,7 @@ def iter_accounts(self, accnum, current_univers): a._codeSousPoste = poste['codeSousPoste'] if 'codeSousPoste' in poste else None a._consultable = poste['consultable'] a._univers = current_univers + a._parent_number = None a.id = '%s.%s' % (a._number, a._nature) if content['comptePEA']: @@ -197,8 +195,8 @@ def iter_accounts(self, accnum, current_univers): if a.type == Account.TYPE_UNKNOWN: self.logger.warning("unknown type %s" % poste['codeNature']) - if a.type == Account.TYPE_CARD: - a.parent = find_object(accounts_list, _number=a._number, type=Account.TYPE_CHECKING) + if a.type != Account.TYPE_CHECKING: + a._parent_number = a._number if 'numeroDossier' in poste and poste['numeroDossier']: a._file_number = poste['numeroDossier'] @@ -210,7 +208,8 @@ def iter_accounts(self, accnum, current_univers): a.currency = poste['montantTitres']['monnaie']['code'].strip() if not a.balance and not a.currency and 'dateTitres' not in poste: continue - accounts_list.append(a) + yield a + continue if 'libelle' not in poste: continue @@ -232,9 +231,7 @@ def iter_accounts(self, accnum, current_univers): continue seen.add(a.id) - accounts_list.append(a) - - return accounts_list + yield a class IbanPage(LoggedPage, MyJsonPage): -- GitLab