diff --git a/base_search_custom_field_filter/tests/test_filter.py b/base_search_custom_field_filter/tests/test_filter.py index d4d008bdcf..e2ccfc53b1 100644 --- a/base_search_custom_field_filter/tests/test_filter.py +++ b/base_search_custom_field_filter/tests/test_filter.py @@ -30,3 +30,41 @@ def test_1(self): """ ) ) + + def test_invalid_expression(self): + filter_form = Form(self.env["ir.ui.custom.field.filter"]) + filter_form.model_id = self.env.ref("base.model_res_partner") + filter_form.name = "Invalid Expression" + with self.assertRaises(exceptions.ValidationError): + filter_form.expression = "invalid_expression" + filter_form.save() + + def test_valid_expression(self): + filter_form = Form(self.env["ir.ui.custom.field.filter"]) + filter_form.model_id = self.env.ref("base.model_res_partner") + filter_form.name = "Valid Expression" + filter_form.expression = "valid_expression" + filter_form.save() + arch = self.env["res.partner"].get_view(False, "search")["arch"] + search = etree.fromstring(arch) + self.assertTrue( + search.xpath( + """ + //search + /field[@name="valid_expression"] + """ + ) + ) + + def test_duplicate_filter(self): + filter_form = Form(self.env["ir.ui.custom.field.filter"]) + filter_form.model_id = self.env.ref("base.model_res_partner") + filter_form.name = "Duplicate Filter" + filter_form.expression = "duplicate_expression" + filter_form.save() + with self.assertRaises(exceptions.ValidationError): + duplicate_filter_form = Form(self.env["ir.ui.custom.field.filter"]) + duplicate_filter_form.model_id = self.env.ref("base.model_res_partner") + duplicate_filter_form.name = "Duplicate Filter" + duplicate_filter_form.expression = "duplicate_expression" + duplicate_filter_form.save() diff --git a/base_search_custom_field_filter/views/ir_ui_custom_field_filter_views.xml b/base_search_custom_field_filter/views/ir_ui_custom_field_filter_views.xml index 6da2b1b06f..99966248eb 100644 --- a/base_search_custom_field_filter/views/ir_ui_custom_field_filter_views.xml +++ b/base_search_custom_field_filter/views/ir_ui_custom_field_filter_views.xml @@ -5,13 +5,13 @@ ir.ui.custom.field.filter - + - +