From a32c277facf535c36a4800a9dff81517b5db18b4 Mon Sep 17 00:00:00 2001 From: "Antoine Vandevenne (anv)" Date: Thu, 22 Feb 2024 18:36:03 +0100 Subject: [PATCH] [FIX] payment: prevent changing the company when transactions exist opw-3696841 closes odoo/odoo#155113 Signed-off-by: Antoine Vandevenne (anv) --- addons/payment/i18n/payment.pot | 9 +++++++++ addons/payment/models/payment_provider.py | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/addons/payment/i18n/payment.pot b/addons/payment/i18n/payment.pot index 48a7b96f2e9..5325afd7745 100644 --- a/addons/payment/i18n/payment.pot +++ b/addons/payment/i18n/payment.pot @@ -2054,6 +2054,15 @@ msgstr "" msgid "Xendit" msgstr "" +#. module: payment +#. odoo-python +#: code:addons/payment/models/payment_provider.py:0 +#, python-format +msgid "" +"You cannot change the company of a payment provider with existing " +"transactions." +msgstr "" + #. module: payment #. odoo-python #: code:addons/payment/models/payment_provider.py:0 diff --git a/addons/payment/models/payment_provider.py b/addons/payment/models/payment_provider.py index 6de3adb3069..7ae402526ab 100644 --- a/addons/payment/models/payment_provider.py +++ b/addons/payment/models/payment_provider.py @@ -322,6 +322,20 @@ class PaymentProvider(models.Model): } } + @api.onchange('company_id') + def _onchange_company_block_if_existing_transactions(self): + """ Raise a user error when the company is changed and linked transactions exist. + + :return: None + :raise UserError: If transactions are linked to the provider. + """ + if self._origin.company_id != self.company_id and self.env['payment.transaction'].search( + [('provider_id', '=', self._origin.id)], limit=1 + ): + raise UserError(_( + "You cannot change the company of a payment provider with existing transactions." + )) + #=== CRUD METHODS ===# @api.model_create_multi