From a0f325d6c21faea6fe3cd2ec61c270c9f52a2b08 Mon Sep 17 00:00:00 2001 From: Florent Viard Date: Mon, 4 Jan 2021 14:46:29 +0100 Subject: [PATCH] [boursorama] Fixes new_recipient when called by the backend from a bank openapi account --- modules/boursorama/browser.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/modules/boursorama/browser.py b/modules/boursorama/browser.py index f104dba092..e464622fd7 100644 --- a/modules/boursorama/browser.py +++ b/modules/boursorama/browser.py @@ -45,7 +45,7 @@ from weboob.capabilities.base import NotLoaded, empty, find_object, strict_find_object from weboob.capabilities.contact import Advisor from weboob.tools.value import Value -from weboob.tools.compat import basestring, urlsplit +from weboob.tools.compat import urlsplit from weboob.tools.capabilities.bank.transactions import sorted_transactions from weboob.tools.capabilities.bank.bank_transfer import sorted_transfers @@ -703,6 +703,10 @@ def init_transfer(self, transfer, **kwargs): raise TransferInvalidEmitter('The account cannot emit transfers') recipients = [rcpt for rcpt in recipients if rcpt.id == transfer.recipient_id] + if len(recipients) == 0 and not empty(transfer.recipient_iban): + # try to find recipients by iban: + recipients = [rcpt for rcpt in recipients + if not empty(rcpt.iban) and rcpt.iban == transfer.recipient_iban] if len(recipients) == 0: raise TransferInvalidRecipient('The recipient cannot be used with the emitter account') assert len(recipients) == 1 @@ -802,6 +806,10 @@ def init_new_recipient(self, recipient): break elif account.id == recipient.origin_account_id: break + elif (not empty(recipient.origin_account_iban) + and not empty(account.iban) + and account.iban == recipient.origin_account_iban): + break else: raise AddRecipientBankError(message="Compte ne permettant pas l'ajout de bénéficiaires") @@ -895,7 +903,11 @@ def check_and_update_recipient(self, recipient, account_url): # here we just want to return the right Recipient object. # We are taking it from the recipient list page # because there is no summary of the adding - self.go_recipients_list(account_url, recipient.origin_account_id) + account = self.get_account(recipient.origin_account_id, recipient.origin_account_iban) + if not account: + raise AccountNotFound() + + self.go_recipients_list(account_url, account.id) return find_object(self.page.iter_recipients(), iban=recipient.iban, error=RecipientNotFound) @need_login -- GitLab