[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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user