[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) <aab@odoo.com>
This commit is contained in:
Simon Genin (ges)
2024-01-26 21:07:53 +00:00
parent 6ab7a11e3a
commit bf65cb53d0
2 changed files with 22 additions and 1 deletions
@@ -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))))
@@ -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 */ `
<form>
<field name="datetime" widget="daterange" options="{'end_date_field': 'datetime_end', 'always_range': 'true'}" />
<field name="datetime" widget="daterange" options="{'end_date_field': 'datetime_end', 'always_range': 'true'}" readonly="true" />
</form>`,
});
assert.containsOnce(target, ".fa-long-arrow-right");
}
);
});