[FIX] payment: prevent changing the company when transactions exist

opw-3696841

closes odoo/odoo#155113

Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com>
This commit is contained in:
Antoine Vandevenne (anv)
2024-02-23 15:13:54 +00:00
parent 6ac4cd7d7b
commit a32c277fac
2 changed files with 23 additions and 0 deletions
+9
View File
@@ -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
+14
View File
@@ -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