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.
This commit is contained in:
Laurent Bachelier 2012-03-10 20:03:27 +01:00 committed by Romain Bignon
commit 42a1fee141
2 changed files with 46 additions and 24 deletions

View file

@ -29,13 +29,27 @@ __all__ = ['AccountsList']
class AccountsList(BasePage): 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): def on_loaded(self):
pass pass
def get_list(self): def _parse_account_group(self, table):
l = [] typename = unicode(table.attrib.get('summary', '').replace('Liste des contrats/comptes ', ''))
for tr in self.document.xpath('//table[@class="tableCompte"]//tr[not(@class)]'): 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': 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 = Account()
account.id = tr.xpath('.//td[@class="libelleCompte"]/input')[0].attrib['id'][len('libelleCompte'):] account.id = tr.xpath('.//td[@class="libelleCompte"]/input')[0].attrib['id'][len('libelleCompte'):]
account._link_id = account.id account._link_id = account.id
@ -45,11 +59,21 @@ class AccountsList(BasePage):
account.label = tr.xpath('.//td[@class="libelleCompte"]/a')[0].text.strip() account.label = tr.xpath('.//td[@class="libelleCompte"]/a')[0].text.strip()
tds = tr.findall('td') tds = tr.findall('td')
account.balance = float(tds[3].find('a').text.replace('.','').replace(',','.').strip(u' \t\u20ac\xa0\n\r')) account.balance = self._parse_amount(tds[3].find('a'))
if tds[4].find('a') is not None: 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')) account.coming = self._parse_amount(tds[4].find('a'))
else: else:
account.coming = NotAvailable 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 table in self.document.xpath('//table[@class="tableCompte"]'):
for account in self._parse_account_group(table):
l.append(account) l.append(account)
if len(l) == 0: if len(l) == 0:

View file

@ -43,14 +43,12 @@ class Recipient(CapBaseObject):
class Account(Recipient): class Account(Recipient):
TYPE_UNKNOWN = 0 TYPE_UNKNOWN = 0
TYPE_CHECKING = 1 TYPE_CHECKING = 1 # Transaction, everyday transactions
TYPE_LIABILITY = 2 TYPE_SAVINGS = 2 # Savings/Deposit, can be used for everyday banking
TYPE_ASSET = 3 TYPE_DEPOSIT = 3 # Term or Fixed Deposit, has time/amount constraints
TYPE_INVESTMENT = 4 TYPE_LOAN = 4
TYPE_LOAN = 5 TYPE_MARKET = 5 # Stock market or other variable investments
TYPE_CASH = 6 TYPE_JOINT = 6 # Joint account
TYPE_CREDIT_CARD = 7
TYPE_SAVINGS = 8
def __init__(self): def __init__(self):
Recipient.__init__(self) Recipient.__init__(self)