From 283389ea0e555ebae0b0a9a4571d38d5d274afb0 Mon Sep 17 00:00:00 2001 From: Maxime Pommier Date: Tue, 30 Apr 2019 14:12:56 +0200 Subject: [PATCH] [societegenerale] Added the debit account as the loan's parent --- modules/societegenerale/browser.py | 10 ++++++++ .../societegenerale/pages/accounts_list.py | 24 ++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/modules/societegenerale/browser.py b/modules/societegenerale/browser.py index c6f03f46dd..6d922ebe46 100644 --- a/modules/societegenerale/browser.py +++ b/modules/societegenerale/browser.py @@ -199,8 +199,11 @@ def get_accounts_list(self): # get accounts coming account_comings = self.page.get_account_comings() + accounts = {} + self.accounts.go() for account in self.page.iter_accounts(): + account._parent_id = None for card in self.iter_cards(account): card.parent = account card.ownership = account.ownership @@ -225,6 +228,13 @@ def get_accounts_list(self): self.loan_details_page.go(params={'b64e200_prestationIdTechnique': account._internal_id}) self.page.set_loan_details(account) + accounts[account.id] = account + + # Adding parent account to LOAN account + for account_id, account in accounts.items(): + if account._parent_id: + account.parent = accounts.get(account._parent_id, NotAvailable) + yield account @need_login diff --git a/modules/societegenerale/pages/accounts_list.py b/modules/societegenerale/pages/accounts_list.py index 2c3e6be692..f561f55883 100644 --- a/modules/societegenerale/pages/accounts_list.py +++ b/modules/societegenerale/pages/accounts_list.py @@ -33,7 +33,8 @@ from weboob.browser.elements import DictElement, ItemElement, TableElement, method, ListElement from weboob.browser.filters.json import Dict from weboob.browser.filters.standard import ( - CleanText, CleanDecimal, Regexp, Currency, Eval, Field, Format, Date, Env, Map + CleanText, CleanDecimal, Regexp, Currency, Eval, Field, Format, Date, Env, Map, Coalesce, + empty, ) from weboob.browser.filters.html import Link, TableCell from weboob.browser.pages import HTMLPage, XMLPage, JsonPage, LoggedPage, pagination @@ -246,6 +247,18 @@ def set_loan_details(self, account): class LoansPage(JsonBasePage): + + def set_parent_account_id(self, loan, acc): + account_parent = Coalesce( + Dict('prestationCAV', default=NotAvailable), + Dict('comptePrelevement1', default=NotAvailable), + default=NotAvailable + )(acc) + + loan._parent_id = None + if not empty(account_parent): + loan._parent_id = account_parent.replace(' ', '') + def get_loan_account(self, account): assert account._prestation_id in Dict('donnees/tabIdAllPrestations')(self.doc), \ 'Loan with prestation id %s should be on this page ...' % account._prestation_id @@ -275,10 +288,12 @@ def get_loan_account(self, account): now = datetime.datetime.now().date() next_payment_date = now.replace(day=repayment_day) if repayment_day < now.day: - next_payment_date += relativedelta(months=+1) + next_payment_date += relativedelta(months=1) loan.next_payment_date = next_payment_date else: - self.logger.warning('Not handled periodicity: %s' % CleanText(Dict('periodicite'))(acc)) + self.logger.warning('Not handled periodicity: %s', CleanText(Dict('periodicite'))(acc)) + + self.set_parent_account_id(loan, acc) loan._internal_id = account._internal_id loan._prestation_id = account._prestation_id @@ -340,6 +355,9 @@ def get_revolving_account(self, account): if Dict('dateMensualite', default=NotAvailable)(acc): loan.next_payment_date = datetime.datetime.strptime(Dict('dateMensualite')(acc), '%Y%m%d') + + self.set_parent_account_id(loan, acc) + return loan return loan -- GitLab