ability to see list of recipients

This commit is contained in:
Romain Bignon 2011-05-07 14:23:31 +02:00
commit 44f8123aae
3 changed files with 54 additions and 20 deletions

View file

@ -21,7 +21,7 @@
# python2.5 compatibility # python2.5 compatibility
from __future__ import with_statement from __future__ import with_statement
from weboob.capabilities.bank import ICapBank, AccountNotFound, Account from weboob.capabilities.bank import ICapBank, AccountNotFound, Account, Recipient
from weboob.tools.backend import BaseBackend from weboob.tools.backend import BaseBackend
from weboob.tools.value import ValuesDict, Value from weboob.tools.value import ValuesDict, Value
@ -86,6 +86,13 @@ class BNPorcBackend(BaseBackend, ICapBank):
for coming in self.browser.get_coming_operations(account): for coming in self.browser.get_coming_operations(account):
yield coming yield coming
def iter_transfer_recipients(self, ignored):
for account in self.browser.get_transfer_accounts().itervalues():
recipient = Recipient()
recipient.id = account.id
recipient.label = account.label
yield recipient
def transfer(self, account, to, amount, reason=None): def transfer(self, account, to, amount, reason=None):
if isinstance(account, Account): if isinstance(account, Account):
account = account.id account = account.id

View file

@ -133,10 +133,18 @@ class BNPorc(BaseBrowser):
self.location('/NS_AVEDT?ch4=%s' % account.link_id) self.location('/NS_AVEDT?ch4=%s' % account.link_id)
return self.page.get_operations() return self.page.get_operations()
def get_transfer_accounts(self):
if not self.is_on_page(pages.TransferPage):
self.location('/NS_VIRDF')
assert self.is_on_page(pages.TransferPage)
return self.page.get_accounts()
def transfer(self, from_id, to_id, amount, reason=None): def transfer(self, from_id, to_id, amount, reason=None):
if not self.is_on_page(pages.TransferPage): if not self.is_on_page(pages.TransferPage):
self.location('/NS_VIRDF') self.location('/NS_VIRDF')
accounts = self.page.get_accounts()
self.page.transfer(from_id, to_id, amount, reason) self.page.transfer(from_id, to_id, amount, reason)
if not self.is_on_page(pages.TransferCompletePage): if not self.is_on_page(pages.TransferCompletePage):
@ -144,7 +152,7 @@ class BNPorc(BaseBrowser):
transfer = Transfer(self.page.get_id()) transfer = Transfer(self.page.get_id())
transfer.amount = amount transfer.amount = amount
transfer.origin = from_id transfer.origin = accounts[from_id].label
transfer.recipient = to_id transfer.recipient = accounts[to_id].label
transfer.date = datetime.now() transfer.date = datetime.now()
return transfer return transfer

View file

@ -21,39 +21,58 @@
import re import re
from weboob.tools.browser import BasePage from weboob.tools.browser import BasePage
from weboob.tools.ordereddict import OrderedDict
from weboob.capabilities.bank import TransferError from weboob.capabilities.bank import TransferError
__all__ = ['TransferPage', 'TransferConfirmPage', 'TransferCompletePage'] __all__ = ['TransferPage', 'TransferConfirmPage', 'TransferCompletePage']
class Account(object):
def __init__(self, id, label, send_checkbox, receive_checkbox):
self.id = id
self.label = label
self.send_checkbox = send_checkbox
self.receive_checkbox = receive_checkbox
class TransferPage(BasePage): class TransferPage(BasePage):
def transfer(self, from_id, to_id, amount, reason): def get_accounts(self):
self.browser.select_form(nr=0) accounts = OrderedDict()
from_found = False
to_found = False
for table in self.document.getiterator('table'): for table in self.document.getiterator('table'):
if table.attrib.get('cellspacing') == '2': if table.attrib.get('cellspacing') == '2':
for tr in table.cssselect('tr.hdoc1, tr.hdotc1'): for tr in table.cssselect('tr.hdoc1, tr.hdotc1'):
tds = tr.findall('td') tds = tr.findall('td')
id = tds[1].text.replace(u'\xa0', u'') id = tds[1].text.replace(u'\xa0', u'')
if id == from_id: label = tds[0].text
if tds[4].find('input') is None: if label is None and tds[0].find('nobr') is not None:
raise TransferError("Unable to make a transfer from %s" % from_id) label = tds[0].find('nobr').text
self.browser['C1'] = [tds[4].find('input').attrib['value']] send_checkbox = tds[4].find('input').attrib['value'] if tds[4].find('input') is not None else None
from_found = True receive_checkbox = tds[5].find('input').attrib['value'] if tds[5].find('input') is not None else None
elif id == to_id: account = Account(id, label, send_checkbox, receive_checkbox)
if tds[5].find('input') is None: accounts[id] = account
raise TransferError("Unable to make a transfer to %s" % from_id) return accounts
self.browser['C2'] = [tds[5].find('input').attrib['value']]
to_found = True
if not from_found: def transfer(self, from_id, to_id, amount, reason):
accounts = self.get_accounts()
try:
sender = accounts[from_id]
except KeyError:
raise TransferError('Account %s not found' % from_id) raise TransferError('Account %s not found' % from_id)
if not to_found: try:
recipient = accounts[to_id]
except KeyError:
raise TransferError('Recipient %s not found' % to_id) raise TransferError('Recipient %s not found' % to_id)
if sender.send_checkbox is None:
raise TransferError('Unable to make a transfer from %s' % sender.label)
if recipient.receive_checkbox is None:
raise TransferError('Unable to make a transfer to %s' % recipient.label)
self.browser.select_form(nr=0)
self.browser['C1'] = [sender.send_checkbox]
self.browser['C2'] = [recipient.receive_checkbox]
self.browser['T6'] = str(amount).replace('.', ',') self.browser['T6'] = str(amount).replace('.', ',')
if reason: if reason:
self.browser['T5'] = reason self.browser['T5'] = reason