diff --git a/addons/payment/i18n/payment.pot b/addons/payment/i18n/payment.pot index 0ca3abe4a0199da741745b959849d65a6949cf81..d003b7c47a6da421cfcbfd995aa6d6e307dc8ba2 100644 --- a/addons/payment/i18n/payment.pot +++ b/addons/payment/i18n/payment.pot @@ -1987,6 +1987,12 @@ msgstr "" msgid "You can click here to be redirected to the confirmation page." msgstr "" +#. module: payment +#: code:addons/payment/models/payment_acquirer.py:0 +#, python-format +msgid "You cannot delete the payment acquirer %s; archive it instead." +msgstr "" + #. module: payment #: code:addons/payment/wizards/payment_acquirer_onboarding_wizard.py:0 #, python-format diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index 70a7a03f2aa176c909c671e51cc41b78723c467f..f85ecbb8470c0062da14d86292e1b544d8ba570b 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -10,12 +10,14 @@ import psycopg2 from odoo import api, exceptions, fields, models, _, SUPERUSER_ID from odoo.tools import consteq, float_round, image_process, ustr -from odoo.exceptions import ValidationError +from odoo.exceptions import UserError, ValidationError from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT from odoo.tools.misc import formatLang from odoo.http import request from odoo.osv import expression +from odoo.addons.base.models.ir_model import MODULE_UNINSTALL_FLAG + _logger = logging.getLogger(__name__) @@ -336,6 +338,19 @@ class PaymentAcquirer(models.Model): self._check_required_if_provider() return result + def unlink(self): + """ Prevent the deletion of the payment acquirer if it has an xmlid. """ + external_ids = self.get_external_id() + for acquirer in self: + external_id = external_ids[acquirer.id] + if external_id \ + and not external_id.startswith('__export__') \ + and not self._context.get(MODULE_UNINSTALL_FLAG): + raise UserError( + _("You cannot delete the payment acquirer %s; archive it instead.", acquirer.name) + ) + return super().unlink() + def get_acquirer_extra_fees(self, amount, currency_id, country_id): extra_fees = { 'currency_id': currency_id