[IMP] base_automation: adapt views to boolean update
Changes to the UX of boolean field updates via server actions required some adaptations of the views of base_automation. Task-3450200 Part-of: odoo/odoo#138804
This commit is contained in:
@@ -23,7 +23,7 @@ class TestAutomation(TransactionCase):
|
||||
"base_automation_id": automation.id,
|
||||
"state": "object_write",
|
||||
"update_path": "active",
|
||||
"value": False,
|
||||
"update_boolean_value": "false",
|
||||
"model_id": model.id,
|
||||
})
|
||||
automation.write({"action_server_ids": [Command.link(action.id)]})
|
||||
@@ -52,7 +52,7 @@ class TestAutomation(TransactionCase):
|
||||
"model_id": model.id,
|
||||
"state": "object_write",
|
||||
"update_path": "active",
|
||||
"value": False
|
||||
"update_boolean_value": "false",
|
||||
})
|
||||
action.flush_recordset()
|
||||
automation.write({"action_server_ids": [Command.link(action.id)]})
|
||||
|
||||
@@ -179,6 +179,7 @@
|
||||
<span invisible="evaluation_type != 'equation'">as</span>
|
||||
<field name="resource_ref" invisible="not (value_field_to_show == 'resource_ref' and evaluation_type == 'value')" />
|
||||
<field name="selection_value" invisible="not (value_field_to_show == 'selection_value' and evaluation_type == 'value')" class="d-inline"/>
|
||||
<field name="update_boolean_value" invisible="not (value_field_to_show == 'update_boolean_value' and evaluation_type == 'value')" class="d-inline"/>
|
||||
<em invisible="not (value_field_to_show == 'value' and evaluation_type == 'value')" t-out="record.value.raw_value" class="d-inline"/>
|
||||
<code invisible="not (evaluation_type == 'equation')" t-out="record.value.raw_value"/>
|
||||
</t>
|
||||
|
||||
@@ -76,19 +76,24 @@ registry.category("web_tour.tours").add("test_base_automation", {
|
||||
},
|
||||
{
|
||||
content: "Set new action to update the record",
|
||||
trigger: " .modal-content .o_form_renderer [name='state'] select",
|
||||
run: 'text "object_write"',
|
||||
trigger: ".modal-content .o_form_renderer [name='state'] span[value*='object_write']",
|
||||
},
|
||||
{
|
||||
content: "Open update select",
|
||||
content: "Focus on the 'update_path' field",
|
||||
trigger: ".modal-content .o_form_renderer [name='update_path'] .o_model_field_selector",
|
||||
},
|
||||
{
|
||||
content: "Input field name",
|
||||
trigger:
|
||||
'.modal-content .o_form_renderer .o_field_widget[name="update_field_id"] input',
|
||||
'.o_model_field_selector_popover .o_model_field_selector_popover_search input',
|
||||
run: "text Job Position",
|
||||
in_modal: false,
|
||||
},
|
||||
{
|
||||
content: "Open update select",
|
||||
content: "Select field",
|
||||
in_modal: false,
|
||||
trigger:
|
||||
'.modal-content .o_form_renderer div[name="update_field_id"] .dropdown-menu li a:contains(Job Position):not(:has(.fa-spin))',
|
||||
'.o_model_field_selector_popover .o_model_field_selector_popover_page li[data-name="function"] button',
|
||||
},
|
||||
{
|
||||
content: "Open update select",
|
||||
@@ -147,7 +152,7 @@ registry.category("web_tour.tours").add("test_base_automation_on_tag_added", {
|
||||
on_time_updated: "After last update",
|
||||
on_create_or_write: "On save",
|
||||
on_unlink: "On deletion",
|
||||
on_change: "On live update",
|
||||
on_change: "On UI change",
|
||||
on_webhook: "On webhook",
|
||||
})
|
||||
);
|
||||
@@ -157,21 +162,36 @@ registry.category("web_tour.tours").add("test_base_automation_on_tag_added", {
|
||||
trigger: ".o_form_renderer #trigger_0",
|
||||
run: 'text "on_tag_set"',
|
||||
},
|
||||
{
|
||||
trigger: '.o_form_renderer div[name="trg_field_ref"] input',
|
||||
run: "text test",
|
||||
},
|
||||
{
|
||||
trigger:
|
||||
'.o_form_renderer div[name="trg_field_ref"] .dropdown-menu li a:contains(test):not(:has(.fa-spin))',
|
||||
},
|
||||
{
|
||||
trigger: '.o_form_renderer div[name="action_server_ids"] button',
|
||||
},
|
||||
{
|
||||
trigger: " .modal-content .o_form_renderer [name='state'] select",
|
||||
run: 'text "object_write"',
|
||||
trigger: " .modal-content .o_form_renderer [name='state'] span[value*='object_write']",
|
||||
},
|
||||
{
|
||||
content: "Focus on the 'update_path' field",
|
||||
trigger: ".modal-content .o_form_renderer [name='update_path'] .o_model_field_selector",
|
||||
},
|
||||
{
|
||||
content: "Input field name",
|
||||
trigger:
|
||||
'.modal-content .o_form_renderer .o_field_widget[name="update_field_id"] input',
|
||||
'.o_model_field_selector_popover .o_model_field_selector_popover_search input',
|
||||
run: "text Name",
|
||||
in_modal: false,
|
||||
},
|
||||
{
|
||||
content: "Select field",
|
||||
in_modal: false,
|
||||
trigger:
|
||||
'.modal-content .o_form_renderer div[name="update_field_id"] .dropdown-menu li a:contains(Name):not(:has(.fa-spin))',
|
||||
'.o_model_field_selector_popover .o_model_field_selector_popover_page li[data-name="name"] button',
|
||||
},
|
||||
{
|
||||
trigger: '.modal-content .o_form_renderer div[name="value"] textarea',
|
||||
@@ -184,17 +204,24 @@ registry.category("web_tour.tours").add("test_base_automation_on_tag_added", {
|
||||
trigger: '.o_form_renderer div[name="action_server_ids"] button',
|
||||
},
|
||||
{
|
||||
trigger: " .modal-content .o_form_renderer [name='state'] select",
|
||||
run: 'text "object_write"',
|
||||
trigger: " .modal-content .o_form_renderer [name='state'] span[value*='object_write']",
|
||||
},
|
||||
{
|
||||
content: "Focus on the 'update_path' field",
|
||||
trigger: ".modal-content .o_form_renderer [name='update_path'] .o_model_field_selector",
|
||||
},
|
||||
{
|
||||
content: "Input field name",
|
||||
trigger:
|
||||
'.modal-content .o_form_renderer .o_field_widget[name="update_field_id"] input',
|
||||
'.o_model_field_selector_popover .o_model_field_selector_popover_search input',
|
||||
run: "text Priority",
|
||||
in_modal: false,
|
||||
},
|
||||
{
|
||||
content: "Select field",
|
||||
in_modal: false,
|
||||
trigger:
|
||||
'.modal-content .o_form_renderer div[name="update_field_id"] .dropdown-menu li a:contains(Priority):not(:has(.fa-spin))',
|
||||
'.o_model_field_selector_popover .o_model_field_selector_popover_page li[data-name="priority"] button',
|
||||
},
|
||||
{
|
||||
trigger: '.modal-content .o_form_renderer div[name="selection_value"] input',
|
||||
@@ -221,7 +248,7 @@ registry.category("web_tour.tours").add("test_base_automation_on_tag_added", {
|
||||
);
|
||||
assertEqual(
|
||||
card.querySelector(".o_automation_actions").textContent,
|
||||
"Update Display NameUpdate Priority"
|
||||
"Update NameUpdate Priority"
|
||||
);
|
||||
},
|
||||
},
|
||||
@@ -335,7 +362,7 @@ registry.category("web_tour.tours").add("test_kanban_automation_view_create_acti
|
||||
async run() {
|
||||
assertEqual(
|
||||
document.querySelector("div[name='action_server_ids']").innerText,
|
||||
"Create User with name NameX"
|
||||
"Create Contact with name NameX"
|
||||
);
|
||||
assertEqual(document.querySelectorAll(".fa.fa-edit").length, 1);
|
||||
},
|
||||
@@ -375,7 +402,7 @@ registry.category("web_tour.tours").add("test_form_view_resequence_actions", {
|
||||
async run() {
|
||||
assertEqual(
|
||||
this.$anchor[0].innerText,
|
||||
"Set Active To False 0\nSet Active To False 1\nSet Active To False 2"
|
||||
"Update Active 0\nto\nNo (False)\nUpdate Active 1\nto\nNo (False)\nUpdate Active 2\nto\nNo (False)"
|
||||
);
|
||||
},
|
||||
},
|
||||
@@ -391,7 +418,7 @@ registry.category("web_tour.tours").add("test_form_view_resequence_actions", {
|
||||
async run() {
|
||||
assertEqual(
|
||||
this.$anchor[0].innerText,
|
||||
"Set Active To False 2\nSet Active To False 0\nSet Active To False 1"
|
||||
"Update Active 2\nto\nNo (False)\nUpdate Active 0\nto\nNo (False)\nUpdate Active 1\nto\nNo (False)"
|
||||
);
|
||||
},
|
||||
},
|
||||
@@ -412,16 +439,14 @@ registry.category("web_tour.tours").add("test_form_view_resequence_actions", {
|
||||
},
|
||||
},
|
||||
{
|
||||
trigger: ".modal-content .o_form_renderer [name='state'] select",
|
||||
run: 'text "object_write"',
|
||||
trigger: ".modal-content .o_form_renderer [name='state'] span[value*='object_write']",
|
||||
},
|
||||
{
|
||||
trigger: ".modal-content .o_form_renderer [name='state'] select",
|
||||
run: 'text "followers"',
|
||||
trigger: ".modal-content .o_form_renderer [name='state'] span[value*='followers']",
|
||||
},
|
||||
{
|
||||
extra_trigger:
|
||||
".modal-content .o_form_renderer [name='state'] select:contains(Add Followers)",
|
||||
".modal-content .o_form_renderer [name='state'] span.active[value*='followers']",
|
||||
trigger: ".modal-content .o_form_button_cancel",
|
||||
},
|
||||
{
|
||||
@@ -454,7 +479,7 @@ registry.category("web_tour.tours").add("test_form_view_model_id", {
|
||||
);
|
||||
assertEqual(
|
||||
triggerGroups.map((el) => el.innerText).join(" // "),
|
||||
"User is set // Based on date fieldAfter creationAfter last update // On saveOn deletionOn live update // On webhook"
|
||||
"User is set // Based on date fieldAfter creationAfter last update // On saveOn deletionOn UI change // On webhook"
|
||||
);
|
||||
},
|
||||
},
|
||||
@@ -488,7 +513,7 @@ registry.category("web_tour.tours").add("test_form_view_model_id", {
|
||||
);
|
||||
assertEqual(
|
||||
triggerGroups.map((el) => el.innerText).join(" // "),
|
||||
"Stage is set toUser is setTag is addedPriority is set to // Based on date fieldAfter creationAfter last update // On saveOn deletionOn live update // On webhook"
|
||||
"Stage is set toUser is setTag is addedPriority is set to // Based on date fieldAfter creationAfter last update // On saveOn deletionOn UI change // On webhook"
|
||||
);
|
||||
},
|
||||
},
|
||||
@@ -603,4 +628,4 @@ registry.category("web_tour.tours").add("test_form_view_mail_triggers", {
|
||||
run() {}
|
||||
}
|
||||
],
|
||||
});
|
||||
});
|
||||
@@ -801,7 +801,7 @@ if env.context.get('old_values', None): # on write
|
||||
trigger='on_unarchive',
|
||||
trigger_field_ids=[active_field.id],
|
||||
filter_domain="[('active', '=', True)]",
|
||||
_actions={'state': 'code', 'code': "record.write({'name': record.name + '!'})"},
|
||||
_actions={'state': 'object_write', 'evaluation_type': 'equation', 'update_path': 'name', 'value': "record.name + '!'"},
|
||||
)
|
||||
lead = self.create_lead()
|
||||
self.assertEqual(lead.name, 'Lead Test')
|
||||
@@ -969,8 +969,8 @@ class TestCompute(common.TransactionCase):
|
||||
lead_thread_model = self.env["ir.model"]._get("base.automation.lead.thread.test")
|
||||
automation = create_automation(self, trigger="on_message_sent", model_id=lead_thread_model.id, _actions={
|
||||
"state": "object_write",
|
||||
"update_field_id": self.env["ir.model.fields"]._get("base.automation.lead.thread.test", "active").id,
|
||||
"value": False
|
||||
"update_path": "active",
|
||||
"update_boolean_value": "false"
|
||||
})
|
||||
|
||||
ext_partner = self.env["res.partner"].create({"name": "ext", "email": "email@server.com"})
|
||||
@@ -1013,12 +1013,11 @@ class TestCompute(common.TransactionCase):
|
||||
@common.tagged("post_install", "-at_install")
|
||||
class TestHttp(common.HttpCase):
|
||||
def test_webhook_trigger(self):
|
||||
self.authenticate(None, None)
|
||||
model = self.env["ir.model"]._get("base.automation.linked.test")
|
||||
record_getter = "model.search([('name', '=', payload['name'])]) if payload.get('name') else None"
|
||||
automation = create_automation(self, trigger="on_webhook", model_id=model.id, record_getter=record_getter, log_webhook_calls=True, _actions={
|
||||
automation = create_automation(self, trigger="on_webhook", model_id=model.id, record_getter=record_getter, _actions={
|
||||
"state": "object_write",
|
||||
"update_field_id": self.env["ir.model.fields"]._get(model.model, "another_field").id,
|
||||
"update_path": "another_field",
|
||||
"value": "written"
|
||||
})
|
||||
|
||||
|
||||
@@ -87,20 +87,21 @@ class BaseAutomationTestUi(HttpCase):
|
||||
('model_id', '=', project_model.id),
|
||||
('name', '=', 'stage_id'),
|
||||
])
|
||||
self.env['test_base_automation.stage'].create({'name': 'Stage value'})
|
||||
test_stage = self.env['test_base_automation.stage'].create({'name': 'Stage value'})
|
||||
|
||||
automation = self.env["base.automation"].create({
|
||||
"name": "Test Stage",
|
||||
"trigger": "on_stage_set",
|
||||
"model_id": project_model.id,
|
||||
"trigger_field_ids": [stage_field.id],
|
||||
"trg_field_ref": test_stage,
|
||||
})
|
||||
|
||||
action = {
|
||||
"name": "Set Active To False",
|
||||
"base_automation_id": automation.id,
|
||||
"state": "object_write",
|
||||
"update_field_id": self.env.ref("base.field_res_partner__active").id,
|
||||
"update_path": "user_ids.active",
|
||||
"value": False,
|
||||
"model_id": project_model.id
|
||||
}
|
||||
@@ -162,7 +163,7 @@ class BaseAutomationTestUi(HttpCase):
|
||||
})
|
||||
|
||||
action = {
|
||||
"name": "Create User with name NameX",
|
||||
"name": "This name should not survive :)",
|
||||
"base_automation_id": automation.id,
|
||||
"state": "object_create",
|
||||
"value": "NameX",
|
||||
@@ -192,7 +193,7 @@ class BaseAutomationTestUi(HttpCase):
|
||||
"name": "Set Active To False",
|
||||
"base_automation_id": automation.id,
|
||||
"state": "object_write",
|
||||
"update_field_id": self.env.ref("base.field_res_partner__active").id,
|
||||
"update_path": "active",
|
||||
"value": False,
|
||||
"model_id": model.id,
|
||||
}
|
||||
@@ -214,11 +215,11 @@ class BaseAutomationTestUi(HttpCase):
|
||||
}
|
||||
)
|
||||
action = {
|
||||
"name": "Set Active To False",
|
||||
"name": "Update Active",
|
||||
"base_automation_id": automation.id,
|
||||
"state": "object_write",
|
||||
"update_field_id": self.env.ref("base.field_res_partner__active").id,
|
||||
"value": False,
|
||||
"update_path": "active",
|
||||
"update_boolean_value": "false",
|
||||
"model_id": model.id,
|
||||
}
|
||||
automation.write(
|
||||
@@ -226,7 +227,7 @@ class BaseAutomationTestUi(HttpCase):
|
||||
)
|
||||
self.assertEqual(
|
||||
automation.action_server_ids.mapped("name"),
|
||||
["Set Active To False 0", "Set Active To False 1", "Set Active To False 2"],
|
||||
["Update Active 0", "Update Active 1", "Update Active 2"],
|
||||
)
|
||||
|
||||
onchange_link_passes = 0
|
||||
@@ -240,10 +241,10 @@ class BaseAutomationTestUi(HttpCase):
|
||||
default_keys = {k: v for k, v in self_model._context.items() if k.startswith("default_")}
|
||||
self.assertEqual(
|
||||
default_keys,
|
||||
{"default_model_id": model.id, "default_state": False, "default_usage": "base_automation"},
|
||||
{"default_model_id": model.id, "default_usage": "base_automation"},
|
||||
)
|
||||
if onchange_link_passes == 2:
|
||||
self.assertEqual(res["value"]["name"], "Update False")
|
||||
self.assertFalse(res["value"], "No change should be triggered here")
|
||||
if onchange_link_passes == 3:
|
||||
self.assertEqual(res["value"]["name"], "Add followers: ")
|
||||
|
||||
@@ -261,7 +262,7 @@ class BaseAutomationTestUi(HttpCase):
|
||||
self.assertEqual(onchange_link_passes, 3)
|
||||
self.assertEqual(
|
||||
automation.action_server_ids.mapped("name"),
|
||||
["Set Active To False 2", "Set Active To False 0", "Set Active To False 1"],
|
||||
["Update Active 2", "Update Active 0", "Update Active 1"],
|
||||
)
|
||||
|
||||
def test_form_view_model_id(self):
|
||||
|
||||
Reference in New Issue
Block a user