From 18337878abd7f2baac848cd25f172759503a4743 Mon Sep 17 00:00:00 2001 From: Martin Lavoie Date: Fri, 18 Jun 2021 09:44:24 +0200 Subject: [PATCH] [bnporc] Add owner_type to some accounts We can reliabely know if an account is pro only from the transfert initiation page. As such, only checking accounts and some saving accounts are supported. For the other accounts, we try to set something based on the label. --- modules/bnporc/pp/browser.py | 11 +++++++++-- modules/bnporc/pp/pages.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/modules/bnporc/pp/browser.py b/modules/bnporc/pp/browser.py index e252ec211c..ac6ee2f8be 100644 --- a/modules/bnporc/pp/browser.py +++ b/modules/bnporc/pp/browser.py @@ -353,13 +353,20 @@ def iter_accounts(self): raise ActionNeeded("Veuillez réaliser l'authentification forte depuis votre navigateur.") ibans = self.page.get_ibans_dict() + is_pro = {} # This page might be unavailable. try: - ibans.update(self.transfer_init.go(json={'modeBeneficiaire': '0'}).get_ibans_dict('Crediteur')) + self.transfer_init.go(json={'modeBeneficiaire': '0'}) + ibans.update(self.page.get_ibans_dict('Crediteur')) + is_pro = self.page.get_pro_accounts('Crediteur') except (TransferAssertionError, AttributeError): pass - accounts = list(self.accounts.go().iter_accounts(ibans=ibans)) + self.accounts.go() + accounts = list(self.page.iter_accounts( + ibans=ibans, + is_pro=is_pro, + )) self.market_syn.go(json={}) market_accounts = self.page.get_list() # get the list of 'Comptes Titres' checked_accounts = set() diff --git a/modules/bnporc/pp/pages.py b/modules/bnporc/pp/pages.py index 5d115afb29..574e18070b 100644 --- a/modules/bnporc/pp/pages.py +++ b/modules/bnporc/pp/pages.py @@ -31,7 +31,7 @@ from woob.browser.filters.json import Dict from woob.browser.filters.standard import ( Format, Eval, Regexp, CleanText, Date, CleanDecimal, - Field, Coalesce, Map, MapIn, Env, Currency, FromTimestamp, + Field, Coalesce, Map, MapIn, Env, Currency, FromTimestamp, Lower, ) from woob.browser.filters.html import TableCell from woob.browser.pages import JsonPage, LoggedPage, HTMLPage, PartialHTMLPage, RawPage @@ -41,6 +41,7 @@ AddRecipientBankError, AccountOwnership, Emitter, EmitterNumberType, TransferStatus, TransferDateType, TransferInvalidAmount, + AccountOwnerType, ) from woob.capabilities.wealth import ( Investment, MarketOrder, MarketOrderDirection, @@ -374,6 +375,25 @@ def obj_iban(self): return iban return None + def obj_owner_type(self): + is_pro = Map(Dict('key'), Env('is_pro')(self), default=NotAvailable)(self) + # For checking account, we can often get + # the true value from the transfer page response + if is_pro: + return AccountOwnerType.ORGANIZATION + elif is_pro != NotAvailable: + return AccountOwnerType.PRIVATE + + # Loan and savings accounts "often" include + # this information in their label. + label = Lower(Field('label'))(self) + if 'professionnel' in label: + return AccountOwnerType.ORGANIZATION + elif re.search('particulier|personnel', label): + return AccountOwnerType.PRIVATE + + return NotAvailable + def obj_ownership(self): indic = Dict('titulaire/indicTitulaireCollectif', default=None)(self) # The boolean is in the form of a string ('true' or 'false') @@ -445,6 +465,13 @@ def get_ibans_dict(self, account_type): return dict([(a['ibanCrypte'], a['iban']) for a in self.path('data.infoVirement.listeComptes%s.*' % account_type)]) + def get_pro_accounts(self, account_type): + comptes = self.path('data.infoVirement.listeComptes%s.*' % account_type) + return { + compte['ibanCrypte']: compte.get('indicComptePro', False) + for compte in comptes + } + def can_transfer_to_recipients(self, origin_account_id): return next( a['eligibleVersBenef'] -- GitLab