From 7b4c9781aa345fed5d281b3547ec216ee0d80729 Mon Sep 17 00:00:00 2001 From: Etienne Lachere Date: Wed, 13 Nov 2019 14:04:25 -0500 Subject: [PATCH] [axabanque] add account ownership --- modules/axabanque/browser.py | 24 +++++++++++++++++++++++- modules/axabanque/pages/bank.py | 10 +++++++++- modules/axabanque/pages/wealth.py | 3 ++- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/modules/axabanque/browser.py b/modules/axabanque/browser.py index 247cb2d66e..2fae880266 100644 --- a/modules/axabanque/browser.py +++ b/modules/axabanque/browser.py @@ -27,7 +27,9 @@ from weboob.browser.exceptions import ClientError, HTTPNotFound from weboob.capabilities.base import NotAvailable from weboob.capabilities.bill import Subscription -from weboob.capabilities.bank import Account, Transaction, AddRecipientStep, Recipient +from weboob.capabilities.bank import ( + Account, Transaction, AddRecipientStep, Recipient, AccountOwnership, +) from weboob.exceptions import BrowserIncorrectPassword, ActionNeeded from weboob.tools.value import Value from weboob.tools.capabilities.bank.transactions import sorted_transactions @@ -175,6 +177,7 @@ def iter_accounts(self): if 'accs' not in self.cache.keys(): accounts = [] ids = set() + owner_name = self.get_profile().name.upper().split(' ', 1)[1] # Get accounts self.transactions.go() self.bank_accounts.go() @@ -220,6 +223,7 @@ def iter_accounts(self): break # Need it to get accounts from tabs a._tab, a._pargs, a._purl = tab, page_args, self.url + self.set_ownership(a, owner_name) accounts.append(a) # Get investment accounts if there has self.wealth_accounts.go() @@ -233,6 +237,24 @@ def iter_accounts(self): self.bank_accounts.go() return self.cache['accs'] + def set_ownership(self, account, owner_name): + # Some accounts _owner attribute says 'MLLE PRENOM NOM1' or other + # only 'NOM' while profile.name is 'MME PRENOM NOM1 NOM2' or 'MME PRENOM NOM' + # It makes it pretty hard to determine precisely wether the owernship + # should be OWNER or ATTORNEY. So we prefer set it to NotAvailable: + # better no information than an inaccurate one. + if not account.ownership: + if account.parent and account.parent.ownership: + account.ownership = account.parent.ownership + elif re.search(r'(m|mr|me|mme|mlle|mle|ml)\.? (.*)\bou (m|mr|me|mme|mlle|mle|ml)\b(.*)', account._owner, re.IGNORECASE): + account.ownership = AccountOwnership.CO_OWNER + elif all(n in account._owner for n in owner_name.split()): + account.ownership = AccountOwnership.OWNER + elif 'Mandat' in account.label: + account.ownership = AccountOwnership.ATTORNEY + else: + account.ownership = NotAvailable + @need_login def go_account_pages(self, account, action): # Default to "comptes" diff --git a/modules/axabanque/pages/bank.py b/modules/axabanque/pages/bank.py index b2cdce7ad9..de94c2c0cf 100644 --- a/modules/axabanque/pages/bank.py +++ b/modules/axabanque/pages/bank.py @@ -29,7 +29,7 @@ from weboob.browser.elements import ItemElement, TableElement, method from weboob.browser.filters.standard import CleanText, CleanDecimal, Date, Regexp, Field, Env, Currency from weboob.browser.filters.html import Attr, Link, TableCell -from weboob.capabilities.bank import Account, Investment +from weboob.capabilities.bank import Account, Investment, AccountOwnership from weboob.tools.capabilities.bank.iban import is_iban_valid from weboob.capabilities.base import NotAvailable, empty from weboob.capabilities.profile import Person @@ -135,6 +135,7 @@ def get_list(self): self.browser.bank_accounts.open() account.balance = loan_details.get_loan_balance() account.currency = loan_details.get_loan_currency() + account.ownership = loan_details.get_loan_ownership() # Skip loans without any balance (already fully reimbursed) if empty(account.balance): continue @@ -237,6 +238,7 @@ def get_list(self): account._url = self.doc.xpath('//form[contains(@action, "panorama")]/@action')[0] account._acctype = "bank" + account._owner = CleanText('./td[has-class("libelle")]')(box) # get accounts currency currency_title = table.xpath('./thead//th[@class="montant"]')[0].text.strip() @@ -319,6 +321,12 @@ def get_loan_balance(self): def get_loan_currency(self): return Currency('//*[@id="table-detail"]/tbody/tr/td[@class="capital"]', default=NotAvailable)(self.doc) + def get_loan_ownership(self): + co_owner = CleanText('//td[@class="coEmprunteur"]')(self.doc) + if co_owner: + return AccountOwnership.CO_OWNER + return AccountOwnership.OWNER + def open_market(self): # only for netfinca PEA self.browser.bourse.go() diff --git a/modules/axabanque/pages/wealth.py b/modules/axabanque/pages/wealth.py index 7dece8b68c..fe767b0664 100644 --- a/modules/axabanque/pages/wealth.py +++ b/modules/axabanque/pages/wealth.py @@ -30,7 +30,7 @@ ) from weboob.browser.filters.json import Dict from weboob.browser.filters.html import Attr, Link, TableCell -from weboob.capabilities.bank import Account, Investment +from weboob.capabilities.bank import Account, Investment, AccountOwnership from weboob.capabilities.profile import Person from weboob.capabilities.base import NotAvailable, NotLoaded, empty from weboob.tools.capabilities.bank.transactions import FrenchTransaction @@ -68,6 +68,7 @@ class item(ItemElement): obj__acctype = "investment" obj_type = MapIn(Lower(Field('label')), TYPES, Account.TYPE_UNKNOWN) obj_url = Attr('.', 'data-module-open-link--link') + obj_ownership = AccountOwnership.OWNER class InvestmentPage(LoggedPage, HTMLPage): -- GitLab