Commit cfd32a7b authored by Martin Sicot's avatar Martin Sicot Committed by hydrargyrum
Browse files

[degiro] Fix: balance, original_val, liquidity

Balance : The account balance and the total amount of the investments in
that same account was not the same because of the wrong dictionnary key.

original_valuation : added parse function to handle correclty
investments in foreign currency

liquidity : replaced the investments that are cash in the iter_investments list by
liquidities.
parent 133fc067
......@@ -23,6 +23,8 @@
from weboob.browser.exceptions import ClientError
from weboob.exceptions import BrowserIncorrectPassword
from weboob.tools.json import json
from weboob.tools.capabilities.bank.investments import create_french_liquidity
from weboob.capabilities.base import Currency
from dateutil.relativedelta import relativedelta
......@@ -87,7 +89,9 @@ def iter_investment(self, account):
if account.id not in self.invs:
staging = '_s' if 'staging' in self.sessionId else ''
self.accounts.stay_or_go(staging=staging, accountId=self.intAccount, sessionId=self.sessionId)
self.invs[account.id] = list(self.page.iter_investment())
invests = list(self.page.iter_investment(currency=account.currency))
# Replace as liquidities investments that are cash
self.invs[account.id] = [create_french_liquidity(inv.valuation) if len(inv.label) < 4 and Currency.get_currency(inv.label) else inv for inv in invests]
return self.invs[account.id]
@need_login
......
......@@ -60,12 +60,8 @@ class get_account(ItemElement):
klass = Account
def obj_balance(self):
d = list_to_dict(self.el['totalPortfolio']['value'])
if 'reportNetliq' in d:
return Decimal(str(d['reportNetliq']))
return CleanDecimal().filter(sum(
[abs(round(y['value']['EUR'], 2)) for x in Dict('portfolio/value')(self) for y in x['value'] if y['name'] == 'todayPlBase']
[round(y['value'], 2) for x in Dict('portfolio/value')(self) for y in x['value'] if y['name'] == 'value']
))
def obj_id(self):
......@@ -89,15 +85,19 @@ class iter_investment(DictElement):
class item(ItemElement):
klass = Investment
def condition(self):
return Decimal(str(list_to_dict(self.el['value'])['size']))
obj_unitvalue = Env('unitvalue', default=NotAvailable)
obj_original_currency = Env('original_currency', default=NotAvailable)
obj_original_unitvalue = Env('original_unitvalue', default=NotAvailable)
def obj__product_id(self):
return str(list_to_dict(self.el['value'])['id'])
def obj_quantity(self):
return Decimal(str(list_to_dict(self.el['value'])['size']))
def obj_unitvalue(self):
return Decimal(str(list_to_dict(self.el['value'])['price']))
def obj_valuation(self):
return Decimal(str(list_to_dict(self.el['value'])['value']))
......@@ -117,12 +117,20 @@ def obj_code_type(self):
return Investment.CODE_TYPE_ISIN
return NotAvailable
def obj_original_currency(self):
return self._product()['currency']
def _product(self):
return self.page.browser.get_product(str(Field('_product_id')(self)))
def parse(self, el):
currency = self._product()['currency']
unitvalue = Decimal(str(list_to_dict(self.el['value'])['price']))
if currency == self.env['currency']:
self.env['unitvalue'] = unitvalue
else:
self.env['original_unitvalue'] = unitvalue
self.env['original_currency'] = currency
class InvestmentPage(LoggedPage, JsonPage):
def get_products(self):
......
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