From 8d0a63f35519090a74fcefedf482fea5f6eedd97 Mon Sep 17 00:00:00 2001 From: "Guillaume (gdi)" Date: Tue, 22 Feb 2022 09:28:57 +0000 Subject: [PATCH] [FIX] website, website_hr_recruitment: give the priority to auto-fill This commit allows to give priority to auto-fill values and to values coming from a data-for when in addition to one of these values this same field has a default value. The form's test are also improved so that it checks for this desired behavior. task-2715201 X-original-commit: 7b23d3aacd22f87cb0c22ecd0478eba4a17b4bf3 Part-of: odoo/odoo#90103 --- .../static/src/snippets/s_website_form/000.js | 4 ++-- .../static/tests/tours/website_form_editor.js | 13 +++-------- .../tests/tours/website_hr_recruitment.js | 22 ++++++++++++++++++- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/addons/website/static/src/snippets/s_website_form/000.js b/addons/website/static/src/snippets/s_website_form/000.js index 25b30aff6ea..f98fbfd14a3 100644 --- a/addons/website/static/src/snippets/s_website_form/000.js +++ b/addons/website/static/src/snippets/s_website_form/000.js @@ -143,9 +143,9 @@ odoo.define('website.s_website_form', function (require) { for (const name of fieldNames) { const fieldEl = this.$target[0].querySelector(`[name="${name}"]`); let newValue; - if (!fieldEl.value && dataForValues && dataForValues[name]) { + if (dataForValues && dataForValues[name]) { newValue = dataForValues[name]; - } else if (!fieldEl.value && this.preFillValues[fieldEl.dataset.fillWith]) { + } else if (this.preFillValues[fieldEl.dataset.fillWith]) { newValue = this.preFillValues[fieldEl.dataset.fillWith]; } if (newValue) { diff --git a/addons/website/static/tests/tours/website_form_editor.js b/addons/website/static/tests/tours/website_form_editor.js index 1e905bf5daf..5159ed82f63 100644 --- a/addons/website/static/tests/tours/website_form_editor.js +++ b/addons/website/static/tests/tours/website_form_editor.js @@ -300,7 +300,7 @@ odoo.define('website.tour.form_editor', function (require) { trigger: '.s_website_form_send.btn.btn-sm.btn-secondary.rounded-circle', run: () => null, }, - // Add a default value. + // Add a default value to a auto-fillable field. { content: 'Select the name field', trigger: '.s_website_form_field:eq(0)', @@ -309,20 +309,13 @@ odoo.define('website.tour.form_editor', function (require) { trigger: 'we-input[data-attribute-name="value"] input', run: 'text John Smith', }, - // Save the page - { - trigger: 'body', - run: function () { - $('body').append('
'); - }, - }, { content: "Save the page", trigger: "button[data-action=save]", }, { - content: "Wait reloading...", - trigger: "html:not(:has(#completlyloaded)) div", + content: 'Verify value attribute and property', + trigger: '.s_website_form_field:eq(0) input[value="John Smith"]:propValue("Mitchell Admin")', }, // Check that if we edit again and save again the default value is not deleted. { diff --git a/addons/website_hr_recruitment/static/tests/tours/website_hr_recruitment.js b/addons/website_hr_recruitment/static/tests/tours/website_hr_recruitment.js index 7a0612ec394..e92dbf399c4 100644 --- a/addons/website_hr_recruitment/static/tests/tours/website_hr_recruitment.js +++ b/addons/website_hr_recruitment/static/tests/tours/website_hr_recruitment.js @@ -74,6 +74,14 @@ odoo.define('website_hr_recruitment.tour', function(require) { }, { content: 'Enter in edit mode', trigger: 'a[data-action="edit"]', + }, { + content: 'Add a fake default value for the job_id field', + trigger: 'button[data-action="save"]', + run: () => { + // It must be done in this way because the editor does not allow to + // put a default value on a field with type="hidden". + document.querySelector('input[name="job_id"]').value = 'FAKE_JOB_ID_DEFAULT_VAL'; + }, }, { content: 'Edit the form', trigger: 'input[type="file"]', @@ -100,11 +108,23 @@ odoo.define('website_hr_recruitment.tour', function(require) { content: 'Check that a job_id has been loaded', trigger: 'form', run: () => { - const selector = 'input[name="job_id"]:not([value=""])'; + const selector = + 'input[name="job_id"]:not([value=""]):not([value = "FAKE_JOB_ID_DEFAULT_VAL"])'; if (!document.querySelector(selector)) { console.error('The job_id field has a wrong value'); } } + }, { + content: 'Enter in edit mode', + trigger: 'a[data-action="edit"]', + }, { + content: 'Verify that the job_id field has kept its default value', + trigger: 'button[data-action="save"]', + run: () => { + if (!document.querySelector('input[name="job_id"][value="FAKE_JOB_ID_DEFAULT_VAL"]')) { + console.error('The job_id field has lost its default value'); + } + } }, ]);