Commit 82578ccb authored by Célande Adrien's avatar Célande Adrien Committed by Romain Bignon

[caissedepargne] bank statement for CaisseEpargneBrowser

parent f1235679
......@@ -45,7 +45,8 @@ from .pages import (
TransferPage, ProTransferPage, TransferConfirmPage, TransferSummaryPage, ProTransferConfirmPage,
ProTransferSummaryPage, ProAddRecipientOtpPage, ProAddRecipientPage,
SmsPage, SmsPageOption, SmsRequest, AuthentPage, RecipientPage, CanceledAuth, CaissedepargneKeyboard,
TransactionsDetailsPage, LoadingPage, ConsLoanPage, MeasurePage, NatixisLIHis, NatixisLIInv, NatixisRedirectPage
TransactionsDetailsPage, LoadingPage, ConsLoanPage, MeasurePage, NatixisLIHis, NatixisLIInv, NatixisRedirectPage,
SubscriptionPage,
)
from .linebourse_browser import LinebourseBrowser
......@@ -76,6 +77,7 @@ class CaisseEpargne(LoginBrowser, StatesMixin):
pro_add_recipient = URL('https://.*/Portail.aspx.*', ProAddRecipientPage)
measure_page = URL('https://.*/Portail.aspx.*', MeasurePage)
authent = URL('https://.*/Portail.aspx.*', AuthentPage)
subscription = URL('https://.*/Portail.aspx\?tache=(?P<tache>).*', SubscriptionPage)
home = URL('https://.*/Portail.aspx.*', IndexPage)
home_tache = URL('https://.*/Portail.aspx\?tache=(?P<tache>).*', IndexPage)
error = URL('https://.*/login.aspx',
......@@ -660,3 +662,37 @@ class CaisseEpargne(LoginBrowser, StatesMixin):
self.page.check_canceled_auth()
self.page.set_browser_form()
raise AddRecipientStep(self.get_recipient_obj(recipient), Value('sms_password', label=self.page.get_prompt_text()))
@need_login
def iter_subscription(self):
self.home.go()
self.home_tache.go(tache='CPTSYNT1')
self.page.go_subscription()
assert self.subscription.is_here()
return self.page.iter_subscription()
@need_login
def iter_documents(self, subscription):
self.home.go()
self.home_tache.go(tache='CPTSYNT1')
self.page.go_subscription()
assert self.subscription.is_here()
sub_id = subscription.id
self.page.go_document_list(sub_id=sub_id)
for doc in self.page.iter_documents(sub_id=sub_id):
yield doc
@need_login
def download_document(self, document):
self.home.go()
self.home_tache.go(tache='CPTSYNT1')
self.page.go_subscription()
assert self.subscription.is_here()
sub_id = document.id.split('_')[0]
self.page.go_document_list(sub_id=sub_id)
return self.page.download_document(document).content
......@@ -22,6 +22,11 @@ import re
from decimal import Decimal
from weboob.capabilities.bank import CapBankWealth, CapBankTransferAddRecipient, AccountNotFound, Account, RecipientNotFound
from weboob.capabilities.bill import (
CapDocument, Subscription, SubscriptionNotFound,
Document, DocumentNotFound,
)
from weboob.capabilities.base import NotAvailable
from weboob.capabilities.contact import CapContact
from weboob.capabilities.profile import CapProfile
from weboob.capabilities.base import find_object
......@@ -33,7 +38,7 @@ from .proxy_browser import ProxyBrowser
__all__ = ['CaisseEpargneModule']
class CaisseEpargneModule(Module, CapBankWealth, CapBankTransferAddRecipient, CapContact, CapProfile):
class CaisseEpargneModule(Module, CapBankWealth, CapBankTransferAddRecipient, CapContact, CapProfile, CapDocument):
NAME = 'caissedepargne'
MAINTAINER = u'Romain Bignon'
EMAIL = 'romain@weboob.org'
......@@ -110,3 +115,37 @@ class CaisseEpargneModule(Module, CapBankWealth, CapBankTransferAddRecipient, Ca
def new_recipient(self, recipient, **params):
#recipient.label = ' '.join(w for w in re.sub('[^0-9a-zA-Z:\/\-\?\(\)\.,\'\+ ]+', '', recipient.label).split())
return self.browser.new_recipient(recipient, **params)
def iter_resources(self, objs, split_path):
if Account in objs:
self._restrict_level(split_path)
return self.iter_accounts()
if Subscription in objs:
self._restrict_level(split_path)
return self.iter_subscription()
def get_subscription(self, _id):
return find_object(self.iter_subscription(), id=_id, error=SubscriptionNotFound)
def get_document(self, _id):
subscription_id = _id.split('_')[0]
subscription = self.get_subscription(subscription_id)
return find_object(self.iter_documents(subscription), id=_id, error=DocumentNotFound)
def iter_subscription(self):
return self.browser.iter_subscription()
def iter_documents(self, subscription):
if not isinstance(subscription, Subscription):
subscription = self.get_subscription(subscription)
return self.browser.iter_documents(subscription)
def download_document(self, document):
if not isinstance(document, Document):
document = self.get_document(document)
if document.url is NotAvailable:
return
return self.browser.download_document(document)
......@@ -30,11 +30,12 @@ from datetime import datetime
from weboob.browser.pages import LoggedPage, HTMLPage, JsonPage, pagination, FormNotFound
from weboob.browser.elements import ItemElement, method, ListElement, TableElement, SkipItem, DictElement
from weboob.browser.filters.standard import Date, CleanDecimal, Regexp, CleanText, Env, Upper, Field, Eval
from weboob.browser.filters.standard import Date, CleanDecimal, Regexp, CleanText, Env, Upper, Field, Eval, Format
from weboob.browser.filters.html import Link, Attr, TableCell
from weboob.capabilities import NotAvailable
from weboob.capabilities.bank import Account, Investment, Recipient, TransferError, TransferBankError, Transfer,\
AddRecipientError, Loan
from weboob.capabilities.bill import Subscription, Document
from weboob.tools.capabilities.bank.transactions import FrenchTransaction
from weboob.tools.capabilities.bank.iban import is_rib_valid, rib2iban, is_iban_valid
from weboob.tools.captcha.virtkeyboard import GridVirtKeyboard
......@@ -650,6 +651,13 @@ class IndexPage(LoggedPage, HTMLPage):
if msg:
return msg
def go_subscription(self):
form = self.get_form(name='main')
form['m_ScriptManager'] = 'MM$m_UpdatePanel|MM$Menu_Ajax'
form['__EVENTTARGET'] = 'MM$Menu_Ajax'
form['__EVENTARGUMENT'] = 'CPTEDOC&codeMenu=WCE0'
form.submit()
class ConsLoanPage(JsonPage):
def get_conso(self):
......@@ -1251,3 +1259,55 @@ class TransactionsDetailsPage(LoggedPage, HTMLPage):
form = self.get_form(name='main')
form['__EVENTTARGET'] = "MM$ECRITURE_GLOBALE$lnkRetourHisto"
form.submit()
class SubscriptionPage(LoggedPage, HTMLPage):
def is_here(self):
return self.doc.xpath('//h2[text()="e-Documents"]')
@method
class iter_subscription(ListElement):
item_xpath = '//select[contains(@id, "ClientsBancaires")]/option'
class item(ItemElement):
klass = Subscription
obj_id = Attr('.', 'value')
obj_label = CleanText('.')
obj_subscriber = CleanText('.')
def condition(self):
return 'Clos' not in Field('label')(self)
def go_document_list(self, sub_id):
target = Attr('//select[contains(@id, "ClientsBancaires")]', 'id')(self.doc)
form = self.get_form(name='main')
form['m_ScriptManager'] = target
form['MM$COMPTE_EDOCUMENTS$ctrlEDocumentsConsultationDocument$cboClientsBancaires'] = sub_id
form['__EVENTTARGET'] = target
form.submit()
def get_years(self):
return self.doc.xpath('//select[contains(@id, "Annee")]/option')
@method
class iter_documents(ListElement):
item_xpath = '//ul[@class="telecharger"]/li/a'
class item(ItemElement):
klass = Document
obj_label = Format('%s %s', CleanText('./preceding::h3[1]'), CleanText('./span'))
obj_date = Date(CleanText('./span'), dayfirst=True)
obj_type = 'other'
obj_format = 'pdf'
obj_url = Regexp(Link('.'), r'WebForm_PostBackOptions\("(\S*)"')
obj_id = Format('%s_%s_%s', Env('sub_id'), CleanText('./span', symbols='/'), Regexp(Field('url'), r'ctl(.*)'))
obj__event_id = Regexp(Attr('.', 'onclick'), r"val\('(.*)'\);")
def download_document(self, document):
form = self.get_form(name='main')
form['m_ScriptManager'] = document.url
form['__EVENTTARGET'] = document.url
form['MM$COMPTE_EDOCUMENTS$ctrlEDocumentsConsultationDocument$eventId'] = document._event_id
return form.submit()
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