Commit 6cfeb9c1 authored by Quentin Defenouillere's avatar Quentin Defenouillere Committed by Vincent A

[cragr] Repair life insurance investments & handled Rothschild invests

parent 9893aa4c
......@@ -397,6 +397,7 @@ class CreditAgricoleBrowser(LoginBrowser, StatesMixin):
accounts_list = list(
for account in accounts_list:
account._contract = contract
''' Other accounts have no balance in the main JSON, so we must get all
the (_id_element_contrat, balance) pairs in the account_details JSON.
......@@ -453,6 +454,7 @@ class CreditAgricoleBrowser(LoginBrowser, StatesMixin):
if not in all_accounts:
all_accounts[] = account
yield account
''' Fetch all deferred credit cards for this space: from the space type
we must determine the required URL parameters to build the cards URL.
If there is no card on the space, the server will return a 500 error
......@@ -708,23 +710,29 @@ class CreditAgricoleBrowser(LoginBrowser, StatesMixin):
def iter_investment(self, account):
if account.balance == 0:
if account.balance == 0 or empty(account.balance):
if (
account.type == Account.TYPE_LIFE_INSURANCE
and ('rothschild' in account.label.lower() or re.match(r'^open (perspective|strat)', account.label, re.I))
# We must go to the right perimeter before trying to access the Life Insurance investments
self.life_insurance_investments.go(, idx=account._index, category=account._category)
# for inv in
# yield inv
if self.life_insurance_investments.is_here():
for inv in
yield inv
self.logger.warning('Failed to reach investment details for account %s',
elif (
account.type in (Account.TYPE_LIFE_INSURANCE, Account.TYPE_CAPITALISATION)
and ('vendome' in account.label.lower() or account.label.lower() == 'espace gestion')
and'vendome|aster sélection|espace gestion', account.label, re.I)
# 'Vendome Optimum Euro', 'Vendome Patrimoine' & 'Espace Gestion' and investments are on the BGPI space
# 'Vendome Optimum Euro', 'Vendome Patrimoine', 'Espace Gestion' & 'Aster sélection'
# investments are on the BGPI space
if self.bgpi_accounts.is_here() or self.bgpi_investments.is_here():
# To avoid logouts by going from Cragr to Bgpi and back, we go directly to the account details.
# When there are several BGPI accounts, this shortcut saves a lot of requests.
......@@ -780,10 +788,11 @@ class CreditAgricoleBrowser(LoginBrowser, StatesMixin):
self.predica_redirection.go(, data=data)
except ServerError:
self.logger.warning('Got ServerError when fetching investments for account id %s',
self.logger.warning('Got ServerError when fetching investments for account %s',
for inv in
yield inv
......@@ -712,8 +712,36 @@ class PredicaInvestmentsPage(LoggedPage, JsonPage):
class LifeInsuranceInvestmentsPage(LoggedPage, HTMLPage):
class iter_investments(ListElement):
item_xpath = '//div[@id="menu1"]/div'
class item(ItemElement):
klass = Investment
obj_label = CleanText('.//div[has-class("PrivateBank-tabsNavContentTitle")]')
obj_valuation = CleanDecimal.French('.//div[contains(text(), "Valorisation")]/span')
obj_quantity = CleanDecimal.French(
'.//div[contains(text(), "Nombre de parts")]/following-sibling::div[1]',
obj_unitvalue = CleanDecimal.French(
'.//div[contains(text(), "Valeur de la part")]/following-sibling::div[1]',
obj_diff = CleanDecimal.French(
'.//div[contains(text(), "+/- values")]/span',
def obj_portfolio_share(self):
portfolio_share = CleanDecimal.French(
if not empty(portfolio_share):
return Eval(lambda x: x / 100, portfolio_share)(self)
return NotAvailable
class BgpiRedirectionPage(LoggedPage, HTMLPage):
......@@ -750,10 +778,12 @@ class BgpiInvestmentsPage(LoggedPage, HTMLPage):
'.//span[@class="box"][span[span[text()="Nombre de part"]]]/span[2]/span'
obj_unitvalue = CleanDecimal.French(
'.//span[@class="box"][span[span[text()="Valeur liquidative"]]]/span[2]/span'
'.//span[@class="box"][span[span[text()="Valeur liquidative"]]]/span[2]/span',
obj_unitprice = CleanDecimal.French(
'.//span[@class="box"][span[span[text()="Prix de revient"]]]/span[2]/span', default=NotAvailable
'.//span[@class="box"][span[span[text()="Prix de revient"]]]/span[2]/span',
obj_portfolio_share = Eval(
lambda x: x / 100,
......@@ -763,7 +793,7 @@ class BgpiInvestmentsPage(LoggedPage, HTMLPage):
def obj_diff_ratio(self):
# Euro funds have '-' instead of a diff_ratio value
text = CleanText('.//span[@class="box"][span[span[text()="+/- value latente (%)"]]]/span[2]/span')(self)
if text == '-':
if text in ('', '-'):
return NotAvailable
return Eval(
lambda x: x / 100,
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