Commit 2f376937 authored by Sylvie Ye's avatar Sylvie Ye Committed by Romain Bignon

[societegenerale] handle PLAN_EPARGNE_POPULAIRE as saving account

* Refactorize iter history from old website

* PLAN_EPARGNE_POPULAIRE savings accounts don't have json history
wait for account with transaction to implemente history
parent 417a7323
......@@ -34,7 +34,7 @@ from weboob.tools.value import Value, ValueBool
from .pages.accounts_list import (
AccountsMainPage, AccountDetailsPage, AccountsPage, LoansPage, HistoryPage,
CardHistoryPage, PeaLiquidityPage, AccountsSynthesesPage,
AdvisorPage, HTMLProfilePage, CreditPage, CreditHistoryPage,
AdvisorPage, HTMLProfilePage, CreditPage, CreditHistoryPage, OldHistoryPage,
MarketPage, LifeInsurance, LifeInsuranceHistory, LifeInsuranceInvest, LifeInsuranceInvest2,
UnavailableServicePage,
)
......@@ -57,10 +57,15 @@ class SocieteGenerale(LoginBrowser, StatesMixin):
accounts = URL(r'/icd/cbo/data/liste-prestations-navigation-authsec.json', AccountsPage)
accounts_syntheses = URL(r'/icd/cbo/data/liste-prestations-authsec.json\?n10_avecMontant=1', AccountsSynthesesPage)
history = URL(r'/icd/cbo/data/liste-operations-authsec.json', HistoryPage)
card_history = URL(r'/restitution/cns_listeReleveCarteDd.xml', CardHistoryPage)
loans = URL(r'/abm/restit/listeRestitutionPretsNET.json\?a100_isPretConso=(?P<conso>\w+)', LoansPage)
card_history = URL(r'/restitution/cns_listeReleveCarteDd.xml', CardHistoryPage)
credit = URL(r'/restitution/cns_detailAVPAT.html', CreditPage)
credit_history = URL(r'/restitution/cns_listeEcrCav.xml', CreditHistoryPage)
old_hist_page = URL(r'/restitution/cns_detailPep.html',
r'/restitution/cns_listeEcrPep.html',
r'/restitution/cns_detailAlterna.html',
r'/restitution/cns_listeEncoursAlterna.html', OldHistoryPage)
# Recipient
add_recipient = URL(r'/personnalisation/per_cptBen_ajouterFrBic.html',
......@@ -223,28 +228,22 @@ class SocieteGenerale(LoginBrowser, StatesMixin):
if not account._internal_id:
raise BrowserUnavailable()
if account.type in (account.TYPE_LIFE_INSURANCE, account.TYPE_PERP, ):
# request to get json is not available yet, old request to get html response
# get history for account on old website
# request to get json is not available yet, old request to get html response
if any((
account.type in (account.TYPE_LIFE_INSURANCE, account.TYPE_PERP),
account.type == account.TYPE_REVOLVING_CREDIT and account._loan_type != 'PR_CONSO',
account.type in (account.TYPE_REVOLVING_CREDIT, account.TYPE_SAVINGS) and not account._is_json_histo
)):
self.account_details_page.go(params={'idprest': account._prestation_id})
link = self.page.get_history_link()
if link:
self.location(self.absurl(link))
for tr in self.page.iter_li_history():
yield tr
return
history_url = self.page.get_history_url()
assert history_url
self.location(self.absurl(history_url))
if account.type == account.TYPE_REVOLVING_CREDIT and account._loan_type != 'PR_CONSO':
# request to get json is not available yet, old request to get html response
self.account_details_page.go(params={'idprest': account._prestation_id})
self.page.go_history_page()
for tr in self.page.iter_credit_history():
for tr in self.page.iter_history():
yield tr
return
if account.type == account.TYPE_REVOLVING_CREDIT and not account._is_json_histo:
# Waiting for account with transactions
return
if account.type == account.TYPE_CARD:
self.history.go(params={'b64e200_prestationIdTechnique': account.parent._internal_id})
for summary_card_tr in self.page.iter_card_transactions(card_number=account.number):
......@@ -269,6 +268,10 @@ class SocieteGenerale(LoginBrowser, StatesMixin):
if not account._internal_id:
raise BrowserUnavailable()
if account.type == account.TYPE_SAVINGS and not account._is_json_histo:
# Waiting for account with transactions
return
internal_id = account._internal_id
if account.type == account.TYPE_CARD:
internal_id = account.parent._internal_id
......
......@@ -121,7 +121,7 @@ class AccountsPage(JsonBasePage):
class item(ItemElement):
def condition(self):
return not Dict('etatPrestation')(self) == 'INDISPONIBLE'
return Dict('etatPrestation')(self) != 'INDISPONIBLE'
klass = Account
......@@ -138,6 +138,7 @@ class AccountsPage(JsonBasePage):
'COMPTE_SUR_LIVRET': Account.TYPE_SAVINGS,
'LIVRET_EPARGNE_PLUS': Account.TYPE_SAVINGS,
'PLAN_EPARGNE_BANCAIRE': Account.TYPE_SAVINGS,
'PLAN_EPARGNE_POPULAIRE': Account.TYPE_SAVINGS,
'LIVRET_EPARGNE_POPULAIRE': Account.TYPE_SAVINGS,
'BANQUE_FRANCAISE_MUTUALISEE': Account.TYPE_SAVINGS,
'PRET_GENERAL': Account.TYPE_LOAN,
......@@ -189,6 +190,10 @@ class AccountsPage(JsonBasePage):
if Field('type')(self) == Account.TYPE_REVOLVING_CREDIT and \
not Dict('produit')(self) in ('COMPTE_ALTERNA', 'AVANCE_PATRIMOINE'):
return True
# PLAN_EPARGNE_POPULAIRE account type history is not in json yet
if Field('type')(self) == Account.TYPE_SAVINGS and \
not Dict('produit')(self) in ('PLAN_EPARGNE_POPULAIRE', ):
return True
class AccountsSynthesesPage(JsonBasePage):
def is_new_website_available(self):
......@@ -501,11 +506,11 @@ class CardHistoryPage(LoggedPage, HTMLPage):
class CreditPage(LoggedPage, HTMLPage):
def go_history_page(self):
def get_history_url(self):
redirection_script = CleanText('//script[contains(text(), "setPrestationURL")]')(self.doc)
history_link = re.search(r'setPrestationURL\("(.*)"\)', redirection_script)
if history_link:
self.browser.location(self.browser.absurl(history_link.group(1)))
return history_link.group(1)
class CreditHistoryPage(LoggedPage, HTMLPage):
......@@ -516,7 +521,7 @@ class CreditHistoryPage(LoggedPage, HTMLPage):
return super(CreditHistoryPage, self).build_doc(content)
@method
class iter_credit_history(ListElement):
class iter_history(ListElement):
item_xpath = '//tr'
class item(ItemElement):
......@@ -532,6 +537,24 @@ class CreditHistoryPage(LoggedPage, HTMLPage):
return MyDecimal(CleanText('./td[contains(@headers, "Debit")]', replace=[('&nbsp;', '')]))(self)
class OldHistoryPage(LoggedPage, HTMLPage):
def get_history_url(self):
redirection = CleanText('//body/@onload')(self.doc)
history_link = re.search(r",'(/.*)',", redirection)
if history_link:
return history_link.group(1)
def iter_history(self):
is_no_transaction_msg = any((
self.doc.xpath(u'//div[contains(text(), "Aucune opération trouvée sur la période de restitution possible")]'),
self.doc.xpath(u'//div[contains(text(), "Aucune opération n\'a été réalisée depuis le dernier relevé")]'),
))
assert is_no_transaction_msg, 'There are transactions, retrieve them !'
# waiting for account with history
return []
class LifeInsurance(LoggedPage, HTMLPage):
def on_load(self):
errors_msg = (
......@@ -549,8 +572,9 @@ class LifeInsurance(LoggedPage, HTMLPage):
def has_link(self):
return Link('//a[@href="asvcns20a.html"]', default=NotAvailable)(self.doc)
def get_history_link(self):
return Link('//a[img[@alt="Suivi des opérations"]]', default=NotAvailable)(self.doc)
def get_history_url(self):
history_url = Link('//a[img[@alt="Suivi des opérations"]]', default=NotAvailable)(self.doc)
return history_url
def get_pages(self):
pages = CleanText('//div[@class="net2g_asv_tableau_pager"]')(self.doc)
......@@ -625,7 +649,7 @@ class LifeInsuranceInvest2(LifeInsuranceInvest):
class LifeInsuranceHistory(LifeInsurance):
@pagination
@method
class iter_li_history(TableElement):
class iter_history(TableElement):
def next_page(self):
return self.page.li_pagination()
......
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