[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) <vfe@odoo.com> Signed-off-by: Mohamed Megahed Abbas Megahed SALLAM (mome) <mome@odoo.com>
This commit is contained in:
@@ -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)
|
||||
))
|
||||
|
||||
@@ -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 ""
|
||||
|
||||
Reference in New Issue
Block a user