Commit 11cb5222 authored by Quentin Defenouillere's avatar Quentin Defenouillere Committed by Romain Bignon

[cmes/cices] Corrected investments and pockets for CCB supports

The code for CCB investments was completely obsolete, the get_link did
not work anymore, the xpaths were wrong.
Now the CCB invests and pockets are correctly scraped so the valuation
sum fits the account balance.

Closes: 8379@zendesk
parent d6db8a10
......@@ -23,7 +23,7 @@ from weboob.browser import LoginBrowser, URL, need_login
from .pages import (
LoginPage, AccountsPage, FCPEInvestmentPage,
CCBInvestmentPage, HistoryPage, AlertPage,
CCBInvestmentPage, HistoryPage,
)
......@@ -36,11 +36,10 @@ class CmesBrowser(LoginBrowser):
r'/fr/espace/devbavoirs.aspx\?.*SituationParFonds.*GoOpenDetailFond.*',
r'(?P<subsite>.*)fr/espace/devbavoirs.aspx\?_tabi=C&a_mode=net&a_menu=cpte&_pid=SituationGlobale&_fid=GoPositionsParFond',
r'(?P<subsite>.*)fr/espace/devbavoirs.aspx\?_tabi=C&a_mode=net&a_menu=cpte&_pid=SituationParFonds.*', FCPEInvestmentPage)
ccb_investment = URL('(?P<subsite>.*)fr/.*LstSuppCCB.*', CCBInvestmentPage)
ccb_investment = URL('(?P<subsite>.*)fr/espace/devbavoirs.aspx\?_tabi=C&a_mode=net&a_menu=cpte&_pid=SituationGlobale&_fid=GoCCB', CCBInvestmentPage)
history = URL('(?P<subsite>.*)fr/espace/devbavoirs.aspx\?mode=net&menu=cpte&page=operations',
'(?P<subsite>.*)fr/.*GoOperationsTraitees',
'(?P<subsite>.*)fr/.*GoOperationDetails', HistoryPage)
supp_alert = URL(r'(?P<subsite>.*)fr/espace/LstSuppAlerte.asp', AlertPage)
def __init__(self, website, username, password, subsite="", *args, **kwargs):
super(LoginBrowser, self).__init__(*args, **kwargs)
......@@ -57,12 +56,12 @@ class CmesBrowser(LoginBrowser):
@need_login
def iter_accounts(self):
return self.accounts.stay_or_go(subsite=self.subsite).iter_accounts()
return self.accounts.go(subsite=self.subsite).iter_accounts()
@need_login
def iter_investment(self, account):
fcpe_link = self.accounts.stay_or_go(subsite=self.subsite).get_investment_link()
ccb_link = self.supp_alert.go(subsite=self.subsite).get_pocket_link()
fcpe_link = self.accounts.go(subsite=self.subsite).get_investment_link()
ccb_link = self.accounts.go(subsite=self.subsite).get_pocket_link()
if fcpe_link or ccb_link:
return self._iter_investment(fcpe_link, ccb_link)
......@@ -80,18 +79,17 @@ class CmesBrowser(LoginBrowser):
@need_login
def iter_pocket(self, account):
self.accounts.stay_or_go(subsite=self.subsite)
self.accounts.go(subsite=self.subsite)
for inv in self.iter_investment(account):
if inv._pocket_url:
# Only FCPE investments have pocket link:
self.location(inv._pocket_url)
for pocket in self.page.iter_pocket(inv=inv):
yield pocket
self.location(inv._pocket_url)
for pocket in self.page.iter_pocket(inv=inv):
yield pocket
# don't know if it is still releavent
# need ccb case
ccb_link = self.supp_alert.stay_or_go(subsite=self.subsite).get_pocket_link()
ccb_link = self.accounts.go(subsite=self.subsite).get_pocket_link()
if ccb_link:
for inv in self.location(ccb_link).page.iter_pocket():
for inv in self.location(ccb_link).page.iter_investment():
for poc in self.page.iter_pocket(inv=inv):
yield poc
......
......@@ -55,6 +55,9 @@ class AccountsPage(LoggedPage, HTMLPage):
def get_investment_link(self):
return Link('//a[contains(text(), "Par fonds") or contains(@href,"GoPositionsParFond")]', default=None)(self.doc)
def get_pocket_link(self):
return Link('//a[contains(@href, "CCB")]', default=None)(self.doc)
@method
class iter_accounts(ListElement):
class item(ItemElement):
......@@ -80,11 +83,6 @@ class AccountsPage(LoggedPage, HTMLPage):
return Currency().filter(CleanText('//table[@class="fiche"]//td/small')(self))
class AlertPage(LoggedPage, HTMLPage):
def get_pocket_link(self):
return Link('//a[contains(@href, "CCB")]', default=None)(self.doc)
class FCPEInvestmentPage(LoggedPage, HTMLPage):
@method
class iter_investment(TableElement):
......@@ -147,14 +145,13 @@ class CCBInvestmentPage(LoggedPage, HTMLPage):
continue
inv = Investment()
inv.label = CleanText(el.xpath('./td[has-class("g")]'))(self.doc)
inv.label = CleanText(el.xpath('./td[has-class("i g")]'))(self.doc)
inv.valuation = MyDecimal(el.xpath('./td[last()]'))(self.doc)
i = 1
while i < rowspan:
inv._pocket_url = None
for i in range(1, rowspan):
# valuation is not directly written on website, but it's separated by pocket, so we compute it here,
# and is also written in footer so it's sum of all valuation, not just one
inv.valuation += MyDecimal(el_list[index+i].xpath('./td[last()]'))(self.doc)
i += 1
yield inv
......
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