From 636601c4a4d4036578d1065ebea26e76650ad82d Mon Sep 17 00:00:00 2001 From: momegahed Date: Tue, 13 Dec 2022 13:28:23 +0000 Subject: [PATCH] [FIX] payment: user is able to delete linked journals Steps to reproduce: 1- install any payment acquirer (e.g. stripe) 2- configure the payment acquirer and link it to a journal 3- try to delete the journal 4- the journal can be deleted which will create an internal server error when this payment acquirer is used Bug: There is no restriction on deleting `account.journal` linked to payment acquirers Fix: add a restriction that forces the user to remove the journal from the payment acquirers first OPW-3089006 closes odoo/odoo#108403 X-original-commit: 3ec6fe4ab1df3e3368fd06ff0e18a240caf088e5 Signed-off-by: Victor Feyens (vfe) Signed-off-by: Mohamed Megahed Abbas Megahed SALLAM (mome) --- addons/account_payment/models/account_journal.py | 11 +++++++++++ addons/payment/i18n/payment.pot | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/addons/account_payment/models/account_journal.py b/addons/account_payment/models/account_journal.py index bd7f2d43b73..dfc60af1a15 100644 --- a/addons/account_payment/models/account_journal.py +++ b/addons/account_payment/models/account_journal.py @@ -75,3 +75,14 @@ class AccountJournal(models.Model): to_remove.append(payment_method.id) journal.available_payment_method_ids = [Command.unlink(payment_method) for payment_method in to_remove] + + @api.ondelete(at_uninstall=False) + def _unlink_except_linked_to_payment_provider(self): + linked_providers = self.env['payment.provider'].sudo().search([]).filtered( + lambda p: p.journal_id.id in self.ids and p.state != 'disabled' + ) + if linked_providers: + raise UserError(_( + "You must first deactivate a payment provider before deleting its journal.\n" + "Linked providers: %s", ', '.join(p.display_name for p in linked_providers) + )) diff --git a/addons/payment/i18n/payment.pot b/addons/payment/i18n/payment.pot index 2f334edc42e..ecf8603150e 100644 --- a/addons/payment/i18n/payment.pot +++ b/addons/payment/i18n/payment.pot @@ -2161,3 +2161,11 @@ msgstr "" #: model_terms:ir.ui.view,arch_db:payment.transaction_status msgid "warning" msgstr "" + +#. module: payment +#: code:addons/payment/models/account_journal.py:0 +#, python-format +msgid "" +"You must first deactivate a payment provider before deleting its journal.\n" +"Linked providers: %s" +msgstr ""