Commit 0b884402 authored by Florent Viard's avatar Florent Viard Committed by Vincent A

[boursorama] Fixes succesful recipient additions that results in "Recipient not found" errors

When adding recipients, sometimes the process would successfully go to
completion but an error "Recipient not found" would be raised at the
final check.
(ie when we check that the newly added recipient is inside the
recipients list)

The origin of the problem is that on Boursorama side, the recipient list
is global for all accounts.
But for some accounts, the recipient list is prefixed (ex. saving
accounts) or transfer is not allowed (ex. market accounts).

Before, the "origin" account that was used to add the recipient was
selected in a random way as "the first account retrieved by
get_accounts".
This was not good as, randomly, an unusable account could have been
selected, like saving accounts.

Boobank does not select an origin_account_id, but if it is the case, we
also have to ensure that the account is valid to add the recipient.
And so, avoid to fail in an unexpected way.
parent 93ee2b51
......@@ -40,6 +40,7 @@ from weboob.capabilities.bank import (
TransferInvalidEmitter, TransferInvalidLabel, TransferInvalidRecipient,
AddRecipientStep, Rate, TransferBankError, AccountOwnership, RecipientNotFound,
AddRecipientTimeout, TransferDateType, Emitter, TransactionType,
AddRecipientBankError,
)
from weboob.capabilities.base import empty, find_object
from weboob.capabilities.contact import Advisor
......@@ -770,26 +771,46 @@ class BoursoramaBrowser(RetryLoginBrowser, TwoFactorBrowser):
@need_login
def init_new_recipient(self, recipient):
self.recipient_form = None # so it is reset when a new recipient is added
# so it is reset when a new recipient is added
self.recipient_form = None
# get url
# If an account was provided for the recipient, use it
# otherwise use the first checking account available
account = None
for account in self.get_accounts_list():
if account.url:
if not account.url:
continue
if recipient.origin_account_id is None:
if account.type == Account.TYPE_CHECKING:
break
elif account.id == recipient.origin_account_id:
break
suffix = 'virements/comptes-externes/nouveau'
if account.url.endswith('/'):
target = account.url + suffix
else:
target = account.url + '/' + suffix
raise AddRecipientBankError(message="Compte ne permettant pas l'ajout de bénéficiaires")
try:
self.go_recipients_list(account.url, account.id)
except AccountNotFound:
raise AddRecipientBankError(message="Compte ne permettant pas d'emettre des virements")
assert (
self.recipients_page.is_here()
or self.new_transfer_wizard.is_here()
), 'Should be on recipients page'
if not self.page.is_new_recipient_allowed():
raise AddRecipientBankError(message="Compte ne permettant pas l'ajout de bénéficiaires")
target = '%s/virements/comptes-externes/nouveau' % account.url.rstrip('/')
self.location(target)
assert self.page.is_characteristics(), 'Not on the page to add recipients.'
# fill recipient form
self.page.submit_recipient(recipient)
recipient.origin_account_id = account.id
if recipient.origin_account_id is None:
recipient.origin_account_id = account.id
# confirm sending sms
assert self.page.is_confirm_send_sms(), 'Cannot reach the page asking to send a sms.'
......@@ -804,7 +825,8 @@ class BoursoramaBrowser(RetryLoginBrowser, TwoFactorBrowser):
self.recipient_form['account_url'] = account.url
raise AddRecipientStep(recipient, Value('otp_sms', label='Veuillez saisir le code recu par sms'))
# if the add recipient is restarted after the sms has been confirmed recently, the sms step is not presented again
# if the add recipient is restarted after the sms has been confirmed recently,
# the sms step is not presented again
return self.rcpt_after_sms(recipient, account.url)
def new_recipient(self, recipient, **kwargs):
......@@ -814,8 +836,9 @@ class BoursoramaBrowser(RetryLoginBrowser, TwoFactorBrowser):
# validating the sms code directly adds the recipient
account_url = self.send_recipient_form(kwargs['otp_sms'])
return self.rcpt_after_sms(recipient, account_url)
# step 3 of new_recipient (not always used)
elif 'otp_email' in kwargs:
if 'otp_email' in kwargs:
account_url = self.send_recipient_form(kwargs['otp_email'])
return self.check_and_update_recipient(recipient, account_url)
......
......@@ -40,7 +40,7 @@ from weboob.browser.filters.standard import (
MapIn, Lower, Base,
)
from weboob.browser.filters.json import Dict
from weboob.browser.filters.html import Attr, Link, TableCell
from weboob.browser.filters.html import Attr, HasElement, Link, TableCell
from weboob.capabilities.bank import (
Account as BaseAccount, Recipient, Transfer, TransferDateType, AccountNotFound,
AddRecipientBankError, TransferInvalidAmount, Loan, AccountOwnership,
......@@ -1292,6 +1292,9 @@ class TransferRecipients(LoggedPage, HTMLPage):
form['CreditAccount[creditAccountKey]'] = tempid
form.submit()
def is_new_recipient_allowed(self):
return True
class NewTransferWizard(LoggedPage, HTMLPage):
def get_errors(self):
......@@ -1385,6 +1388,13 @@ class NewTransferWizard(LoggedPage, HTMLPage):
form.submit()
def is_new_recipient_allowed(self):
try:
self.get_form(name='CreditAccount')
except FormNotFound:
return False
return HasElement('//input[@id="CreditAccount_newBeneficiary"]')(self.doc)
# STEP 3 -
# If using existing recipient: select the amount
# If new beneficiary: select if new recipient is own account or third party one
......
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