Add a transfer capability and implante it in bp and boobank

Make a transfer in boobank like that:

>transfer fromaccountid toaccoundid amount

Signed-off-by: Nicolas Duhamel <nicolas@jombi.fr>
Signed-off-by: Romain Bignon <romain@peerfuse.org>
This commit is contained in:
Nicolas Duhamel 2010-09-24 18:07:06 +02:00 committed by Romain Bignon
commit 81706f23ad
4 changed files with 59 additions and 1 deletions

View file

@ -88,3 +88,25 @@ class Boobank(ReplApplication):
for backend, operation in self.do(do):
self.format(operation)
def do_transfer(self, arg):
"""
Make a transfer beetwen two account
"""
id_from , id_to, amount = arg.split()
id_from, backend_name = self.parse_id(id_from)
id_to, backend_name = self.parse_id(id_to)
names = (backend_name,) if backend_name is not None else None
self.load_backends(ICapBank, names=names)
def do(backend):
return backend.transfer(id_from, id_to, amount)
for backend, operation in self.do(do):
pass

View file

@ -2,7 +2,7 @@
#
# backend.py
#
# Copyright 2010 nicolas <nicolas@NicolasDesktop>
# Copyright 2010 nicolas <nicolas@jombi.fr>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -52,3 +52,15 @@ class BPBackend(BaseBackend, ICapBank):
for history in self.browser.get_history(account):
yield history
def transfer(self, id_from, id_to, amount):
from_account = self.get_account(id_from)
to_account = self.get_account(id_to)
#TODO: retourner le numero du virement
self.browser.make_transfer(from_account, to_account, amount)

View file

@ -183,6 +183,24 @@ class BPbrowser(object):
def make_transfer(self, from_account, to_account, amount):
self.Browser.open("https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/f_virementSafran.jsp?n=11")
self.Browser.open("https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/virementsafran/aiguillage/saisieComptes.ea")
self.Browser.select_form(name="AiguillageForm")
self.Browser["idxCompteEmetteur"] = [from_account.id]
self.Browser["idxCompteReceveur"] = [to_account.id]
self.Browser.submit()
self.Browser.select_form(name="VirementNationalForm")
self.Browser["montant"] = str(amount)
self.Browser.submit()
#Confirmation
# TODO: verifier que tout c'est bien passe
self.Browser.open("https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/virementsafran/virementnational/4-virementNational.ea")

View file

@ -30,6 +30,9 @@ __all__ = ['Account', 'AccountNotFound', 'ICapBank', 'Operation']
class AccountNotFound(Exception):
pass
class NotEnoughMoney(Exception):
pass
class Account(CapBaseObject):
FIELDS = ('label', 'balance', 'coming')
@ -100,3 +103,6 @@ class ICapBank(IBaseCap):
def iter_history(self, id):
raise NotImplementedError()
def transfer(self, id_from, id_to, amount):
raise NotImplementedError()