From fc98da7fa7a2868a818bd6a6dc78f312da1e4f3d Mon Sep 17 00:00:00 2001 From: Maxime Gasselin Date: Tue, 27 Nov 2018 18:24:37 +0100 Subject: [PATCH] [hsbc] Add History for Scpi market account The navigation to the history has been inspired by the invest scpi navigation. Closes: 16236@sibi --- modules/hsbc/browser.py | 18 +++++++++++++++++- modules/hsbc/pages/account_pages.py | 28 +++++++++++++++++++++++++--- modules/hsbc/pages/investments.py | 5 ++++- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/modules/hsbc/browser.py b/modules/hsbc/browser.py index 0985c4c7b1..bd75e9302c 100644 --- a/modules/hsbc/browser.py +++ b/modules/hsbc/browser.py @@ -36,7 +36,7 @@ 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 @@ def get_history(self, account, coming=False, retry_li=True): 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 [] diff --git a/modules/hsbc/pages/account_pages.py b/modules/hsbc/pages/account_pages.py index 089ba1ce94..2c04e5fa53 100644 --- a/modules/hsbc/pages/account_pages.py +++ b/modules/hsbc/pages/account_pages.py @@ -26,10 +26,10 @@ 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 get_profile(ItemElement): 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) diff --git a/modules/hsbc/pages/investments.py b/modules/hsbc/pages/investments.py index b1e382d17d..63147b3d73 100644 --- a/modules/hsbc/pages/investments.py +++ b/modules/hsbc/pages/investments.py @@ -16,7 +16,7 @@ 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 @@ def go_more_scpi_detail_page(self): 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' -- GitLab