Commit 70e6b91b authored by Louise Zanier's avatar Louise Zanier Committed by Vincent A

[caissedepargne] Corrected life insurance browsing, and removed closed accounts from the final list

parent ab539090
......@@ -1277,6 +1277,12 @@ def add_owner_accounts(self):
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]:
if account.type == Account.TYPE_LIFE_INSURANCE:
# For life insurance accounts, we check if the contract is still open
if not self.go_life_insurance_investments(account):
return
if self.page.is_contract_closed():
continue
self.accounts.append(account)
wealth_not_accessible = False
......@@ -1500,13 +1506,11 @@ def _get_history_invests(self, account):
self.life_insurance_history.go()
# Life insurance transactions are not sorted by date in the JSON
return sorted_transactions(self.page.iter_history())
except (IndexError, AttributeError) as e:
self.logger.error(e)
return []
except ServerError as e:
if e.response.status_code == 500:
raise BrowserUnavailable()
raise
return self.page.iter_history()
@need_login
......@@ -1625,8 +1629,8 @@ def get_investment(self, account):
else:
self.home.go()
self.page.go_history(account._info)
if account.type in (Account.TYPE_MARKET, Account.TYPE_PEA):
self.page.go_history(account._info)
# Some users may not have access to this.
if not self.market.is_here():
return
......@@ -1656,22 +1660,7 @@ def get_investment(self, account):
yield tr
return
try:
# Some life insurances are not on the accounts summary
self.home_tache.go(tache='EPASYNT0')
self.page.go_life_insurance(account)
if self.home.is_here():
# no detail is available for this account
return
elif not self.market.is_here() and not self.message.is_here():
# life insurance website is not always available
raise BrowserUnavailable()
self.page.submit()
self.life_insurance_investments.go()
except (IndexError, AttributeError) as e:
self.logger.error(e)
if not self.go_life_insurance_investments(account):
return
if self.garbage.is_here():
......@@ -1682,6 +1671,21 @@ def get_investment(self, account):
if self.market.is_here():
self.page.come_back()
@need_login
def go_life_insurance_investments(self, account):
# Returns whether it managed to go to the page
self.home_tache.go(tache='EPASYNT0')
self.page.go_life_insurance(account)
if self.home.is_here():
# no detail is available for this account
return False
elif not self.market.is_here() and not self.message.is_here():
# life insurance website is not always available
raise BrowserUnavailable()
self.page.submit()
self.life_insurance_investments.go()
return True
@need_login
def iter_market_orders(self, account):
if account.type not in (Account.TYPE_MARKET, Account.TYPE_PEA):
......
......@@ -603,6 +603,7 @@ def _get_account_info(self, a, accounts):
r"PostBack(Options)?\([\"'][^\"']+[\"'],\s*['\"]([HISTORIQUE_\w|SYNTHESE_ASSURANCE_CNP|BOURSE|COMPTE_TITRE][\d\w&]+)?['\"]",
a.attrib.get('href', '')
)
if m is None:
return None
else:
......@@ -876,9 +877,9 @@ def get_loan_list(self):
account.currency = account.get_currency(CleanText('./a')(tds[4]))
accounts[account.id] = account
website = 'old'
website = 'new'
if accounts:
website = 'new'
website = 'old'
self.logger.debug('we are on the %s website', website)
if len(accounts) == 0:
......@@ -1858,6 +1859,9 @@ def obj_unitvalue(self):
obj_code = IsinCode(CleanText(Dict('codeIsin', default='')), default=NotAvailable)
obj_code_type = IsinType(CleanText(Dict('codeIsin', default='')))
def is_contract_closed(self):
return Dict('etatContrat/code')(self.doc) == "01"
class NatixisLIHis(LoggedPage, JsonPage):
@method
......
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