From 42a1fee1410729d0e221ba0e79db737ccb6d7f05 Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Sat, 10 Mar 2012 20:03:27 +0100 Subject: [PATCH] Fix account types and add account types support to bnporc, for the account types I could get. Types were taken from KMyMoney, which is for personal tracking, however some types had no use (cash not something the bank can provide, maybe credit card but it is usually the "coming" field for us). Sources: https://en.wikipedia.org/wiki/Bank_account (but not focused on personal banking) and it's French translation which was more interesting. Other websites for American and Australian banking almost always mentioned three accounts: checking/current, savings/deposits, term/fixed deposits. And some code refactoring. --- modules/bnporc/pages/accounts_list.py | 56 +++++++++++++++++++-------- weboob/capabilities/bank.py | 14 +++---- 2 files changed, 46 insertions(+), 24 deletions(-) diff --git a/modules/bnporc/pages/accounts_list.py b/modules/bnporc/pages/accounts_list.py index c84c9fa6..a73fe0cc 100644 --- a/modules/bnporc/pages/accounts_list.py +++ b/modules/bnporc/pages/accounts_list.py @@ -29,27 +29,51 @@ __all__ = ['AccountsList'] class AccountsList(BasePage): + ACCOUNT_TYPES = { + u'Liquidités': Account.TYPE_CHECKING, + u'Epargne disponible': Account.TYPE_SAVINGS, + u'Titres': Account.TYPE_MARKET, + u'Assurance vie': Account.TYPE_DEPOSIT, + u'Crédit immobilier': Account.TYPE_LOAN, + } + def on_loaded(self): pass + def _parse_account_group(self, table): + typename = unicode(table.attrib.get('summary', '').replace('Liste des contrats/comptes ', '')) + typeid = self.ACCOUNT_TYPES.get(typename, Account.TYPE_UNKNOWN) + for tr in table.xpath('.//tr[not(@class)]'): + if tr.find('td') is not None and tr.find('td').attrib.get('class', '') == 'typeTitulaire': + account = self._parse_account(tr) + account.type = typeid + yield account + + def _parse_account(self, tr): + account = Account() + account.id = tr.xpath('.//td[@class="libelleCompte"]/input')[0].attrib['id'][len('libelleCompte'):] + account._link_id = account.id + if len(str(account.id)) == 23: + account.id = str(account.id)[5:21] + + account.label = tr.xpath('.//td[@class="libelleCompte"]/a')[0].text.strip() + + tds = tr.findall('td') + account.balance = self._parse_amount(tds[3].find('a')) + if tds[4].find('a') is not None: + account.coming = self._parse_amount(tds[4].find('a')) + else: + account.coming = NotAvailable + + return account + + def _parse_amount(self, elem): + return float(elem.text.replace('.', '').replace(',', '.').strip(u' \t\u20ac\xa0€\n\r')) + def get_list(self): l = [] - for tr in self.document.xpath('//table[@class="tableCompte"]//tr[not(@class)]'): - if tr.find('td') is not None and tr.find('td').attrib.get('class', '') == 'typeTitulaire': - account = Account() - account.id = tr.xpath('.//td[@class="libelleCompte"]/input')[0].attrib['id'][len('libelleCompte'):] - account._link_id = account.id - if len(str(account.id)) == 23: - account.id = str(account.id)[5:21] - - account.label = tr.xpath('.//td[@class="libelleCompte"]/a')[0].text.strip() - - tds = tr.findall('td') - account.balance = float(tds[3].find('a').text.replace('.','').replace(',','.').strip(u' \t\u20ac\xa0€\n\r')) - if tds[4].find('a') is not None: - account.coming = float(tds[4].find('a').text.replace('.','').replace(',','.').strip(u' \t\u20ac\xa0€\n\r')) - else: - account.coming = NotAvailable + for table in self.document.xpath('//table[@class="tableCompte"]'): + for account in self._parse_account_group(table): l.append(account) if len(l) == 0: diff --git a/weboob/capabilities/bank.py b/weboob/capabilities/bank.py index 69742691..769d0d2a 100644 --- a/weboob/capabilities/bank.py +++ b/weboob/capabilities/bank.py @@ -43,14 +43,12 @@ class Recipient(CapBaseObject): class Account(Recipient): TYPE_UNKNOWN = 0 - TYPE_CHECKING = 1 - TYPE_LIABILITY = 2 - TYPE_ASSET = 3 - TYPE_INVESTMENT = 4 - TYPE_LOAN = 5 - TYPE_CASH = 6 - TYPE_CREDIT_CARD = 7 - TYPE_SAVINGS = 8 + TYPE_CHECKING = 1 # Transaction, everyday transactions + TYPE_SAVINGS = 2 # Savings/Deposit, can be used for everyday banking + TYPE_DEPOSIT = 3 # Term or Fixed Deposit, has time/amount constraints + TYPE_LOAN = 4 + TYPE_MARKET = 5 # Stock market or other variable investments + TYPE_JOINT = 6 # Joint account def __init__(self): Recipient.__init__(self)