[REF] payment: cleanup payment link wizard
Delete code that is not useful anymore and was introduced in task-2666881 (PR #78334) task-2694027 closes odoo/odoo#80051 Related: odoo/upgrade#3050 Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com>
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -17,9 +17,7 @@
|
||||
<field name="has_multiple_acquirers" invisible="1"/>
|
||||
<field name="description"/>
|
||||
<field name="amount"/>
|
||||
<field name="acquirer_id"
|
||||
placeholder="Leave empty to allow all acquirers"
|
||||
options="{'no_open': True, 'no_create': True}"
|
||||
<field name="payment_acquirer_selection"
|
||||
attrs="{'invisible':[('has_multiple_acquirers', '=', False)]}"/>
|
||||
<field name="currency_id" invisible="1"/>
|
||||
<field name="access_token" invisible="1"/>
|
||||
|
||||
Reference in New Issue
Block a user