[UPD] web_m2x_options_manager: Add option to prevent Create/Edit wizard to pop up

pull/2081/head
Maksym Yankin 2021-10-18 13:12:56 +03:00 committed by Germana
parent ffb66eb0f8
commit c1677bbe84
4 changed files with 47 additions and 0 deletions

View File

@ -25,6 +25,11 @@ msgstr ""
msgid "Add"
msgstr ""
#. module: web_m2x_options_manager
#: model:ir.model.fields,field_description:web_m2x_options_manager.field_m2x_create_edit_option__option_create_edit_wizard
msgid "Create & Edit Wizard"
msgstr ""
#. module: web_m2x_options_manager
#: model:ir.model.fields,field_description:web_m2x_options_manager.field_m2x_create_edit_option__option_create_edit
msgid "Create & Edit Option"
@ -50,6 +55,13 @@ msgstr ""
msgid "Created on"
msgstr ""
#. module: web_m2x_options_manager
#: model:ir.model.fields,help:web_m2x_options_manager.field_m2x_create_edit_option__option_create_edit_wizard
msgid ""
"Defines behaviour for 'Create & Edit' Wizard\n"
"Set to False to prevent 'Create & Edit' Wizard to pop up"
msgstr ""
#. module: web_m2x_options_manager
#: model:ir.model.fields,help:web_m2x_options_manager.field_m2x_create_edit_option__option_create_edit
msgid ""

View File

@ -77,6 +77,13 @@ class M2xCreateEditOption(models.Model):
string="Create & Edit Option",
)
option_create_edit_wizard = fields.Boolean(
default=True,
help="Defines behaviour for 'Create & Edit' Wizard\n"
"Set to False to prevent 'Create & Edit' Wizard to pop up",
string="Create & Edit Wizard",
)
_sql_constraints = [
(
"model_field_uniqueness",
@ -142,6 +149,9 @@ class M2xCreateEditOption(models.Model):
if mode == "force" or k not in options:
options[k] = val == "true"
node.set("options", str(options))
if not self.option_create_edit_wizard:
node.set("can_create", "false")
node.set("can_write", "false")
@api.model
def get(self, model_name, field_name):

View File

@ -29,6 +29,7 @@ class TestM2xCreateEditOption(SavepointCase):
"model_id": self.res_partner_model.id,
"option_create": "set_true",
"option_create_edit": "set_true",
"option_create_edit_wizard": True,
}
)
self.categories_opt = self.env["m2x.create.edit.option"].create(
@ -37,6 +38,7 @@ class TestM2xCreateEditOption(SavepointCase):
"model_id": self.res_partner_model.id,
"option_create": "set_true",
"option_create_edit": "set_true",
"option_create_edit_wizard": True,
}
)
self.company_opt = self.env["m2x.create.edit.option"].create(
@ -45,6 +47,7 @@ class TestM2xCreateEditOption(SavepointCase):
"model_id": self.res_users_model.id,
"option_create": "force_true",
"option_create_edit": "set_true",
"option_create_edit_wizard": False,
}
)
@ -82,11 +85,25 @@ class TestM2xCreateEditOption(SavepointCase):
safe_eval(title_node.attrib.get("options"), nocopy=True),
{"create": True, "create_edit": True},
)
self.assertEqual(
(
title_node.attrib.get("can_create"),
title_node.attrib.get("can_write"),
),
("true", "true"),
)
categ_node = form_doc.xpath("//field[@name='category_id']")[0]
self.assertEqual(
safe_eval(categ_node.attrib.get("options"), nocopy=True),
{"create": False, "create_edit": True},
)
self.assertEqual(
(
categ_node.attrib.get("can_create"),
categ_node.attrib.get("can_write"),
),
("true", "true"),
)
# Check fields on res.users tree view (contained in ``user_ids`` field)
tree_arch = res["fields"]["user_ids"]["views"]["tree"]["arch"]
@ -96,6 +113,13 @@ class TestM2xCreateEditOption(SavepointCase):
safe_eval(company_node.attrib.get("options"), nocopy=True),
{"create": True, "create_edit": True},
)
self.assertEqual(
(
company_node.attrib.get("can_create"),
company_node.attrib.get("can_write"),
),
("false", "false"),
)
# Update options, check that node has been updated too
self.title_opt.option_create_edit = "force_false"

View File

@ -27,6 +27,7 @@
/>
<field name="option_create" />
<field name="option_create_edit" />
<field name="option_create_edit_wizard" />
</tree>
</field>
</page>