Commit 3cfac69f authored by Maxime Pommier's avatar Maxime Pommier Committed by Romain Bignon

[bred] Get all life insurance account

We only got one life insurance account. Fixed it, now we get all invest account in Browser2 way.
Same thing for the invest.
parent fa3a8d0b
......@@ -21,10 +21,10 @@ from __future__ import unicode_literals
import json
import time
import operator
from datetime import date
from decimal import Decimal
from import Account, Investment
from import Account
from weboob.browser import LoginBrowser, need_login, URL
from weboob.capabilities.base import find_object
from import sorted_transactions
......@@ -117,10 +117,12 @@ class BredBrowser(LoginBrowser):
for universe_key in self.get_universes():
return sorted(accounts, key=lambda x: x._univers)
# 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'))
def get_loans_list(self):
......@@ -138,12 +140,11 @@ class BredBrowser(LoginBrowser):
def get_life_insurance_list(self, accounts):
accounts = self.get_list()
for ins in
ins.parent = find_object(accounts, _number=ins._number, type=Account.TYPE_CHECKING)
for ins in
ins.parent = find_object(accounts, _number=ins._parent_number, type=Account.TYPE_CHECKING)
yield ins
......@@ -170,7 +171,7 @@ class BredBrowser(LoginBrowser):
def get_history(self, account, coming=False):
if account.type is Account.TYPE_LOAN or not account._consultable:
if account.type in (Account.TYPE_LOAN, Account.TYPE_LIFE_INSURANCE) or not account._consultable:
raise NotImplementedError()
if account._univers != self.current_univers:
......@@ -210,15 +211,8 @@ class BredBrowser(LoginBrowser):
if account.type != Account.TYPE_LIFE_INSURANCE:
raise NotImplementedError()
if account._univers != self.current_univers:
for invest in account._investments:
inv = Investment()
inv.label = invest['libelle'].strip()
inv.code = invest['code']
inv.valuation = Decimal(str(invest['montant']))
yield inv
yield invest
def get_profile(self):
......@@ -28,9 +28,12 @@ from weboob.exceptions import BrowserIncorrectPassword, BrowserUnavailable, Acti
from weboob.capabilities.base import find_object
from weboob.browser.pages import JsonPage, LoggedPage, HTMLPage
from weboob.capabilities import NotAvailable
from import Account
from import Account, Investment
from import is_isin_valid
from weboob.capabilities.profile import Person
from weboob.browser.filters.standard import CleanText
from weboob.browser.filters.standard import CleanText, CleanDecimal, Env, Eval
from weboob.browser.filters.json import Dict
from weboob.browser.elements import DictElement, ItemElement, method
from import FrenchTransaction
......@@ -187,21 +190,56 @@ class IbanPage(MyJsonPage):
account.iban = iban_response.get('iban', NotAvailable)
class LifeInsurancesPage(MyJsonPage):
def iter_life_insurances(self, current_univers):
for content in self.get_content():
a = Account() = str(content['avoirs']['contrats'][0]['numero'])
a._number = content['avoirs']['contrats'][0]['cptRattachement'].rstrip('0')
a.type = Account.TYPE_LIFE_INSURANCE
a.label = ' '.join([content['titulaire'].strip(), content['avoirs']['contrats'][0]['libelleProduit'].strip()])
a.balance = Decimal(str(content['avoirs']['valeur']))
a.currency = 'EUR'
a._univers = current_univers
# The investment list for each life insurance is available here:
a._investments = [inv for inv in content['avoirs']['contrats'][0]['allocations']]
a._consultable = False
yield a
class LifeInsurancesPage(LoggedPage, JsonPage):
class iter_lifeinsurances(DictElement):
item_xpath = 'content'
class iter_accounts(DictElement):
item_xpath = 'avoirs/contrats'
def get_owner(self):
return CleanText(Dict('titulaire'))(self)
class item(ItemElement):
klass = Account
obj_balance = CleanDecimal(Dict('valorisation'))
obj_type = Account.TYPE_LIFE_INSURANCE
obj_currency = 'EUR'
obj__univers = Env('univers')
def obj_id(self):
return Eval(str, Dict('numero'))(self)
def obj_label(self):
return '%s - %s' % (CleanText(Dict('libelleProduit'))(self), self.parent.get_owner())
def obj__parent_number(self):
return CleanText(Dict('cptRattachement'))(self).rstrip('0')
# Investments are already present in this JSON,
# so we fill the lists of Investment objects now
class obj__investments(DictElement):
item_xpath = 'allocations'
class item(ItemElement):
klass = Investment
obj_label = CleanText(Dict('libelle'))
obj_valuation = CleanDecimal(Dict('montant'))
def obj_code_type(self):
if is_isin_valid(CleanText(Dict('code'))(self)):
return Investment.CODE_TYPE_ISIN
return NotAvailable
def obj_code(self):
code = CleanText(Dict('code'))(self)
if is_isin_valid(code):
return code
return NotAvailable
class SearchPage(LoggedPage, JsonPage):
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