Petar Najman 6a89f5b4f9 [IMP] core: add support for NULLS {FIRST | LAST} in ORDER BY clauses
Recent Odoo versions require modern postgres (e.g. use of jsonb), the
`NULLS {FIRST | LAST}` clause was added in 8.3 so should be well
supported.

While Odoo's use of nulls is not always consistent, the NULLS ordering
clauses can be quite useful especially when sorting `DESC`: `NULLS
FIRST` and `NULLS LAST` are literal positions so they put nulls at
that location regardless of sort order whereas the default Postgres
ordering is to consider nulls larger than every other value so they
appear first when sorting DESC, which is often undesirable (putting
nulls first when sorting ASC can also be useful to fill records).

Update `_generate_order_by_inner` to correctly process `NULLS` clauses:

- Use `regex_order` to ensure we parse orderings correctly and
  consistently, also update `regex_order` to use named groups to make
  the relevant bits clearer (and VERBOSE for readability).
- Given `a_id DESC` and `_fields[a_id].relation._order = 'xxx NULLS
  LAST'`, reversing the clause should order by `xxx DESC NULLS FIRST`
  to correctly flip the original as `NULLS` clauses are not relative
  to the sorting order (they put the `NULL`-valued records at the
  specified location regardless). Therefore apply `reverse_direction`
  to `NULLS`.
- Manually expand `NULLS` clauses on m2o fields: propagating the
  clause through the join would yield unexpected and illogical results
  when mixing NULL m2o fields and non-NULL m2o fields with NULL
  `_order` fields (as they would get mixed rather than clearly layered
  / separated).

  However because SQL booleans are ordered the usual way (`true >
  false`) the `NULLS` clause is fundamentally equivalent to sorting on
  the field being NULL (if `NULLS LAST`) or not (if `NULLS FIRST`). So
  we can prepend the expanded m2o's ordering with such a clause to get
  the correct behavior.

Replaces #116464
Supersedes #116664

closes odoo/odoo#117439

Signed-off-by: Raphael Collet <rco@odoo.com>
Co-authored-by: Petar Najman <petar.najman@modoolar.com>
2023-04-06 14:58:49 +02:00
…
…
…
…
…
2023-01-03 13:16:02 +01:00

Build Status Tech Doc Help Nightly Builds

Odoo

Odoo is a suite of web based open source business apps.

The main Odoo Apps include an Open Source CRM, Website Builder, eCommerce, Warehouse Management, Project Management, Billing & Accounting, Point of Sale, Human Resources, Marketing, Manufacturing, ...

Odoo Apps can be used as stand-alone applications, but they also integrate seamlessly so you get a full-featured Open Source ERP when you install several Apps.

Getting started with Odoo

For a standard installation please follow the Setup instructions from the documentation.

To learn the software, we recommend the Odoo eLearning, or Scale-up, the business game. Developers can start with the developer tutorials

S
Description
No description provided
Readme LGPL-3.0
3.4 GiB
Languages
Python 49.6%
JavaScript 47.8%
SCSS 2%
CSS 0.3%
HTML 0.2%