From 81706f23adeaa2abfda30ef66f6a6f609f1417e4 Mon Sep 17 00:00:00 2001 From: Nicolas Duhamel Date: Fri, 24 Sep 2010 18:07:06 +0200 Subject: [PATCH] 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 Signed-off-by: Romain Bignon --- weboob/applications/boobank/boobank.py | 22 ++++++++++++++++++++++ weboob/backends/bp/backend.py | 14 +++++++++++++- weboob/backends/bp/browser.py | 18 ++++++++++++++++++ weboob/capabilities/bank.py | 6 ++++++ 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/weboob/applications/boobank/boobank.py b/weboob/applications/boobank/boobank.py index 1ffb1bfd..09f65ea8 100644 --- a/weboob/applications/boobank/boobank.py +++ b/weboob/applications/boobank/boobank.py @@ -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 + + + + + diff --git a/weboob/backends/bp/backend.py b/weboob/backends/bp/backend.py index 6aa9cabc..f7f2c0bd 100644 --- a/weboob/backends/bp/backend.py +++ b/weboob/backends/bp/backend.py @@ -2,7 +2,7 @@ # # backend.py # -# Copyright 2010 nicolas +# Copyright 2010 nicolas # # 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) + + + + + + diff --git a/weboob/backends/bp/browser.py b/weboob/backends/bp/browser.py index 5b53ab35..9332038e 100644 --- a/weboob/backends/bp/browser.py +++ b/weboob/backends/bp/browser.py @@ -183,8 +183,26 @@ 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") + + + + diff --git a/weboob/capabilities/bank.py b/weboob/capabilities/bank.py index e08b2f44..91453bbb 100644 --- a/weboob/capabilities/bank.py +++ b/weboob/capabilities/bank.py @@ -29,6 +29,9 @@ __all__ = ['Account', 'AccountNotFound', 'ICapBank', 'Operation'] class AccountNotFound(Exception): pass + +class NotEnoughMoney(Exception): + pass class Account(CapBaseObject): @@ -100,3 +103,6 @@ class ICapBank(IBaseCap): def iter_history(self, id): raise NotImplementedError() + + def transfer(self, id_from, id_to, amount): + raise NotImplementedError()