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
25 lines
1022 B
Python
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
|
|
)
|
|
)
|