Commit f3efae3d authored by Martin Sicot's avatar Martin Sicot Committed by Romain Bignon

[caissedepargne] Cenet Loans

Loan page added (middle to long term) Might need to adapt for short term
loans when finding one case.

closes:9665@zendesk
parent aa9911e4
......@@ -33,6 +33,7 @@ from .pages import (
LoginPage, CenetLoginPage, CenetHomePage,
CenetAccountsPage, CenetAccountHistoryPage, CenetCardsPage,
CenetCardSummaryPage, SubscriptionPage, DownloadDocumentPage,
CenetLoanPage,
)
from ..pages import CaissedepargneKeyboard
......@@ -52,6 +53,7 @@ class CenetBrowser(LoginBrowser, StatesMixin):
cenet_vk = URL('https://www.cenet.caisse-epargne.fr/Web/Api/ApiAuthentification.asmx/ChargerClavierVirtuel')
cenet_home = URL('/Default.aspx$', CenetHomePage)
cenet_accounts = URL('/Web/Api/ApiComptes.asmx/ChargerSyntheseComptes', CenetAccountsPage)
cenet_loans = URL('/Web/Api/ApiFinancements.asmx/ChargerListeFinancementsMLT', CenetLoanPage)
cenet_account_history = URL('/Web/Api/ApiComptes.asmx/ChargerHistoriqueCompte', CenetAccountHistoryPage)
cenet_account_coming = URL('/Web/Api/ApiCartesBanquaires.asmx/ChargerEnCoursCarte', CenetAccountHistoryPage)
cenet_tr_detail = URL('/Web/Api/ApiComptes.asmx/ChargerDetailOperation', CenetCardSummaryPage)
......@@ -120,11 +122,6 @@ class CenetBrowser(LoginBrowser, StatesMixin):
@need_login
def get_accounts_list(self):
if self.accounts is None:
headers = {
'Content-Type': 'application/json; charset=UTF-8',
'Accept': 'application/json, text/javascript, */*; q=0.01'
}
data = {
'contexte': '',
'dateEntree': None,
......@@ -133,15 +130,17 @@ class CenetBrowser(LoginBrowser, StatesMixin):
}
try:
self.accounts = [account for account in self.cenet_accounts.go(data=json.dumps(data), headers=headers).get_accounts()]
self.accounts = [account for account in self.cenet_accounts.go(json=data).get_accounts()]
except ClientError:
# Unauthorized due to wrongpass
raise BrowserIncorrectPassword()
self.cenet_loans.go(json=data)
for account in self.page.get_accounts():
self.accounts.append(account)
for account in self.accounts:
try:
account._cards = []
self.cenet_cards.go(data=json.dumps(data), headers=headers)
self.cenet_cards.go(json=data)
for card in self.page.get_cards():
if card['Compte']['Numero'] == account.id:
......
......@@ -23,10 +23,10 @@ from datetime import datetime
from weboob.browser.pages import LoggedPage, HTMLPage, JsonPage
from weboob.browser.elements import DictElement, ItemElement, method
from weboob.browser.filters.standard import Date, CleanDecimal, CleanText, Format, Field, Env, Regexp
from weboob.browser.filters.standard import Date, CleanDecimal, CleanText, Format, Field, Env, Regexp, Currency
from weboob.browser.filters.json import Dict
from weboob.capabilities import NotAvailable
from weboob.capabilities.bank import Account, Transaction
from weboob.capabilities.bank import Account, Transaction, Loan
from weboob.capabilities.contact import Advisor
from weboob.capabilities.profile import Profile
from weboob.capabilities.bill import DocumentTypes, Subscription, Document
......@@ -117,6 +117,37 @@ class CenetAccountsPage(LoggedPage, CenetJsonPage):
return self.el
class CenetLoanPage(LoggedPage, CenetJsonPage):
@method
class get_accounts(DictElement):
item_xpath = "DonneesSortie"
class item(ItemElement):
klass = Loan
obj_id = CleanText(Dict('IdentifiantUniqueContrat'))
obj_label = CleanText(Dict('Libelle'))
obj_total_amount = CleanDecimal(Dict('MontantInitial/Valeur'))
obj_currency = Currency(Dict('MontantInitial/Devise'))
obj_balance = CleanDecimal(Dict('CapitalRestantDu/Valeur'))
obj_type = Account.TYPE_LOAN
obj_duration = CleanDecimal(Dict('Duree'))
obj_rate = CleanDecimal.French(Dict('Taux'))
obj_next_payment_amount = CleanDecimal(Dict('MontantProchaineEcheance/Valeur'))
def obj_subscription_date(self):
date = CleanDecimal(Dict('DateDebutEffet'))(self) / 1000
return datetime.fromtimestamp(date).date()
def obj_maturity_date(self):
date = CleanDecimal(Dict('DateDerniereEcheance'))(self) / 1000
return datetime.fromtimestamp(date).date()
def obj_next_payment_date(self):
date = CleanDecimal(Dict('DateProchaineEcheance'))(self) / 1000
return datetime.fromtimestamp(date).date()
class CenetCardsPage(LoggedPage, CenetJsonPage):
def get_cards(self):
cards = Dict('DonneesSortie')(self.doc)
......
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