diff --git a/modules/bnporc/pp/browser.py b/modules/bnporc/pp/browser.py index e252ec211c930b15f144c633e578158c148fd96c..ac6ee2f8bea64470c46e763eb8ced350347b5bde 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 5d115afb2967144fb60b3c96d785d64d801bef3a..574e18070bd540d6ae34fa3cdc443187e0850e15 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']