diff --git a/addons/payment/wizards/payment_link_wizard.py b/addons/payment/wizards/payment_link_wizard.py index c9fa3b46eda..a17c0691c13 100644 --- a/addons/payment/wizards/payment_link_wizard.py +++ b/addons/payment/wizards/payment_link_wizard.py @@ -1,5 +1,4 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. -from lxml import etree from werkzeug import urls from odoo import _, api, fields, models @@ -31,41 +30,6 @@ class PaymentLinkWizard(models.TransientModel): }) return res - @api.model - def fields_view_get(self, *args, **kwargs): - """ Overrides orm fields_view_get - - Using a Many2One field, when a user opens this wizard and tries to select a preferred - payment acquirer, he will get an AccessError telling that he is not allowed to access - 'payment.acquirer' records. This error is thrown because the Many2One field is filled - by the name_get() function and users don't have clearance to read 'payment.acquirer' records. - - This override allows replacing the Many2One with a selection field, that is prefilled in the - backend with the name of available acquirers. Therefore, Users will be able to select their - preferred acquirer. - - :return: composition of the requested view (including inherited views and extensions) - :rtype: dict - """ - res = super().fields_view_get(*args, **kwargs) - if res['type'] == 'form': - doc = etree.XML(res['arch']) - - # Replace acquirer_id with payment_acquirer_selection in the view - acq = doc.xpath("//field[@name='acquirer_id']")[0] - acq.attrib['name'] = 'payment_acquirer_selection' - acq.attrib['widget'] = 'selection' - acq.attrib['string'] = 'Force Payment Acquirer' - del acq.attrib['options'] - del acq.attrib['placeholder'] - - # Replace acquirer_id with payment_acquirer_selection in the fields list - xarch, xfields = self.env['ir.ui.view'].postprocess_and_fields(doc, model=self._name) - - res['arch'] = xarch - res['fields'] = xfields - return res - res_model = fields.Char('Related Document Model', required=True) res_id = fields.Integer('Related Document ID', required=True) amount = fields.Monetary(currency_field='currency_id', required=True) @@ -83,22 +47,17 @@ class PaymentLinkWizard(models.TransientModel): compute='_compute_available_acquirer_ids', compute_sudo=True, ) - acquirer_id = fields.Many2one( - comodel_name='payment.acquirer', - string="Force Payment Acquirer", - domain="[('id', 'in', available_acquirer_ids)]", - help="Force the customer to pay via the specified payment acquirer. Leave empty to allow the customer to choose among all acquirers." - ) has_multiple_acquirers = fields.Boolean( string="Has Multiple Acquirers", compute='_compute_has_multiple_acquirers', ) payment_acquirer_selection = fields.Selection( - string="Payment acquirer selected", + string="Allow Payment Acquirer", + help="If a specific payment acquirer is selected, customers will only be allowed to pay " + "via this one. If 'All' is selected, customers can pay via any available payment " + "acquirer.", selection='_selection_payment_acquirer_selection', default='all', - compute='_compute_payment_acquirer_selection', - inverse='_inverse_payment_acquirer_selection', required=True, ) @@ -135,15 +94,6 @@ class PaymentLinkWizard(models.TransientModel): currency_id=link.currency_id.id, ) - @api.depends('acquirer_id') - def _compute_payment_acquirer_selection(self): - for link in self: - link.payment_acquirer_selection = link.acquirer_id.id if link.acquirer_id else 'all' - - def _inverse_payment_acquirer_selection(self): - for link in self: - link.acquirer_id = link.payment_acquirer_selection if link.payment_acquirer_selection != 'all' else False - def _selection_payment_acquirer_selection(self): """ Specify available acquirers in the selection field. :return: The selection list of available acquirers. diff --git a/addons/payment/wizards/payment_link_wizard_views.xml b/addons/payment/wizards/payment_link_wizard_views.xml index ef38915f695..5951c9caddb 100644 --- a/addons/payment/wizards/payment_link_wizard_views.xml +++ b/addons/payment/wizards/payment_link_wizard_views.xml @@ -17,9 +17,7 @@ -