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