Commit aef7ad21 authored by Florent Viard's avatar Florent Viard Committed by Vincent A

[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.
parent 4607e1fa
......@@ -340,7 +340,7 @@ def get_accounts_list(self):
universe_accounts = []
linebourse_accounts = self.get_linebourse_accounts(universe_key)
for account in universe_accounts:
......@@ -354,8 +354,17 @@ def get_accounts_list(self):
# Life insurances are sometimes in multiple universes, we have to remove duplicates
unique_accounts = { account for account in accounts}
return sorted(unique_accounts.values(), key=operator.attrgetter('_univers'))
unique_accounts = { 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]:
account.parent = find_object(
unique_accounts, _number=account._parent_number, type=Account.TYPE_CHECKING
return sorted(unique_accounts, key=operator.attrgetter('_univers'))
def get_linebourse_accounts(self, universe_key):
......@@ -387,17 +396,12 @@ def get_loans_list(self):
def get_list(self):
for acc in, current_univers=self.current_univers):
yield acc
return, current_univers=self.current_univers)
def get_life_insurance_list(self, accounts):
def get_life_insurance_list(self):
for ins in
ins.parent = find_object(accounts, _number=ins._parent_number, type=Account.TYPE_CHECKING)
yield ins
def _make_api_call(self, account, start_date, end_date, offset, max_length=50):
......@@ -25,7 +25,6 @@
from 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 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:
......@@ -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 = '%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:
yield a
if 'libelle' not in poste:
......@@ -232,9 +231,7 @@ def iter_accounts(self, accnum, current_univers):
return accounts_list
yield a
class IbanPage(LoggedPage, MyJsonPage):
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