Commit 9305df41 authored by Julien Veyssier's avatar Julien Veyssier

[creditmut] internal transfer implemented

parent 2b7f6c5b
......@@ -18,7 +18,7 @@
# along with weboob. If not, see <>.
from import ICapBank, AccountNotFound
from import ICapBank, AccountNotFound, Recipient, Account
from import BaseBackend, BackendConfig
from import ValueBackendPassword
......@@ -62,3 +62,25 @@ class CreditMutuelBackend(BaseBackend, ICapBank):
def iter_history(self, account):
for history in self.browser.get_history(account):
yield history
def iter_transfer_recipients(self, ignored):
for account in self.browser.get_accounts_list().itervalues():
recipient = Recipient() =
recipient.label = account.label
yield recipient
def transfer(self, account, to, amount, reason=None):
if isinstance(account, Account):
account =
assert account.isdigit()
assert to.isdigit()
amount = float(amount)
except (AssertionError, ValueError):
raise AccountNotFound()
with self.browser:
return self.browser.transfer(account, to, amount, reason)
......@@ -19,8 +19,10 @@
from import BaseBrowser, BrowserIncorrectPassword
from import Transfer, TransferError
from datetime import datetime
from .pages import LoginPage, LoginErrorPage, AccountsPage, UserSpacePage, OperationsPage, InfoPage
from .pages import LoginPage, LoginErrorPage, AccountsPage, UserSpacePage, OperationsPage, InfoPage, TransfertPage
__all__ = ['CreditMutuelBrowser']
......@@ -35,7 +37,8 @@ class CreditMutuelBrowser(BaseBrowser):
'*/fr/banque/situation_financiere.cgi': AccountsPage,
'*/fr/banque/espace_personnel.aspx': UserSpacePage,
'*/fr/banque/mouvements.cgi.*' : OperationsPage,
'*/fr/banque/BAD.*' : InfoPage
'*/fr/banque/BAD.*' : InfoPage,
'*/fr/banque/.*Vir.*' : TransfertPage
def __init__(self, *args, **kwargs):
......@@ -49,7 +52,6 @@ class CreditMutuelBrowser(BaseBrowser):
def home(self):
return self.location('')
def login(self):
assert isinstance(self.username, basestring)
assert isinstance(self.password, basestring)
......@@ -111,6 +113,55 @@ class CreditMutuelBrowser(BaseBrowser):
return l_ret
def transfer(self, account, to, amount, reason=None):
# access the transfer page
transfert_url = 'WI_VPLV_VirUniSaiCpt.asp?RAZ=ALL&Cat=6&PERM=N&CHX=A'
self.location('https://%s/%s/fr/banque/%s'%(self.DOMAIN, self.currentSubBank, transfert_url))
# fill the form
self['IDB'] = [account[-1]]
self['ICR'] = [to[-1]]
self['MTTVIR'] = '%s' % str(amount).replace('.',',')
if reason != None:
self['LIBDBT'] = reason
self['LIBCRT'] = reason
# look for known errors
content = unicode(self.response().get_data(), self.ENCODING)
insufficient_amount_message = u'Montant insuffisant.'
maximum_allowed_balance_message = u'Solde maximum autorisé dépassé.'
if content.find(insufficient_amount_message) != -1:
raise TransferError('The amount you tried to transfer is too low.')
if content.find(maximum_allowed_balance_message) != -1:
raise TransferError('The maximum allowed balance for the target account has been / would be reached.')
# look for the known "all right" message
ready_for_transfer_message = u'Confirmez un virement entre vos comptes'
if not content.find(ready_for_transfer_message):
raise TransferError('The expected message "%s" was not found.' % ready_for_transfer_message)
# submit the confirmation form
submit_date =
# look for the known "everything went well" message
content = unicode(self.response().get_data(), self.ENCODING)
transfer_ok_message = u'Votre virement a été exécuté ce jour'
if not content.find(transfer_ok_message):
raise TransferError('The expected message "%s" was not found.' % transfer_ok_message)
# We now have to return a Transfer object
transfer = Transfer(submit_date.strftime('%Y%m%d%H%M%S'))
transfer.amount = amount
transfer.origin = account
transfer.recipient = to = submit_date
return transfer
#def get_coming_operations(self, account):
# if not self.is_on_page(AccountComing) or !=
......@@ -35,6 +35,9 @@ class LoginErrorPage(BasePage):
class InfoPage(BasePage):
class TransfertPage(BasePage):
class UserSpacePage(BasePage):
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