From bf65cb53d077c9ab1b1839e2e306fc1ebdc02acd Mon Sep 17 00:00:00 2001 From: "Simon Genin (ges)" Date: Thu, 18 Jan 2024 12:05:25 +0100 Subject: [PATCH] [FIX] web: datetime range with always range when empty and readonly Recently, a new option 'always_range' has been added to the datetime field (task 3628069, commit bc98aad). This option forces the display of the arrow between the two dates from the start. Before that, you would add a first date, click a button to add a second date and then only would the arrow appear. The oversight here is when the field is empty AND readonly. In that case, you have an visible arrow next to the label but you can't do anything with the field anyway. So better not to show it. This commit makes sure to not display the arrow in this case. task 3690523 closes odoo/odoo#149912 Signed-off-by: Aaron Bohy (aab) --- .../views/fields/datetime/datetime_field.js | 5 ++++- .../views/fields/daterange_field_tests.js | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/views/fields/datetime/datetime_field.js b/addons/web/static/src/views/fields/datetime/datetime_field.js index 42a2b470614..612f42102a3 100644 --- a/addons/web/static/src/views/fields/datetime/datetime_field.js +++ b/addons/web/static/src/views/fields/datetime/datetime_field.js @@ -221,7 +221,10 @@ export class DateTimeField extends Component { */ shouldShowSeparator() { return ( - this.props.alwaysRange || + (this.props.alwaysRange && + (this.props.readonly + ? !this.isEmpty(this.startDateField) || !this.isEmpty(this.endDateField) + : true)) || (this.state.range && (this.props.required || (!this.isEmpty(this.startDateField) && !this.isEmpty(this.endDateField)))) diff --git a/addons/web/static/tests/views/fields/daterange_field_tests.js b/addons/web/static/tests/views/fields/daterange_field_tests.js index 98964c46b12..7b5cd4f1b59 100644 --- a/addons/web/static/tests/views/fields/daterange_field_tests.js +++ b/addons/web/static/tests/views/fields/daterange_field_tests.js @@ -1219,4 +1219,22 @@ QUnit.module("Fields", (hooks) => { assert.containsNone(target, ".o_add_date"); } ); + + QUnit.test( + "there is no arrow between the dates with option always_range if nothing is set and it is readonly", + async (assert) => { + await makeView({ + type: "form", + resModel: "partner", + serverData, + arch: /* xml */ ` +
+ + + `, + }); + + assert.containsOnce(target, ".fa-long-arrow-right"); + } + ); });