From 1cca0fe471a1a0f0e408ffb2fac2cf0be5007137 Mon Sep 17 00:00:00 2001 From: Sylvie Ye Date: Thu, 24 Jan 2019 18:19:46 +0100 Subject: [PATCH] [societegenerale] handle revolving credit as loan object --- modules/societegenerale/browser.py | 9 +++- .../societegenerale/pages/accounts_list.py | 54 ++++++++++++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/modules/societegenerale/browser.py b/modules/societegenerale/browser.py index 6083af09ed..011061c957 100644 --- a/modules/societegenerale/browser.py +++ b/modules/societegenerale/browser.py @@ -186,9 +186,13 @@ def get_accounts_list(self): 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 @@ def iter_history(self, account): 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() diff --git a/modules/societegenerale/pages/accounts_list.py b/modules/societegenerale/pages/accounts_list.py index 8b42f3a776..5c0fee8111 100644 --- a/modules/societegenerale/pages/accounts_list.py +++ b/modules/societegenerale/pages/accounts_list.py @@ -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 item(ItemElement): '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 item(ItemElement): '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 @@ def obj_type(self): 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 @@ def get_loan_account(self, account): 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
\d{2})\/(?P\d{2})( (?P\d+)H(?P\d+))? (?P.*)'), -- GitLab