Skip to content
Snippets Groups Projects
Commit 027d6b11 authored by Tiffany Chang (tic)'s avatar Tiffany Chang (tic)
Browse files

[FIX] various: enforce consistent listview ordering

During the listview OWL refactoring, it was refactored to have a default
orderby of any field with the `handle` in the view (if no others are
defined):

https://github.com/odoo/odoo/blob/adde4917ccbceb7eb56e8a0326d7aef3ad7e0298/addons/web/static/src/views/list/list_arch_parser.js#L217-L218



Unfortunately this field is often the `sequence` field which
is sometimes created without a `default` field value and can therefore
sometimes be stored in the database as `NULL`. This made it so listviews
that can have `NULL` sequence values will have an inconsistent ordering
when the view is opened, even if the sequence appears to be `0` from
within Odoo.

Reason why this is happening:
  Previously, since there was no default orderby in the listview, so the
  `web_search_read` was called without an orderby parameter and would
  default to the model's `_order` value.

Why this is a problem:
  in some cases this can lead to confusing behavior
  where the displayed listview order is NOT the order that the records
  will be read in some flows. E.g. multiple BoMs for the same product
  with no seq set for any of them. The BoM closest to the beginning of
  the list (when no ordering set) is the one expected to be selected by
  default when starting a new MO for that product (and the ordering of
  the BoM field dropdown list should also match the list ordering), but
  it may not since the ordering in the BoM list view is not consistent.
  More serious example is the ordering of BoM operation steps being
  inconsistently shown since it may not match the step order in the WO.

Solution:
  In master the ORM will be updated so the order will be determinstic in
  this case.

  In stable we will manually update the relevant listviews with
  a `default_order` that follows the pre-OWL `_order` ordering. This
  applies to listviews for models that:
  - have a sequence field with NO default value
  - have a listview for that model that allows for creating records
    without the sequence being set (i.e. seq is NOT required + is created
    via a form view that DOES NOT have the field in it. Note that this
    means many2many/one2many fields within another records are not
    included since "Add a Line" usually acts like the "create" button
    within a list view)
  - previously had a deterministic ordering related to the sequence (e.g.
    `order = "sequence, id"`, but NOT `order = "sequence"`)

Other notes:
  - For existing dbs, this fix will not be auto-applied and will require
    a manual update
  - Some cases may have been missed since it's a manual process to check
    whether the use cases of applicable models have a view where the
    ordering is inconsistent (e.g. does "create" open a form or not)

closes odoo/odoo#110406

Related: odoo/enterprise#36043
Signed-off-by: default avatarArnold Moyaux (arm) <arm@odoo.com>
parent 8e78efa3
Branches
Tags
No related merge requests found
......@@ -272,7 +272,7 @@
<field name="name">fleet.vehicle.model.category.view.tree</field>
<field name="model">fleet.vehicle.model.category</field>
<field name="arch" type="xml">
<tree string="Model Category" editable="bottom">
<tree string="Model Category" editable="bottom" default_order="sequence, id">
<field name="sequence" widget="handle"/>
<field name="name"/>
</tree>
......
......@@ -157,7 +157,7 @@
<field name="name">mrp.bom.tree</field>
<field name="model">mrp.bom</field>
<field name="arch" type="xml">
<tree string="Bill of Materials" sample="1">
<tree string="Bill of Materials" sample="1" default_order="sequence, id">
<field name="active" invisible="1"/>
<field name="sequence" widget="handle"/>
<field name="product_tmpl_id"/>
......
......@@ -4,7 +4,7 @@
<field name="name">product.attribute.tree</field>
<field name="model">product.attribute</field>
<field name="arch" type="xml">
<tree string="Variant Values">
<tree string="Variant Values" default_order="sequence, id">
<field name="sequence" widget="handle"/>
<field name="name"/>
<field name="display_type"/>
......
......@@ -59,7 +59,7 @@
<field name="name">Operation types</field>
<field name="model">stock.picking.type</field>
<field name="arch" type="xml">
<tree string="Operation Types">
<tree string="Operation Types" default_order="sequence, id">
<field name="sequence" widget="handle"/>
<field name="name"/>
<field name="active" invisible="1"/>
......
......@@ -148,7 +148,7 @@
<field name="name">event.sponsor.view.tree</field>
<field name="model">event.sponsor</field>
<field name="arch" type="xml">
<tree multi_edit="1" sample="1">
<tree multi_edit="1" sample="1" default_order="sequence, sponsor_type_id">
<field name="sequence" widget="handle"/>
<field name="partner_id" readonly="1"/>
<field name="name"/>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment