[FIX] account_payment: Better uninstallation

Improve the uninstallation of payment providers by allowing to
uninstall payment providers which have a payment method line on
a journal but no payment yet.

Task id #3595006

closes odoo/odoo#142112

Signed-off-by: Florian Gilbert (flg) <flg@odoo.com>
This commit is contained in:
Nicolas Viseur (vin)
2023-11-27 08:39:47 +00:00
parent 04e121644a
commit 33e837d429
2 changed files with 9 additions and 4 deletions
@@ -554,8 +554,8 @@ msgstr ""
#: code:addons/account_payment/models/payment_provider.py:0
#, python-format
msgid ""
"You cannot uninstall this module as payment method transactions already "
"exist."
"You cannot uninstall this module as payments using this payment method "
"already exist."
msgstr ""
#. module: account_payment
@@ -98,11 +98,16 @@ class PaymentProvider(models.Model):
payment_method.id)], limit=1)
return bool(existing_payment_method_lines_count)
def _check_existing_payment(self, payment_method):
existing_payment_count = self.env['account.payment'].search_count([('payment_method_id', '=', payment_method.id)], limit=1)
return bool(existing_payment_count)
@api.model
def _remove_provider(self, code):
""" Override of `payment` to delete the payment method of the provider. """
payment_method = self._get_provider_payment_method(code)
if self._check_existing_payment_method_lines(payment_method):
raise UserError(_("You cannot uninstall this module as payment method transactions already exist."))
# If the payment method is used by any payments, we block the uninstallation of the module.
if self._check_existing_payment(payment_method):
raise UserError(_("You cannot uninstall this module as payments using this payment method already exist."))
super()._remove_provider(code)
payment_method.unlink()