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(self.page.iter_accounts())
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 account.id not in all_accounts:
all_accounts[account.id] = 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):
@need_login
def iter_investment(self, account):
if account.balance == 0:
if account.balance == 0 or empty(account.balance):
return
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.go_to_account_space(account._contract)
self.life_insurance_investments.go(space=self.space, idx=account._index, category=account._category)
# TODO
# for inv in self.page.iter_investments():
# yield inv
if self.life_insurance_investments.is_here():
for inv in self.page.iter_investments():
yield inv
else:
self.logger.warning('Failed to reach investment details for account %s', account.id)
return
elif (
account.type in (Account.TYPE_LIFE_INSURANCE, Account.TYPE_CAPITALISATION)
and ('vendome' in account.label.lower() or account.label.lower() == 'espace gestion')
and re.search('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):
}
try:
self.predica_redirection.go(space=self.space, data=data)
self.predica_investments.go()
except ServerError:
self.logger.warning('Got ServerError when fetching investments for account id %s', account.id)
self.logger.warning('Got ServerError when fetching investments for account %s', account.id)
return
else:
self.predica_investments.go()
for inv in self.page.iter_investments():
yield inv
......
......@@ -712,8 +712,36 @@ class PredicaInvestmentsPage(LoggedPage, JsonPage):
class LifeInsuranceInvestmentsPage(LoggedPage, HTMLPage):
# TODO
pass
@method
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]',
default=NotAvailable
)
obj_unitvalue = CleanDecimal.French(
'.//div[contains(text(), "Valeur de la part")]/following-sibling::div[1]',
default=NotAvailable
)
obj_diff = CleanDecimal.French(
'.//div[contains(text(), "+/- values")]/span',
default=NotAvailable
)
def obj_portfolio_share(self):
portfolio_share = CleanDecimal.French(
'.//div[has-class("PrivateBank-tabsNavContentTitle")]/following-sibling::div/span',
default=NotAvailable
)(self)
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',
default=NotAvailable
)
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',
default=NotAvailable
)
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