[paypal] Get converted amount for foreign currencies
This commit is contained in:
parent
fc6aa997e7
commit
131b01c599
3 changed files with 55 additions and 21 deletions
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
|
|
||||||
from weboob.deprecated.browser import Browser, BrowserIncorrectPassword
|
from weboob.deprecated.browser import Browser, BrowserIncorrectPassword
|
||||||
from .pages import LoginPage, AccountPage, DownloadHistoryPage, LastDownloadHistoryPage, SubmitPage, HistoryParser, UselessPage, HistoryPage, CSVAlreadyAsked
|
from .pages import LoginPage, AccountPage, DownloadHistoryPage, LastDownloadHistoryPage, SubmitPage, HistoryParser, UselessPage, HistoryPage, CSVAlreadyAsked, HistoryDetailsPage
|
||||||
from .newpages import NewHomePage, NewAccountPage, NewProHistoryPage, NewPartHistoryPage
|
from .newpages import NewHomePage, NewAccountPage, NewProHistoryPage, NewPartHistoryPage
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
|
@ -45,6 +45,7 @@ class Paypal(Browser):
|
||||||
'/cgi-bin/webscr\?cmd=_history-download-recent$': LastDownloadHistoryPage,
|
'/cgi-bin/webscr\?cmd=_history-download-recent$': LastDownloadHistoryPage,
|
||||||
'/cgi-bin/webscr\?dispatch=[a-z0-9]+$': (SubmitPage, HistoryParser()),
|
'/cgi-bin/webscr\?dispatch=[a-z0-9]+$': (SubmitPage, HistoryParser()),
|
||||||
'/cgi-bin/webscr\?cmd=_history-download-recent-submit&dispatch=[a-z0-9]+$': (SubmitPage, HistoryParser()),
|
'/cgi-bin/webscr\?cmd=_history-download-recent-submit&dispatch=[a-z0-9]+$': (SubmitPage, HistoryParser()),
|
||||||
|
'https://history.paypal.com/cgi-bin/webscr\?cmd=_history-details-from-hub&id=[A-Z0-9]+$': HistoryDetailsPage,
|
||||||
'https://www.paypal.com/webapps/business/\?nav=0.0': NewHomePage,
|
'https://www.paypal.com/webapps/business/\?nav=0.0': NewHomePage,
|
||||||
'https://www.paypal.com/webapps/business/\?country_lang.x=true': NewHomePage,
|
'https://www.paypal.com/webapps/business/\?country_lang.x=true': NewHomePage,
|
||||||
'https://www.paypal.com/myaccount/\?nav=0.0': NewHomePage,
|
'https://www.paypal.com/myaccount/\?nav=0.0': NewHomePage,
|
||||||
|
|
@ -144,6 +145,7 @@ class Paypal(Browser):
|
||||||
else:
|
else:
|
||||||
step_min = 90
|
step_min = 90
|
||||||
step_max = 180
|
step_max = 180
|
||||||
|
|
||||||
def fetch_fn(start, end):
|
def fetch_fn(start, end):
|
||||||
if self.website == "old" and self.download_history(start, end).rows:
|
if self.website == "old" and self.download_history(start, end).rows:
|
||||||
return self.page.iter_transactions(account)
|
return self.page.iter_transactions(account)
|
||||||
|
|
@ -214,3 +216,13 @@ class Paypal(Browser):
|
||||||
|
|
||||||
def transfer(self, from_id, to_id, amount, reason=None):
|
def transfer(self, from_id, to_id, amount, reason=None):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def convert_amount(self, account, trans):
|
||||||
|
if(trans['actions']['details']['action'] == 'ACTIVITY_DETAILS'):
|
||||||
|
self.location(trans['actions']['details']['url'])
|
||||||
|
if self.is_on_page(HistoryDetailsPage):
|
||||||
|
cc = self.page.get_converted_amount(account)
|
||||||
|
if cc:
|
||||||
|
trans['originalAmount'] = trans['netAmount']
|
||||||
|
trans['netAmount'] = cc
|
||||||
|
return trans
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ from weboob.tools.date import parse_french_date
|
||||||
class NewHomePage(Page):
|
class NewHomePage(Page):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class NewAccountPage(Page):
|
class NewAccountPage(Page):
|
||||||
def get_account(self, _id):
|
def get_account(self, _id):
|
||||||
return self.get_accounts().get(_id)
|
return self.get_accounts().get(_id)
|
||||||
|
|
@ -52,6 +53,7 @@ class NewAccountPage(Page):
|
||||||
|
|
||||||
return accounts
|
return accounts
|
||||||
|
|
||||||
|
|
||||||
class NewProHistoryPage(Page):
|
class NewProHistoryPage(Page):
|
||||||
|
|
||||||
def iter_transactions(self, account):
|
def iter_transactions(self, account):
|
||||||
|
|
@ -77,22 +79,22 @@ class NewProHistoryPage(Page):
|
||||||
def transaction_left(self):
|
def transaction_left(self):
|
||||||
return (len(self.document.xpath('//div[@class="no-records"]')) == 0)
|
return (len(self.document.xpath('//div[@class="no-records"]')) == 0)
|
||||||
|
|
||||||
|
|
||||||
class NewPartHistoryPage(Page):
|
class NewPartHistoryPage(Page):
|
||||||
def transaction_left(self):
|
def transaction_left(self):
|
||||||
return (len(self.document['data']['activity']['COMPLETED']) > 0 or len(self.document['data']['activity']['PENDING']) > 0)
|
return (len(self.document['data']['activity']['COMPLETED']) > 0 or len(self.document['data']['activity']['PENDING']) > 0)
|
||||||
|
|
||||||
def iter_transactions(self, account):
|
def iter_transactions(self, account):
|
||||||
for trans in self.parse():
|
for trans in self.parse(account):
|
||||||
if trans._currency == account.currency:
|
|
||||||
yield trans
|
yield trans
|
||||||
|
|
||||||
def parse(self):
|
def parse(self, account):
|
||||||
transactions = list()
|
transactions = list()
|
||||||
|
|
||||||
for status in ['PENDING', 'COMPLETED']:
|
for status in ['PENDING', 'COMPLETED']:
|
||||||
transac = self.document['data']['activity'][status]
|
transac = self.document['data']['activity'][status]
|
||||||
for t in transac:
|
for t in transac:
|
||||||
tran = self.parse_transaction(t)
|
tran = self.parse_transaction(t, account)
|
||||||
if tran:
|
if tran:
|
||||||
transactions.append(tran)
|
transactions.append(tran)
|
||||||
|
|
||||||
|
|
@ -100,23 +102,32 @@ class NewPartHistoryPage(Page):
|
||||||
for t in transactions:
|
for t in transactions:
|
||||||
yield t
|
yield t
|
||||||
|
|
||||||
def parse_transaction(self, transaction):
|
def parse_transaction(self, transaction, account):
|
||||||
t = FrenchTransaction(transaction['activityId'])
|
t = FrenchTransaction(transaction['activityId'])
|
||||||
date = parse_french_date(transaction['date'])
|
date = parse_french_date(transaction['date'])
|
||||||
raw = transaction.get('counterparty', transaction['displayType'])
|
raw = transaction.get('counterparty', transaction['displayType'])
|
||||||
t.parse(date=date, raw=raw)
|
t.parse(date=date, raw=raw)
|
||||||
|
|
||||||
|
if transaction['currencyCode'] != account.currency:
|
||||||
|
transaction = self.browser.convert_amount(account, transaction)
|
||||||
try:
|
try:
|
||||||
m = re.search(r"\D", transaction['netAmount'][::-1])
|
t.original_amount = self.format_amount(transaction['originalAmount'], transaction["isCredit"])
|
||||||
amount = Decimal(re.sub(r'[^\d]', '', transaction['netAmount']))/Decimal((10 ** m.start()))
|
t.original_currency = transaction["currencyCode"]
|
||||||
|
except KeyError:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
t.amount = self.format_amount(transaction['netAmount'], transaction["isCredit"])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return
|
return
|
||||||
|
|
||||||
if transaction['isCredit']:
|
|
||||||
t.amount = abs(amount)
|
|
||||||
else:
|
|
||||||
t.amount = - abs(amount)
|
|
||||||
t._currency = transaction['currencyCode']
|
t._currency = transaction['currencyCode']
|
||||||
|
|
||||||
return t
|
return t
|
||||||
|
|
||||||
|
def format_amount(self, to_format, is_credit):
|
||||||
|
m = re.search(r"\D", to_format[::-1])
|
||||||
|
amount = Decimal(re.sub(r'[^\d]', '', to_format))/Decimal((10 ** m.start()))
|
||||||
|
if is_credit:
|
||||||
|
return abs(amount)
|
||||||
|
else:
|
||||||
|
return -abs(amount)
|
||||||
|
|
|
||||||
|
|
@ -366,3 +366,14 @@ class HistoryPage(Page):
|
||||||
for trans in self.parse():
|
for trans in self.parse():
|
||||||
if trans._currency == account.currency:
|
if trans._currency == account.currency:
|
||||||
yield trans
|
yield trans
|
||||||
|
|
||||||
|
|
||||||
|
class HistoryDetailsPage(Page):
|
||||||
|
|
||||||
|
def get_converted_amount(self, account):
|
||||||
|
convert_td = self.document.xpath('//td[contains(text(),"' + account.currency + ')")]')[0].text
|
||||||
|
m = re.match('.* ([^ ]+) ' + account.currency + '\).*', convert_td)
|
||||||
|
if m:
|
||||||
|
return m.group(1)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue