[FIX] payment: prevent deletion of payment provider if it has external reference
"ValueError: External ID not found in the system: payment.payment_provider_ stripe" is generated because the user deleted the Stripe payment provider record and its corresponding model tried to access the record of it. Steps to produce the error:(in >=16.0) 1. Install e-commerce 2. Install 'Payment Provider: Stripe' 3. delete the Stripe from payment Provider 4. Go to the website > Reporting > e-commerce 5. Click Activate Stripe on eCommerce Dashboard This commit solves the above issue by preventing the deletion of the payment provider if it has a external reference. sentry-4041178833 closes odoo/odoo#120534 X-original-commit: 7082ce2460494891e8e063c11678226b164f99e7 Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com> Signed-off-by: Ansari Mahamadasif (maan) <maan@odoo.com>
This commit is contained in:
@@ -2008,6 +2008,13 @@ msgstr ""
|
||||
msgid "You can click here to be redirected to the confirmation page."
|
||||
msgstr ""
|
||||
|
||||
#. module: payment
|
||||
#. odoo-python
|
||||
#: code:addons/payment/models/payment_provider.py:0
|
||||
#, python-format
|
||||
msgid "You cannot delete the payment provider %s; archive it instead."
|
||||
msgstr ""
|
||||
|
||||
#. module: payment
|
||||
#. odoo-python
|
||||
#: code:addons/payment/models/payment_provider.py:0
|
||||
|
||||
@@ -412,6 +412,17 @@ class PaymentProvider(models.Model):
|
||||
"""
|
||||
self.env['payment.token'].search([('provider_id', 'in', self.ids)]).write({'active': False})
|
||||
|
||||
@api.ondelete(at_uninstall=False)
|
||||
def _unlink_except_master_data(self):
|
||||
""" Prevent the deletion of the payment provider if it has an xmlid. """
|
||||
external_ids = self.get_external_id()
|
||||
for provider in self:
|
||||
external_id = external_ids[provider.id]
|
||||
if external_id and not external_id.startswith('__export__'):
|
||||
raise UserError(
|
||||
_("You cannot delete the payment provider %s; archive it instead.", provider.name)
|
||||
)
|
||||
|
||||
#=== ACTION METHODS ===#
|
||||
|
||||
def button_immediate_install(self):
|
||||
|
||||
Reference in New Issue
Block a user