From ad6bf998be203e67457b782161612b9d31df1b21 Mon Sep 17 00:00:00 2001 From: Quentin Defenouillere Date: Wed, 28 Nov 2018 16:57:51 +0100 Subject: [PATCH] [bolden] Remodelled module with one main account and investments The money borrowed on Bolden should be considered as investments, no individual accounts, with the available money retrieved as liquidities. Only the borrowed money that is still ongoing should be considered, the other investment lines without valuation are expired investments. With this model, the sum of investment valuation + liquidities actually fits the main account balance. Closes: 7716@zendesk, 8244@zendesk --- modules/bolden/browser.py | 23 +++++++++-------- modules/bolden/module.py | 7 +++-- modules/bolden/pages.py | 54 ++++++++++++++++++++++----------------- 3 files changed, 49 insertions(+), 35 deletions(-) diff --git a/modules/bolden/browser.py b/modules/bolden/browser.py index b76a339afa..c89cf51344 100644 --- a/modules/bolden/browser.py +++ b/modules/bolden/browser.py @@ -23,6 +23,7 @@ from weboob.browser import LoginBrowser, need_login, URL from weboob.capabilities.bill import Document +from weboob.tools.capabilities.bank.investments import create_french_liquidity from .pages import ( LoginPage, HomeLendPage, PortfolioPage, OperationsPage, MAIN_ID, ProfilePage, @@ -51,13 +52,16 @@ def iter_accounts(self): self.portfolio.go() return self.page.iter_accounts() + def iter_investments(self): + self.portfolio.go() + yield create_french_liquidity(self.page.get_liquidity()) + for inv in self.page.iter_investments(): + yield inv + @need_login def iter_history(self, account): if account.id != MAIN_ID: - return [] - return self._iter_all_history() - - def _iter_all_history(self): + return end = datetime.now() while True: start = end - timedelta(days=365) @@ -86,14 +90,13 @@ def get_profile(self): @need_login def iter_documents(self): - for acc in self.iter_accounts(): - if acc.id == MAIN_ID: + for inv in self.iter_investments(): + if inv.label == "Liquidités": continue - doc = Document() - doc.id = acc.id - doc.url = acc._docurl - doc.label = 'Contrat %s' % acc.label + doc.id = inv.id + doc.url = inv._docurl + doc.label = 'Contrat %s' % inv.label doc.type = 'other' doc.format = 'pdf' yield doc diff --git a/modules/bolden/module.py b/modules/bolden/module.py index 866b4b3d57..45a75d1083 100644 --- a/modules/bolden/module.py +++ b/modules/bolden/module.py @@ -22,7 +22,7 @@ from weboob.tools.backend import Module, BackendConfig from weboob.tools.value import ValueBackendPassword -from weboob.capabilities.bank import CapBank, Account +from weboob.capabilities.bank import CapBankWealth, Account from weboob.capabilities.base import find_object from weboob.capabilities.bill import ( CapDocument, Subscription, SubscriptionNotFound, DocumentNotFound, Document, @@ -35,7 +35,7 @@ __all__ = ['BoldenModule'] -class BoldenModule(Module, CapBank, CapDocument, CapProfile): +class BoldenModule(Module, CapBankWealth, CapDocument, CapProfile): NAME = 'bolden' DESCRIPTION = 'Bolden' MAINTAINER = 'Vincent A' @@ -59,6 +59,9 @@ def iter_accounts(self): def iter_history(self, account): return self.browser.iter_history(account) + def iter_investment(self, account): + return self.browser.iter_investments() + def get_profile(self): return self.browser.get_profile() diff --git a/modules/bolden/pages.py b/modules/bolden/pages.py index 9f9ee35f20..7588f13e96 100644 --- a/modules/bolden/pages.py +++ b/modules/bolden/pages.py @@ -19,15 +19,14 @@ from __future__ import unicode_literals -from decimal import Decimal - from weboob.browser.elements import ListElement, ItemElement, method, TableElement from weboob.browser.filters.html import TableCell, Link, Attr from weboob.browser.filters.standard import ( CleanText, CleanDecimal, Slugify, Date, Field, Format, ) from weboob.browser.pages import HTMLPage, LoggedPage -from weboob.capabilities.bank import Account, Transaction +from weboob.capabilities.base import NotAvailable +from weboob.capabilities.bank import Account, Transaction, Investment from weboob.capabilities.profile import Profile from weboob.exceptions import BrowserIncorrectPassword from weboob.tools.compat import urljoin @@ -55,37 +54,46 @@ class HomeLendPage(LoggedPage, HTMLPage): class PortfolioPage(LoggedPage, HTMLPage): @method class iter_accounts(ListElement): - class get_main(ItemElement): + class item(ItemElement): klass = Account obj_id = MAIN_ID obj_label = 'Compte Bolden' - obj_type = Account.TYPE_CHECKING + obj_type = Account.TYPE_MARKET obj_currency = 'EUR' - obj_balance = CleanDecimal('//div[p[has-class("investor-state") and contains(text(),"Fonds disponibles :")]]/p[has-class("investor-status")]', replace_dots=True) - #obj_coming = CleanDecimal('//div[p[has-class("investor-state") and contains(text(),"Capital restant dû :")]]/p[has-class("investor-status")]', replace_dots=True) + obj_balance = CleanDecimal('//div[p[has-class("investor-state") and contains(text(),"Total compte Bolden :")]]/p[has-class("investor-status")]', replace_dots=True) + obj_valuation_diff = CleanDecimal('//p[has-class("rent-amount strong dashboard-text")]', replace_dots=True) + + @method + class iter_investments(TableElement): + head_xpath = '//div[@class="tab-wallet"]/table/thead//td' - class iter_lends(TableElement): - head_xpath = '//div[@class="tab-wallet"]/table/thead//td' + col_label = 'Emprunteur' + col_valuation = 'Capital restant dû' + col_doc = 'Contrat' + col_diff = 'Intérêts perçus' - col_label = 'Emprunteur' - col_coming = 'Capital restant dû' - col_doc = 'Contrat' + item_xpath = '//div[@class="tab-wallet"]/table/tbody/tr' - item_xpath = '//div[@class="tab-wallet"]/table/tbody/tr' + class item(ItemElement): + klass = Investment - class item(ItemElement): - klass = Account + obj_label = CleanText(TableCell('label')) + obj_id = Slugify(Field('label')) + obj_valuation = CleanDecimal(TableCell('valuation'), replace_dots=True) + obj_diff = CleanDecimal(TableCell('diff'), replace_dots=True) + obj_code = NotAvailable + obj_code_type = NotAvailable + + def condition(self): + # Investments without valuation are expired. + return CleanDecimal(TableCell('valuation'))(self) - obj_label = CleanText(TableCell('label')) - obj_id = Slugify(Field('label')) - obj_type = Account.TYPE_SAVINGS - obj_currency = 'EUR' - obj_coming = CleanDecimal(TableCell('coming'), replace_dots=True) - obj_balance = Decimal('0') + def obj__docurl(self): + return urljoin(self.page.url, Link('.//a')(TableCell('doc')(self)[0])) - def obj__docurl(self): - return urljoin(self.page.url, Link('.//a')(TableCell('doc')(self)[0])) + def get_liquidity(self): + return CleanDecimal('//div[p[contains(text(), "Fonds disponibles")]]/p[@class="investor-status strong"]', replace_dots=True)(self.doc) class OperationsPage(LoggedPage, HTMLPage): -- GitLab