[FIX] base_automation: correctly trigger on_change rules
Before this commit, and since [1], automated rules of type "on_change" (i.e. on UI update) didn't run. This is because the wrong field (trigger_field_ids) was used to record fields for which the rule must be triggered. For that type of rule, the field to use is on_change_field_ids. As a consequence, those rules were not correctly created, and thus they didn't properly react to field changes. [1] odoo/odoo@8bdac7e26c opw 3632084 opw 3595411 closes odoo/odoo#146780 Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
This commit is contained in:
@@ -98,7 +98,12 @@
|
||||
options="{'no_open': True, 'no_create': True}"
|
||||
domain="[('model_id', '=', model_id)]"
|
||||
context="{'hide_model': 1}"
|
||||
invisible="trigger not in ['on_create_or_write', 'on_change']" widget="many2many_tags" />
|
||||
invisible="trigger != 'on_create_or_write'" widget="many2many_tags" />
|
||||
<field name="on_change_field_ids" string="When updating" placeholder="Select fields..."
|
||||
options="{'no_open': True, 'no_create': True}"
|
||||
domain="[('model_id', '=', model_id)]"
|
||||
context="{'hide_model': 1}"
|
||||
invisible="trigger != 'on_change'" widget="many2many_tags" />
|
||||
</group>
|
||||
<group>
|
||||
<label for="record_getter" string="Target Record" invisible="trigger != 'on_webhook'" />
|
||||
|
||||
@@ -628,4 +628,30 @@ registry.category("web_tour.tours").add("test_form_view_mail_triggers", {
|
||||
run() {}
|
||||
}
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
registry.category("web_tour.tours").add('base_automation.on_change_rule_creation', {
|
||||
test: true,
|
||||
url: "/web#action=base_automation.base_automation_act",
|
||||
steps: () => [
|
||||
{
|
||||
trigger: ".o-kanban-button-new",
|
||||
}, {
|
||||
trigger: ".o_field_widget[name=name] input",
|
||||
run: "text Test rule",
|
||||
}, {
|
||||
trigger: ".o_field_widget[name=model_id] input",
|
||||
run: "text ir.ui.view",
|
||||
}, {
|
||||
trigger: ".ui-menu-item > a:containsExact('View')",
|
||||
}, {
|
||||
trigger: ".o_field_widget[name=trigger] select",
|
||||
run: 'text "on_change"',
|
||||
}, {
|
||||
trigger: ".o_field_widget[name=on_change_field_ids] input",
|
||||
run: "text Active",
|
||||
}, {
|
||||
trigger: ".ui-menu-item > a:containsExact('Active')",
|
||||
},
|
||||
...stepUtils.saveForm(),
|
||||
]});
|
||||
|
||||
@@ -293,3 +293,19 @@ class BaseAutomationTestUi(HttpCase):
|
||||
"test_form_view_mail_triggers",
|
||||
login="admin",
|
||||
)
|
||||
|
||||
def test_on_change_rule_creation(self):
|
||||
""" test on_change rule creation from the UI """
|
||||
self.start_tour("/web#action=base_automation.base_automation_act", 'base_automation.on_change_rule_creation', login="admin")
|
||||
|
||||
rule = self.env['base.automation'].search([], order="create_date desc", limit=1)[0]
|
||||
view_model = self.env['ir.model']._get("ir.ui.view")
|
||||
active_field = self.env['ir.model.fields'].search([
|
||||
('name', '=', 'active'),
|
||||
('model', '=', 'ir.ui.view'),
|
||||
])[0]
|
||||
self.assertEqual(rule.name, "Test rule")
|
||||
self.assertEqual(rule.model_id, view_model)
|
||||
self.assertEqual(rule.trigger, 'on_change')
|
||||
self.assertEqual(len(rule.on_change_field_ids), 1)
|
||||
self.assertEqual(rule.on_change_field_ids[0], active_field)
|
||||
|
||||
Reference in New Issue
Block a user