Maxime Gasselin
Committed by Romain Bignon

[hsbc] Add History for Scpi market account

The navigation to the history has been inspired by the invest scpi navigation.

Closes: 16236@sibi
......@@ -36,7 +36,7 @@ from weboob.capabilities.base import find_object
from .pages.account_pages import (
AccountsPage, OwnersListPage, CBOperationPage, CPTOperationPage, LoginPage,
AppGonePage, RibPage, UnavailablePage, OtherPage, FrameContainer, ProfilePage,
AppGonePage, RibPage, UnavailablePage, OtherPage, FrameContainer, ProfilePage, ScpiHisPage
)
from .pages.life_insurances import (
LifeInsurancesPage, LifeInsurancePortal, LifeInsuranceMain, LifeInsuranceUseless,
......@@ -58,6 +58,7 @@ class HSBC(LoginBrowser):
app_gone = False
scpi_investment_page = URL(r'https://www.hsbc.fr/1/[0-9]/.*', ScpiInvestmentPage)
scpi_his_page = URL(r'https://www.hsbc.fr/1/[0-9]/.*', ScpiHisPage)
connection = URL(r'https://www.hsbc.fr/1/2/hsbc-france/particuliers/connexion', LoginPage)
login = URL(r'https://www.hsbc.fr/1/*', LoginPage)
cptPage = URL(r'/cgi-bin/emcgi.*\&Cpt=.*',
......@@ -325,6 +326,21 @@ class HSBC(LoginBrowser):
if account.url.startswith('javascript') or '&Crd=' in account.url or account.type == Account.TYPE_LOAN:
raise NotImplementedError()
if account.type == Account.TYPE_MARKET and not 'BOURSE_INV' in account.url:
# Clean account url
m = re.search(r"'(.*)'", account.url)
if m:
account_url = m.group(1)
else:
account_url = account.url
# Need to be on accounts page to go on scpi page
self.accounts.go()
# Go on scpi page
self.location(account_url)
self.location(self.page.go_scpi_his_detail_page())
return self.page.iter_history()
if account.type in (Account.TYPE_LIFE_INSURANCE, Account.TYPE_CAPITALISATION):
if coming is True:
return []
......
......@@ -26,10 +26,10 @@ from weboob.capabilities.bank import Account
from weboob.tools.capabilities.bank.transactions import FrenchTransaction
from weboob.tools.compat import urljoin
from weboob.exceptions import BrowserIncorrectPassword, BrowserUnavailable, ActionNeeded
from weboob.browser.elements import ListElement, ItemElement, method
from weboob.browser.pages import HTMLPage, pagination
from weboob.browser.elements import ListElement, ItemElement, method, TableElement
from weboob.browser.pages import HTMLPage, pagination, LoggedPage
from weboob.browser.filters.standard import (
Filter, Env, CleanText, CleanDecimal, Field, DateGuesser, Regexp, Currency,
Filter, Env, CleanText, CleanDecimal, Field, DateGuesser, Regexp, Currency, Format, Date
)
from weboob.browser.filters.html import AbsoluteLink, TableCell
from weboob.browser.filters.javascript import JSVar
......@@ -431,3 +431,25 @@ class ProfilePage(OtherPage):
obj_name = CleanText('//div[@id="div_adr_P1"]//p/label[contains(text(), "Nom")]/parent::p/strong')
obj_address = CleanText('//div[@id="div_adr_P1"]//p/label[contains(text(), "Adresse")]/parent::p/strong')
class ScpiHisPage(LoggedPage, HTMLPage):
def is_here(self):
return self.doc.xpath('//h3[contains(text(), "HISTORIQUE DES MOUVEMENTS")]')
@method
class iter_history(TableElement):
item_xpath = '//table[@class="csTable"]//tbody//tr'
head_xpath = '//table[@class="csTable"]//thead//th/a'
col_date = 'Date'
col_amount = 'Montant brut (en €)'
col_operation = 'Opération'
col_nature = 'Nature'
class item(ItemElement):
klass = Transaction
obj_label = Format('%s - %s', CleanText(TableCell('operation')), CleanText(TableCell('nature')))
obj_rdate = Date(CleanText(TableCell('date')), dayfirst=True)
obj_amount = CleanDecimal(TableCell('amount'), sign=lambda x: -1, replace_dots=True)
......
......@@ -16,7 +16,7 @@ from weboob.browser.pages import HTMLPage, JsonPage, LoggedPage
from weboob.browser.filters.standard import (
CleanText, CleanDecimal, Regexp, Currency, Field, Env,
)
from weboob.browser.filters.html import TableCell
from weboob.browser.filters.html import TableCell, Link
from weboob.browser.filters.json import Dict
from weboob.browser.filters.javascript import JSVar
from weboob.exceptions import BrowserUnavailable
......@@ -524,6 +524,9 @@ class ScpiInvestmentPage(LoggedPage, HTMLPage):
assert len(detail_page) == 1
self.browser.location('https://www.hsbc.fr' + CleanText('./@href')(detail_page[0]))
def go_scpi_his_detail_page(self):
return Link('//div/a[contains(text(), "Historique de vos mouvements de parts")]')(self.doc)
@method
class iter_scpi_investment(TableElement):
item_xpath = '//table[@class="csTable"]//tbody//tr'
......