return a Transfer object insetad of only an ID
This commit is contained in:
parent
08605f7901
commit
3860f87f76
3 changed files with 41 additions and 14 deletions
|
|
@ -52,9 +52,10 @@ class BPBackend(BaseBackend, ICapBank):
|
||||||
for history in self.browser.get_history(account):
|
for history in self.browser.get_history(account):
|
||||||
yield history
|
yield history
|
||||||
|
|
||||||
def transfer(self, id_from, id_to, amount):
|
def transfer(self, id_from, id_to, amount, reason=None):
|
||||||
from_account = self.get_account(id_from)
|
from_account = self.get_account(id_from)
|
||||||
to_account = self.get_account(id_to)
|
to_account = self.get_account(id_to)
|
||||||
|
|
||||||
#TODO: retourner le numero du virement
|
#TODO: retourner le numero du virement
|
||||||
|
#TODO: support the 'reason' parameter
|
||||||
return self.browser.make_transfer(from_account, to_account, amount)
|
return self.browser.make_transfer(from_account, to_account, amount)
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
# MA 02110-1301, USA.
|
# MA 02110-1301, USA.
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
import mechanize
|
import mechanize
|
||||||
import hashlib
|
import hashlib
|
||||||
import re
|
import re
|
||||||
|
|
@ -25,6 +26,7 @@ import re
|
||||||
from weboob.tools.parsers import get_parser
|
from weboob.tools.parsers import get_parser
|
||||||
from weboob.capabilities.bank import Account
|
from weboob.capabilities.bank import Account
|
||||||
from weboob.capabilities.bank import Operation
|
from weboob.capabilities.bank import Operation
|
||||||
|
from weboob.capabilities.bank import Transfer
|
||||||
|
|
||||||
def remove_html_tags(data):
|
def remove_html_tags(data):
|
||||||
p = re.compile(r'<.*?>')
|
p = re.compile(r'<.*?>')
|
||||||
|
|
@ -207,4 +209,9 @@ class BPbrowser(object):
|
||||||
regex = re.compile(pattern)
|
regex = re.compile(pattern)
|
||||||
match = regex.search(html)
|
match = regex.search(html)
|
||||||
id_transfer = match.groups()[0]
|
id_transfer = match.groups()[0]
|
||||||
return id_transfer
|
transfer = Transfer(id_transfer)
|
||||||
|
transfer.amount = amount
|
||||||
|
transfer.origin = from_account.label
|
||||||
|
transfer.recipient = to_account.label
|
||||||
|
transfer.date = datetime.now()
|
||||||
|
return transfer
|
||||||
|
|
|
||||||
|
|
@ -21,16 +21,18 @@ from datetime import datetime
|
||||||
from .base import IBaseCap, CapBaseObject
|
from .base import IBaseCap, CapBaseObject
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['Account', 'AccountNotFound', 'NotEnoughMoney', 'ICapBank', 'Operation']
|
__all__ = ['Account', 'AccountNotFound', 'TransferError', 'ICapBank', 'Operation']
|
||||||
|
|
||||||
|
|
||||||
class AccountNotFound(Exception):
|
class AccountNotFound(Exception):
|
||||||
pass
|
def __init__(self, msg=None):
|
||||||
|
if msg is None:
|
||||||
|
msg = 'Account not found'
|
||||||
|
Exception.__init__(self, msg)
|
||||||
|
|
||||||
class NotEnoughMoney(Exception):
|
class TransferError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Account(CapBaseObject):
|
class Account(CapBaseObject):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
CapBaseObject.__init__(self, 0)
|
CapBaseObject.__init__(self, 0)
|
||||||
|
|
@ -53,6 +55,14 @@ class Operation(CapBaseObject):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<Operation date='%s' label='%s' amount=%s>" % (self.date, self.label, self.amount)
|
return "<Operation date='%s' label='%s' amount=%s>" % (self.date, self.label, self.amount)
|
||||||
|
|
||||||
|
class Transfer(CapBaseObject):
|
||||||
|
def __init__(self, id):
|
||||||
|
CapBaseObject.__init__(self, id)
|
||||||
|
self.add_field('amount', float)
|
||||||
|
self.add_field('date', (basestring,datetime))
|
||||||
|
self.add_field('origin', (int,long,basestring))
|
||||||
|
self.add_field('recipient', (int,long,basestring))
|
||||||
|
|
||||||
class ICapBank(IBaseCap):
|
class ICapBank(IBaseCap):
|
||||||
def iter_accounts(self):
|
def iter_accounts(self):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
@ -63,8 +73,17 @@ class ICapBank(IBaseCap):
|
||||||
def iter_operations(self, account):
|
def iter_operations(self, account):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def iter_history(self, id):
|
def iter_history(self, account):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def transfer(self, id_from, id_to, amount):
|
def transfer(self, account, to, amount, reason=None):
|
||||||
|
"""
|
||||||
|
Make a transfer from an account to a recipient.
|
||||||
|
|
||||||
|
@param account [Account] account to take money
|
||||||
|
@param to [Account] account to send money
|
||||||
|
@param amount [float] amount
|
||||||
|
@param reason [str] reason of transfer
|
||||||
|
@return [Transfer] a Transfer object
|
||||||
|
"""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue