handling when user can't acces account balance on main account

This commit is contained in:
Vincent Paredes 2014-10-29 15:37:11 +01:00 committed by Romain Bignon
commit 594e41e6c0

View file

@ -30,6 +30,7 @@ from weboob.tools.date import parse_french_date
from weboob.capabilities.bank import Account, Transaction
from weboob.tools.capabilities.bank.transactions import \
AmericanTransaction as AmTr
from weboob.capabilities.base import NotAvailable
class CSVAlreadyAsked(Exception):
@ -52,23 +53,27 @@ class AccountPage(Page):
accounts = {}
content = self.document.xpath('//div[@id="main"]//div[@class="col first"]')[0]
# Total currency balance.
# If there are multiple currencies, this balance is all currencies
# converted to the main currency.
balance = content.xpath('.//h3/span[@class="balance"]')
if not balance:
balance = content.xpath('.//li[@class="balance"]//span/strong')
balance = balance[0].text_content().strip()
# Primary currency account
primary_account = Account()
primary_account.type = Account.TYPE_CHECKING
primary_account.balance = AmTr.decimal_amount(balance)
primary_account.currency = Account.get_currency(balance)
primary_account.id = unicode(primary_account.currency)
primary_account.label = u'%s %s*' % (self.browser.username, balance.split()[-1])
accounts[primary_account.id] = primary_account
# Total currency balance.
# If there are multiple currencies, this balance is all currencies
# converted to the main currency.
try:
balance = content.xpath('.//h3/span[@class="balance"]')
if not balance:
balance = content.xpath('.//li[@class="balance"]//span/strong')
balance = balance[0].text_content().strip()
primary_account.balance = AmTr.decimal_amount(balance)
primary_account.currency = Account.get_currency(balance)
primary_account.label = u'%s %s*' % (self.browser.username, balance.split()[-1])
except IndexError:
primary_account.balance = NotAvailable
primary_account.label = u'%s' % (self.browser.username)
# The following code will only work if the user enabled multiple currencies.
balance = content.xpath('.//div[@class="body"]//ul/li[@class="balance"]/span')
table = content.xpath('.//table[@id="balanceDetails"]//tbody//tr')
@ -149,8 +154,10 @@ class SubmitPage(Page):
def iter_transactions(self, account):
csv = self.document
if len(csv.header) == 43:
if len(csv.header) == 42 or len(csv.header) == 43:
# Merchant multi-currency account
# 42 is for when the user can't access the balance on the website
# 43 is for full acces to the account
DATE = 0
TIME = 1
NAME = 3
@ -183,8 +190,9 @@ class SubmitPage(Page):
raise ValueError('CSV fields count of %i is not supported' % len(csv.header))
for row in csv.rows:
# we filter accounts by currency and ignore canceled transactions
if account.get_currency(row[CURRENCY]) != account.currency or row[NET] == '...':
# we filter transaction currceny to match account currency, except if we don't now the account currency
# we ignore canceled transactions
if (account.balance != NotAvailable and account.get_currency(row[CURRENCY]) != account.currency) or row[NET] == '...':
continue
# analog to dict.get()