handling when user can't acces account balance on main account
This commit is contained in:
parent
e66a46766b
commit
594e41e6c0
1 changed files with 22 additions and 14 deletions
|
|
@ -30,6 +30,7 @@ from weboob.tools.date import parse_french_date
|
||||||
from weboob.capabilities.bank import Account, Transaction
|
from weboob.capabilities.bank import Account, Transaction
|
||||||
from weboob.tools.capabilities.bank.transactions import \
|
from weboob.tools.capabilities.bank.transactions import \
|
||||||
AmericanTransaction as AmTr
|
AmericanTransaction as AmTr
|
||||||
|
from weboob.capabilities.base import NotAvailable
|
||||||
|
|
||||||
|
|
||||||
class CSVAlreadyAsked(Exception):
|
class CSVAlreadyAsked(Exception):
|
||||||
|
|
@ -52,23 +53,27 @@ class AccountPage(Page):
|
||||||
accounts = {}
|
accounts = {}
|
||||||
content = self.document.xpath('//div[@id="main"]//div[@class="col first"]')[0]
|
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 currency account
|
||||||
primary_account = Account()
|
primary_account = Account()
|
||||||
primary_account.type = Account.TYPE_CHECKING
|
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.id = unicode(primary_account.currency)
|
||||||
primary_account.label = u'%s %s*' % (self.browser.username, balance.split()[-1])
|
|
||||||
accounts[primary_account.id] = primary_account
|
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.
|
# The following code will only work if the user enabled multiple currencies.
|
||||||
balance = content.xpath('.//div[@class="body"]//ul/li[@class="balance"]/span')
|
balance = content.xpath('.//div[@class="body"]//ul/li[@class="balance"]/span')
|
||||||
table = content.xpath('.//table[@id="balanceDetails"]//tbody//tr')
|
table = content.xpath('.//table[@id="balanceDetails"]//tbody//tr')
|
||||||
|
|
@ -149,8 +154,10 @@ class SubmitPage(Page):
|
||||||
def iter_transactions(self, account):
|
def iter_transactions(self, account):
|
||||||
csv = self.document
|
csv = self.document
|
||||||
|
|
||||||
if len(csv.header) == 43:
|
if len(csv.header) == 42 or len(csv.header) == 43:
|
||||||
# Merchant multi-currency account
|
# 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
|
DATE = 0
|
||||||
TIME = 1
|
TIME = 1
|
||||||
NAME = 3
|
NAME = 3
|
||||||
|
|
@ -183,8 +190,9 @@ class SubmitPage(Page):
|
||||||
raise ValueError('CSV fields count of %i is not supported' % len(csv.header))
|
raise ValueError('CSV fields count of %i is not supported' % len(csv.header))
|
||||||
|
|
||||||
for row in csv.rows:
|
for row in csv.rows:
|
||||||
# we filter accounts by currency and ignore canceled transactions
|
# we filter transaction currceny to match account currency, except if we don't now the account currency
|
||||||
if account.get_currency(row[CURRENCY]) != account.currency or row[NET] == '...':
|
# we ignore canceled transactions
|
||||||
|
if (account.balance != NotAvailable and account.get_currency(row[CURRENCY]) != account.currency) or row[NET] == '...':
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# analog to dict.get()
|
# analog to dict.get()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue