The new woob repository is here: https://gitlab.com/woob/woob. This gitlab will be removed soon.

The new woob repository is here: https://gitlab.com/woob/woob. This gitlab will be removed soon.

Commit 18337878 authored by Martin Lavoie's avatar Martin Lavoie Committed by Vincent A

[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.
parent bfcd87dc
......@@ -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()
......
......@@ -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']
......
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