[IMP] payment: use ondelete instead of custom error
Use generic method on_delete instead of personalized one for the sake of clarity and reproductibility. task-2883630 closes odoo/odoo#99958 Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||||
|
|
||||||
from . import ir_http
|
from . import ir_http
|
||||||
from . import ir_ui_view
|
|
||||||
from . import payment_provider
|
from . import payment_provider
|
||||||
from . import payment_icon
|
from . import payment_icon
|
||||||
from . import payment_token
|
from . import payment_token
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
||||||
|
|
||||||
from odoo import _, api, models
|
|
||||||
from odoo.exceptions import UserError
|
|
||||||
|
|
||||||
|
|
||||||
class IrUiView(models.Model):
|
|
||||||
_inherit = 'ir.ui.view'
|
|
||||||
|
|
||||||
@api.ondelete(at_uninstall=False)
|
|
||||||
def _unlink_if_not_referenced_by_provider(self):
|
|
||||||
referencing_providers_sudo = self.env['payment.provider'].sudo().search([
|
|
||||||
'|', ('redirect_form_view_id', 'in', self.ids), ('inline_form_view_id', 'in', self.ids)
|
|
||||||
]) # In sudo mode to allow non-admin users (e.g., Website designers) to read the view ids.
|
|
||||||
if referencing_providers_sudo:
|
|
||||||
raise UserError(_("You cannot delete a view that is used by a payment provider."))
|
|
||||||
@@ -68,11 +68,15 @@ class PaymentProvider(models.Model):
|
|||||||
redirect_form_view_id = fields.Many2one(
|
redirect_form_view_id = fields.Many2one(
|
||||||
string="Redirect Form Template", comodel_name='ir.ui.view',
|
string="Redirect Form Template", comodel_name='ir.ui.view',
|
||||||
help="The template rendering a form submitted to redirect the user when making a payment",
|
help="The template rendering a form submitted to redirect the user when making a payment",
|
||||||
domain=[('type', '=', 'qweb')])
|
domain=[('type', '=', 'qweb')],
|
||||||
|
ondelete='restrict',
|
||||||
|
)
|
||||||
inline_form_view_id = fields.Many2one(
|
inline_form_view_id = fields.Many2one(
|
||||||
string="Inline Form Template", comodel_name='ir.ui.view',
|
string="Inline Form Template", comodel_name='ir.ui.view',
|
||||||
help="The template rendering the inline payment form when making a direct payment",
|
help="The template rendering the inline payment form when making a direct payment",
|
||||||
domain=[('type', '=', 'qweb')])
|
domain=[('type', '=', 'qweb')],
|
||||||
|
ondelete='restrict',
|
||||||
|
)
|
||||||
token_inline_form_view_id = fields.Many2one(
|
token_inline_form_view_id = fields.Many2one(
|
||||||
string="Token Inline Form Template",
|
string="Token Inline Form Template",
|
||||||
comodel_name='ir.ui.view',
|
comodel_name='ir.ui.view',
|
||||||
|
|||||||
Reference in New Issue
Block a user