Files
odoo_source/addons/base_automation/models/ir_actions_server.py
T
Thibault Delavallée a8b08b8e92 [FIX] base_automation: check server actions model match rule model
New implementation of automated rules does not check if rule model matches
models of its children server actions. This can easily lead to updating
records of another model which have nothing in common with the automation
rule.

Also better write the reset when changing model.

Task-3527758 (Base Automation Refactor Fiximp)
Part of Task-3527752 (Mail: The Pre-Major Freeze FixImpLint)

Part-of: odoo/odoo#137133
2023-10-02 06:54:38 +00:00

25 lines
1022 B
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, exceptions, fields, models, _
class ServerAction(models.Model):
_inherit = "ir.actions.server"
usage = fields.Selection(selection_add=[
('base_automation', 'Automation Rule')
], ondelete={'base_automation': 'cascade'})
base_automation_id = fields.Many2one('base.automation', string='Automation Rule', ondelete='cascade')
@api.constrains('model_id', 'base_automation_id')
def _check_model_coherency_with_automation(self):
for action in self.filtered('base_automation_id'):
if action.model_id != action.base_automation_id.model_id:
raise exceptions.ValidationError(
_("Model of action %(action_name)s should match the one from automated rule %(rule_name)s.",
action_name=action.name,
rule_name=action.base_automation_id.name
)
)