Commit 44f8123a authored by Romain Bignon's avatar Romain Bignon

ability to see list of recipients

parent 7b29d2dc
......@@ -21,7 +21,7 @@
# python2.5 compatibility
from __future__ import with_statement
from import ICapBank, AccountNotFound, Account
from import ICapBank, AccountNotFound, Account, Recipient
from import BaseBackend
from import ValuesDict, Value
......@@ -86,6 +86,13 @@ class BNPorcBackend(BaseBackend, ICapBank):
for coming in self.browser.get_coming_operations(account):
yield coming
def iter_transfer_recipients(self, ignored):
for account in self.browser.get_transfer_accounts().itervalues():
recipient = Recipient() =
recipient.label = account.label
yield recipient
def transfer(self, account, to, amount, reason=None):
if isinstance(account, Account):
account =
......@@ -133,10 +133,18 @@ class BNPorc(BaseBrowser):
self.location('/NS_AVEDT?ch4=%s' % account.link_id)
def get_transfer_accounts(self):
if not self.is_on_page(pages.TransferPage):
assert self.is_on_page(pages.TransferPage)
def transfer(self, from_id, to_id, amount, reason=None):
if not self.is_on_page(pages.TransferPage):
accounts =, to_id, amount, reason)
if not self.is_on_page(pages.TransferCompletePage):
......@@ -144,7 +152,7 @@ class BNPorc(BaseBrowser):
transfer = Transfer(
transfer.amount = amount
transfer.origin = from_id
transfer.recipient = to_id
transfer.origin = accounts[from_id].label
transfer.recipient = accounts[to_id].label =
return transfer
......@@ -21,39 +21,58 @@
import re
from import BasePage
from import OrderedDict
from import TransferError
__all__ = ['TransferPage', 'TransferConfirmPage', 'TransferCompletePage']
class Account(object):
def __init__(self, id, label, send_checkbox, receive_checkbox): = id
self.label = label
self.send_checkbox = send_checkbox
self.receive_checkbox = receive_checkbox
class TransferPage(BasePage):
def transfer(self, from_id, to_id, amount, reason):
from_found = False
to_found = False
def get_accounts(self):
accounts = OrderedDict()
for table in self.document.getiterator('table'):
if table.attrib.get('cellspacing') == '2':
for tr in table.cssselect('tr.hdoc1, tr.hdotc1'):
tds = tr.findall('td')
id = tds[1].text.replace(u'\xa0', u'')
if id == from_id:
if tds[4].find('input') is None:
raise TransferError("Unable to make a transfer from %s" % from_id)
self.browser['C1'] = [tds[4].find('input').attrib['value']]
from_found = True
elif id == to_id:
if tds[5].find('input') is None:
raise TransferError("Unable to make a transfer to %s" % from_id)
self.browser['C2'] = [tds[5].find('input').attrib['value']]
to_found = True
if not from_found:
label = tds[0].text
if label is None and tds[0].find('nobr') is not None:
label = tds[0].find('nobr').text
send_checkbox = tds[4].find('input').attrib['value'] if tds[4].find('input') is not None else None
receive_checkbox = tds[5].find('input').attrib['value'] if tds[5].find('input') is not None else None
account = Account(id, label, send_checkbox, receive_checkbox)
accounts[id] = account
return accounts
def transfer(self, from_id, to_id, amount, reason):
accounts = self.get_accounts()
sender = accounts[from_id]
except KeyError:
raise TransferError('Account %s not found' % from_id)
if not to_found:
recipient = accounts[to_id]
except KeyError:
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['C1'] = [sender.send_checkbox]
self.browser['C2'] = [recipient.receive_checkbox]
self.browser['T6'] = str(amount).replace('.', ',')
if reason:
self.browser['T5'] = reason
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment