8000 [saas-19.3+/20.0] web: a new line of an editable list gets the default values of the previous one (RPC cache) · Issue #300906 · odoo/odoo · GitHub
[go: up one dir, main page]

Skip to content

[saas-19.3+/20.0] web: a new line of an editable list gets the default values of the previous one (RPC cache) #300906

Description

@parabol123654

Odoo Version

  • 18.0
  • 19.0
  • 20.0
  • Other (specify)

saas-19.3, saas-19.4, 20.0 and master. 19.0 and saas-19.2 are not affected.

Steps to Reproduce

  1. Take an editable list view (<list editable="top|bottom">) opened from an action (the RPC cache is enabled by default), on a model with a default value that changes over time: e.g. a field default=fields.Date.context_today or fields.Datetime.now, or a default computed from existing records (next number, search_count() + 1).
  2. Click New: the new line gets the right default values. Save or discard it.
  3. Change what the default depends on (next day, create a record, ...) and click New again.

Current behavior: the new line shows the default values of the previous new line. The browser sends the onchange and the server answers with the new values, but they are not applied to the line. As the RPC cache is persistent (IndexedDB), the values can even come from a previous session.

Expected behavior: each new line gets the values of its own onchange, as in 19.0. Form views and kanban quick create are not affected.

Cause: 2adfe3e "[IMP] web: enable inline creation in offline list views" (#257491) passes RPC cache params from DynamicRecordList._addNewRecord to _loadNewRecord (addons/web/static/src/model/relational_model/dynamic_record_list.js, cache: this.model._getCacheParams(...)). Online, noCache is false in RelationalModel._loadNewRecord for a new record (config.resId is false), so the cached result of the previous onchange is returned at once; and the cache callback that should refresh the record returns early (currentResId is undefined / root.id !== this.root.id, the "root" being the new row), so the fresh result is dropped.

Hoot test reproducing it (web/static/tests/views/list/list_view.test.js), fails on 20.0 with Expected: "2", Received: "1":

test.tags("desktop");
test(`editable list: each new line gets the result of its own onchange`, async () => {
    let onchangeCount = 0;
    onRpc("onchange", ({ parent }) => {
        const result = parent();
        result.value.int_field = ++onchangeCount;
        return result;
    });
    await mountView({
        resModel: "foo",
        type: "list",
        arch: `<list editable="bottom"><field name="foo"/><field name="int_field"/></list>`,
    });

    await contains(`.o_list_button_add`).click();
    expect(`.o_selected_row [name=int_field] input`).toHaveValue("1");
    await contains(`.o_list_button_discard`).click();

    await contains(`.o_list_button_add`).click();
    expect(onchangeCount).toBe(2); // the second onchange is sent...
    expect(`.o_selected_row [name=int_field] input`).toHaveValue("2"); // ...but its result is not used
});

A possible fix is to use the cached onchange only when offline (the online result is still stored in the cache for offline use), or to re-apply the fresh onchange values to the new row in the cache callback, as the form view does. With the first option, the @web/views/list/list_view suite passes, offline tests included.

Log Output

No traceback: wrong default values on the new line.

Support Ticket

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0