diff --git a/addons/contacts/__manifest__.py b/addons/contacts/__manifest__.py index c783ef17c72..0a910c80538 100644 --- a/addons/contacts/__manifest__.py +++ b/addons/contacts/__manifest__.py @@ -17,4 +17,9 @@ You can track your vendors, customers and other contacts. ], 'application': True, 'license': 'LGPL-3', + 'assets': { + 'web.assets_tests': [ + 'contacts/static/tests/tours/**/*', + ], + } } diff --git a/addons/contacts/static/tests/tours/debug_menu_set_defaults.js b/addons/contacts/static/tests/tours/debug_menu_set_defaults.js new file mode 100644 index 00000000000..54fec23d36b --- /dev/null +++ b/addons/contacts/static/tests/tours/debug_menu_set_defaults.js @@ -0,0 +1,70 @@ +odoo.define('debug_menu_set_defaults.tour', function (require) { + "use strict"; + + var tour = require('web_tour.tour'); + + tour.register('debug_menu_set_defaults', { + test: true, + url: '/web?debug=1', + }, + [ + ...tour.stepUtils.goToAppSteps('contacts.menu_contacts', "Open the contacts menu"), + { + content: "Create a new contact", + trigger: '.o-kanban-button-new', + }, + { + content: "Check that Company is checked by default, and not Individual", + trigger: '.o_field_widget[name="company_type"] input[data-value="company"]:checked', + run: function () {}, + }, + { + content: "Select the individual radio button", + trigger: '.o_field_widget[name="company_type"] input[data-value="person"]', + }, + { + content: "Open the debug menu", + trigger: '.o_debug_manager button', + }, + { + content: "Click the Set Defaults menu", + trigger: '.o_debug_manager .dropdown-item:contains(Set Defaults)', + }, + { + content: "Choose Company Type = Individual", + trigger: '#formview_default_fields', + run: function () { + const element_field = document.querySelector('select#formview_default_fields'); + element_field.value = 'company_type'; + element_field.dispatchEvent(new Event("change")); + }, + }, + { + content: "Save the new default", + trigger: 'footer button:contains(Save default)', + }, + { + content: "Discard the contact creation", + trigger: 'button.o_form_button_cancel', + }, + { + trigger: '.o-kanban-button-new', + }, + { + content: "Check that Individual is checked instead of Company", + trigger: '.o_field_widget[name="company_type"] input[data-value="person"]:checked', + run: function () {}, + }, + { + content: "Discard the contact creation", + trigger: 'button.o_form_button_cancel', + }, + { + content: "Wait for discard", + trigger: '.o_control_panel .o-kanban-button-new', + run() {}, + }, + ] + ); + +}); diff --git a/addons/contacts/tests/__init__.py b/addons/contacts/tests/__init__.py new file mode 100644 index 00000000000..2235dde4188 --- /dev/null +++ b/addons/contacts/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import test_ui diff --git a/addons/contacts/tests/test_ui.py b/addons/contacts/tests/test_ui.py new file mode 100644 index 00000000000..a3fb1c5845f --- /dev/null +++ b/addons/contacts/tests/test_ui.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from ast import literal_eval + +import odoo.tests + + +@odoo.tests.tagged('-at_install', 'post_install') +class TestUi(odoo.tests.HttpCase): + def test_set_defaults(self): + """Tests the "Set Defaults" feature of the debug menu on the res.partner form. + + Set a user-defined default on the computed (with inverse) field `company_type` + so the default "Company" becomes "Indivdual". + """ + # Ensure the requirements of the test: + # The tour assumptions are currently that `res.partner.company_type` is a non-readonly computed field + # currently defaulting to "company" in the `res.partner` form. + # If the below assertions change in the future, the tour needs to be adapted, as well as these assertions. + company_type_field = self.env['res.partner']._fields['company_type'] + self.assertTrue(company_type_field.compute) + self.assertFalse(company_type_field.readonly) + action_context = literal_eval(self.env.ref('contacts.action_contacts').context) + self.assertTrue(action_context.get('default_is_company')) + # Make sure there is currently no user-defined default on res.partner.company_type + # so "Company" is the default value for the field res.partner.company_type + self.env['ir.default'].search([ + ('field_id', '=', self.env.ref('base.field_res_partner__company_type').id), + ]).unlink() + self.assertEqual(self.env['res.partner'].with_context(**action_context).new().company_type, "company") + + self.start_tour("/web", 'debug_menu_set_defaults', login="admin") diff --git a/addons/web/static/src/legacy/debug_manager.js b/addons/web/static/src/legacy/debug_manager.js index 2d7a2f1c3a1..8cf180a526a 100644 --- a/addons/web/static/src/legacy/debug_manager.js +++ b/addons/web/static/src/legacy/debug_manager.js @@ -133,9 +133,7 @@ class SetDefaultDialog extends Component { fieldInfo.type === "one2many" || fieldInfo.type === "many2many" || fieldInfo.type === "binary" || - fieldsInfo[fieldName].options.isPassword || - fieldInfo.depends === undefined || - fieldInfo.depends.length !== 0 + fieldsInfo[fieldName].options.isPassword ) { return false; } diff --git a/addons/web/static/src/views/debug_items.js b/addons/web/static/src/views/debug_items.js index 5e16b4d5a82..bf2b5f0dd6b 100644 --- a/addons/web/static/src/views/debug_items.js +++ b/addons/web/static/src/views/debug_items.js @@ -236,9 +236,7 @@ class SetDefaultDialog extends Component { fieldInfo.type === "one2many" || fieldInfo.type === "many2many" || fieldInfo.type === "binary" || - this.fieldsInfo[fieldName].options.isPassword || - fieldInfo.depends === undefined || - fieldInfo.depends.length !== 0 + this.fieldsInfo[fieldName].options.isPassword ) { return false; } diff --git a/addons/web/static/tests/core/debug/debug_manager_tests.js b/addons/web/static/tests/core/debug/debug_manager_tests.js index 6fc658d97ff..21abe9bf608 100644 --- a/addons/web/static/tests/core/debug/debug_manager_tests.js +++ b/addons/web/static/tests/core/debug/debug_manager_tests.js @@ -536,9 +536,6 @@ QUnit.module("DebugMenu", (hooks) => { fields: {}, records: [{ id: 18 }], }; - serverData.models.partner.fields.m2o.depends = []; - serverData.models.partner.fields.foo.depends = []; - serverData.models.partner.fields.o2m.depends = []; serverData.models.partner.records = [{ id: 1, display_name: "p1", foo: "hello" }]; const mockRPC = async (route, args) => { @@ -585,7 +582,6 @@ QUnit.module("DebugMenu", (hooks) => { fields: {}, records: [{ id: 18 }], }; - serverData.models.partner.fields.foo.depends = []; serverData.models.partner.records = [{ id: 1, display_name: "p1", foo: "hello" }]; const mockRPC = async (route, args) => { @@ -635,7 +631,6 @@ QUnit.module("DebugMenu", (hooks) => { fields: {}, records: [{ id: 18 }], }; - serverData.models.partner.fields.foo.depends = []; serverData.models.partner.records = [{ id: 1, display_name: "p1", foo: "hello" }]; const mockRPC = async (route, args) => {