OCA/server-ux

date_range module causes error when selecting a json type field

Closed this issue · 6 comments

Module

date_range

Describe the bug

If a json type field (e.g. analytics) is present in the model, when selecting it from the "Add Custom Filter" drop down in the filter
search, an error is produced as below

TypeError: this.OPERATORS[FIELD_TYPES[type]] is undefined
    setDefaultValue@http://oca-server-ux-16-0-e150a9dd5622.runboat.odoo-community.org/web/assets/437-f62b0ae/web.assets_backend.min.js:13852:134
    setDefaultValue (patch date_range.CustomFilterItem)@http://oca-server-ux-16-0-e150a9dd5622.runboat.odoo-community.org/web/assets/437-f62b0ae/web.assets_backend.min.js:1657:22
    onFieldSelect@http://oca-server-ux-16-0-e150a9dd5622.runboat.odoo-community.org/web/assets/437-f62b0ae/web.assets_backend.min.js:1851:103
    slot2/hdlr1<@http://oca-server-ux-16-0-e150a9dd5622.runboat.odoo-community.org/web/assets/436-6f15138/web.assets_common.min.js line 2056 > Function:52:28
    mainEventHandler@http://oca-server-ux-16-0-e150a9dd5622.runboat.odoo-community.org/web/assets/436-6f15138/web.assets_common.min.js:2106:77
    listener@http://oca-server-ux-16-0-e150a9dd5622.runboat.odoo-community.org/web/assets/436-6f15138/web.assets_common.min.js:1282:15

To Reproduce

Affected versions: v16

Steps to reproduce the behavior:

  1. In runboat, go to the view "Journal Items" in Invoicing->Accounting->Journal Items
  2. Select the "Filters" dropdown, "Add Custom Filter"
  3. Select the Analytic field in the field selection.

Expected behavior
Can select the Analytic (or any json field) with no error.

Additional context
I believe it is an issue with using the javascript constant "FIELD_TYPES" from web.searchUtils, which appears to be a legacy javascript function which does not include the latest field types in the const FIELD_TYPES declaration.

From web.searchUtils

const FIELD_TYPES = {
        binary: 'binary',
        boolean: 'boolean',
        char: 'char',
        date: 'date',
        datetime: 'datetime',
        float: 'number',
        id: 'id',
        integer: 'number',
        html: 'char',
        many2many: 'char',
        many2one: 'char',
        monetary: 'number',
        one2many: 'char',
        text: 'char',
        selection: 'selection',
    };

But from custom_filter_item.js

const FIELD_TYPES = {
    binary: "binary",
    boolean: "boolean",
    char: "char",
    date: "date",
    datetime: "datetime",
    float: "number",
    id: "id",
    integer: "number",
    json: "json",
    html: "char",
    many2many: "char",
    many2one: "char",
    monetary: "number",
    one2many: "char",
    text: "char",
    selection: "selection",
};

Currently the date_range.esm.js file is using the legacy declaration of FIELD_TYPES.

Are you using #723 ?

Yes, this is repeatable in the runboat. I believe the breaking commit is #717 as FIELD_TYPES from web.searchUtils does not contain a type json.

If you try on standard runbot without the module, is it working? @hugosantosred FYI

Yes, on all runboats without date_range installed it works. As soon as you install date_range it causes the error.

If analytic field is the first field alphabetically (therefore the first field is a json field), then the filters dropdown will not load at all. If it is not, then the filters will load and the error will not occur until you select that json field directly.

It should be fixed in #726, @michaelslade54 Could you confirm that is working in the runboat from that PR?

I can confirm issue is fixed. Thanks very much.