From 33e837d4297ce9ac64e3f0554c2a9699fd67ea3b Mon Sep 17 00:00:00 2001 From: "Nicolas Viseur (vin)" Date: Wed, 15 Nov 2023 13:18:55 +0800 Subject: [PATCH] [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) --- addons/account_payment/i18n/account_payment.pot | 4 ++-- addons/account_payment/models/payment_provider.py | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/addons/account_payment/i18n/account_payment.pot b/addons/account_payment/i18n/account_payment.pot index 57ce0c900df..ce1ab79686b 100644 --- a/addons/account_payment/i18n/account_payment.pot +++ b/addons/account_payment/i18n/account_payment.pot @@ -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 diff --git a/addons/account_payment/models/payment_provider.py b/addons/account_payment/models/payment_provider.py index ba2d3eca8f4..cfd6d48d806 100644 --- a/addons/account_payment/models/payment_provider.py +++ b/addons/account_payment/models/payment_provider.py @@ -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()