Commit 1cca0fe4 authored by Sylvie Ye's avatar Sylvie Ye Committed by Romain Bignon

[societegenerale] handle revolving credit as loan object

parent d0ef9f6b
......@@ -186,9 +186,13 @@ class SocieteGenerale(LoginBrowser, StatesMixin):
account.coming = account_comings[account._prestation_id]
if account.type in (account.TYPE_LOAN, account.TYPE_CONSUMER_CREDIT, ):
self.loans.go(conso=(account._loan_type == 'PR_CONSO'))
self.loans.stay_or_go(conso=(account._loan_type == 'PR_CONSO'))
account = self.page.get_loan_account(account)
if account.type == account.TYPE_REVOLVING_CREDIT:
self.loans.stay_or_go(conso=(account._loan_type == 'PR_CONSO'))
account = self.page.get_revolving_account(account)
yield account
@need_login
......@@ -210,6 +214,9 @@ class SocieteGenerale(LoginBrowser, StatesMixin):
return
if account.type == account.TYPE_REVOLVING_CREDIT:
if account._loan_type == 'PR_CONSO':
return
# 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()
......
......@@ -44,6 +44,12 @@ def MyDecimal(*args, **kwargs):
return CleanDecimal(*args, **kwargs)
def eval_decimal_amount(value, decimal_position):
return Eval(lambda x,y: x / 10**y,
CleanDecimal(Dict(value)),
CleanDecimal(Dict(decimal_position)))
class JsonBasePage(LoggedPage, JsonPage):
def on_load(self):
if Dict('commun/statut')(self.doc).upper() == 'NOK':
......@@ -87,6 +93,7 @@ class AccountsPage(JsonBasePage):
'LDD': Account.TYPE_SAVINGS,
'LIVRETA': Account.TYPE_SAVINGS,
'LIVRET_JEUNE': Account.TYPE_SAVINGS,
'LIVRET_EUROKID': Account.TYPE_SAVINGS,
'COMPTE_SUR_LIVRET': Account.TYPE_SAVINGS,
'LIVRET_EPARGNE_PLUS': Account.TYPE_SAVINGS,
'PLAN_EPARGNE_BANCAIRE': Account.TYPE_SAVINGS,
......@@ -102,6 +109,8 @@ class AccountsPage(JsonBasePage):
'VIE_FEDER': Account.TYPE_LIFE_INSURANCE,
'PALISSANDRE': Account.TYPE_LIFE_INSURANCE,
'ASSURANCE_VIE_GENERALE': Account.TYPE_LIFE_INSURANCE,
'RESERVEA': Account.TYPE_REVOLVING_CREDIT,
'COMPTE_ALTERNA': Account.TYPE_REVOLVING_CREDIT,
'AVANCE_PATRIMOINE': Account.TYPE_REVOLVING_CREDIT,
'PRET_EXPRESSO': Account.TYPE_CONSUMER_CREDIT,
'PRET_EVOLUTIF': Account.TYPE_CONSUMER_CREDIT,
......@@ -123,7 +132,8 @@ class AccountsPage(JsonBasePage):
obj__prestation_id = Dict('id')
def obj__loan_type(self):
if Field('type')(self) in (Account.TYPE_LOAN, Account.TYPE_CONSUMER_CREDIT, ):
if Field('type')(self) in (Account.TYPE_LOAN, Account.TYPE_CONSUMER_CREDIT,
Account.TYPE_REVOLVING_CREDIT, ):
return Dict('codeFamille')(self)
return None
......@@ -162,8 +172,50 @@ class LoansPage(JsonBasePage):
loan._internal_id = account._internal_id
loan._prestation_id = account._prestation_id
loan._loan_type = account._loan_type
return loan
def get_revolving_account(self, account):
loan = Loan()
loan.id = loan.number = account.id
loan.label = account.label
loan.type = account.type
loan.currency = account.currency
loan.balance = account.balance
loan.coming = account.coming
loan._internal_id = account._internal_id
loan._prestation_id = account._prestation_id
loan._loan_type = account._loan_type
if Dict('donnees/tabIdAllPrestations')(self.doc):
for acc in Dict('donnees/tabPrestations')(self.doc):
if CleanText(Dict('idPrestation'))(acc) == account._prestation_id:
if Dict('encoursFinMois', default=NotAvailable)(acc):
loan.coming = eval_decimal_amount('encoursFinMois/valeur', 'encoursFinMois/posDecimale')(acc)
if Dict('reserveAutorisee', default=NotAvailable)(acc):
loan.total_amount = eval_decimal_amount('reserveAutorisee/valeur', 'reserveAutorisee/posDecimale')(acc)
else:
loan.total_amount = eval_decimal_amount('reserveMaximum/valeur', 'reserveMaximum/posDecimale')(acc)
loan.available_amount = eval_decimal_amount('reserveDispo/valeur', 'reserveDispo/posDecimale')(acc)
if Dict('reserveUtilisee', default=NotAvailable)(acc):
loan.used_amount = eval_decimal_amount('reserveUtilisee/valeur', 'reserveUtilisee/posDecimale')(acc)
if Dict('prochaineEcheance', default=NotAvailable)(acc):
loan.next_payment_amount = eval_decimal_amount('prochaineEcheance/valeur', 'prochaineEcheance/posDecimale')(acc)
else:
loan.next_payment_amount = eval_decimal_amount('montantMensualite/valeur', 'montantMensualite/posDecimale')(acc)
loan.last_payment_amount = loan.next_payment_amount
loan.duration = Dict('dureeNbMois')(acc)
return loan
return loan
class Transaction(FrenchTransaction):
PATTERNS = [(re.compile(r'^CARTE \w+ RETRAIT DAB.*? (?P<dd>\d{2})\/(?P<mm>\d{2})( (?P<HH>\d+)H(?P<MM>\d+))? (?P<text>.*)'),
......
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