paypal: Start support for multiple currencies
For now, ignore everything that is not the primary, and do not use the converted total. This is based on http://i.imgur.com/TNcLbPB.jpg as I have 0 in all currencies for now.
This commit is contained in:
parent
0e505c0b1d
commit
6e7599d4e3
3 changed files with 30 additions and 8 deletions
|
|
@ -47,7 +47,8 @@ class PaypalBackend(BaseBackend, ICapBank):
|
||||||
self.config['password'].get())
|
self.config['password'].get())
|
||||||
|
|
||||||
def iter_accounts(self):
|
def iter_accounts(self):
|
||||||
yield self.get_account(u"1")
|
for account in self.browser.get_accounts():
|
||||||
|
yield account
|
||||||
|
|
||||||
def get_account(self, _id):
|
def get_account(self, _id):
|
||||||
with self.browser:
|
with self.browser:
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,9 @@ class Paypal(BaseBrowser):
|
||||||
if self.is_on_page(LoginPage):
|
if self.is_on_page(LoginPage):
|
||||||
raise BrowserIncorrectPassword()
|
raise BrowserIncorrectPassword()
|
||||||
|
|
||||||
|
def get_accounts(self):
|
||||||
|
yield self.get_account(u"1")
|
||||||
|
|
||||||
def get_account(self, _id):
|
def get_account(self, _id):
|
||||||
if _id != u"1":
|
if _id != u"1":
|
||||||
return None
|
return None
|
||||||
|
|
@ -62,7 +65,7 @@ class Paypal(BaseBrowser):
|
||||||
if not self.is_on_page(AccountPage):
|
if not self.is_on_page(AccountPage):
|
||||||
self.location('/en/cgi-bin/webscr?cmd=_account&nav=0.0')
|
self.location('/en/cgi-bin/webscr?cmd=_account&nav=0.0')
|
||||||
|
|
||||||
return self.page.get_account()
|
return self.page.get_account(_id)
|
||||||
|
|
||||||
def get_history(self, account):
|
def get_history(self, account):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ from weboob.tools.capabilities.bank.transactions import FrenchTransaction
|
||||||
__all__ = ['LoginPage', 'AccountPage']
|
__all__ = ['LoginPage', 'AccountPage']
|
||||||
|
|
||||||
|
|
||||||
|
def clean_amount(text):
|
||||||
|
return Decimal(FrenchTransaction.clean_amount(text))
|
||||||
|
|
||||||
|
|
||||||
class LoginPage(BasePage):
|
class LoginPage(BasePage):
|
||||||
def login(self, login, password):
|
def login(self, login, password):
|
||||||
self.browser.select_form(name='login_form')
|
self.browser.select_form(name='login_form')
|
||||||
|
|
@ -35,16 +39,30 @@ class LoginPage(BasePage):
|
||||||
|
|
||||||
|
|
||||||
class AccountPage(BasePage):
|
class AccountPage(BasePage):
|
||||||
def get_account(self):
|
def get_account(self, _id):
|
||||||
|
assert _id == u"1" # Only one "account" supported for now
|
||||||
|
|
||||||
account = Account()
|
account = Account()
|
||||||
account.id = u"1"
|
account.id = _id
|
||||||
account.label = unicode(self.browser.username)
|
account.label = unicode(self.browser.username)
|
||||||
account.type = Account.TYPE_CHECKING
|
account.type = Account.TYPE_CHECKING
|
||||||
|
|
||||||
balance = self.document.xpath('//div[@id="main"]')[0] \
|
content = self.document.xpath('//div[@id="main"]//div[@class="col first"]')[0]
|
||||||
.xpath('.//div[@class="col first"]//h3/span[@class="balance"]')[0] \
|
# Total currency balance.
|
||||||
.balance.text_content().strip()
|
# If there are multiple currencies, this balance is all currencies
|
||||||
account.balance = Decimal(FrenchTransaction.clean_amount(balance))
|
# converted to the main currency.
|
||||||
|
balance = content.xpath('//h3/span[@class="balance"]')[0].text_content().strip()
|
||||||
|
account.balance = clean_amount(balance)
|
||||||
account.currency = account.get_currency(balance)
|
account.currency = account.get_currency(balance)
|
||||||
|
|
||||||
|
# Primary currency balance.
|
||||||
|
# If the user enabled multiple currencies, we get this one instead.
|
||||||
|
# An Account object has only one currency; secondary currencies should be other accounts.
|
||||||
|
balance = content.xpath('//div[@class="body"]//ul/li[@class="balance"]/span')
|
||||||
|
if balance:
|
||||||
|
balance = balance[0].text_content().strip()
|
||||||
|
account.balance = clean_amount(balance)
|
||||||
|
# The primary currency of the "head balance" is the same; ensure we got the right one
|
||||||
|
assert account.currency == account.get_currency(balance)
|
||||||
|
|
||||||
return account
|
return account
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue