Skip to content

fix(aggregate_records): accept a bare measure in order on Odoo 19 - #73

Open
bitclicklabs wants to merge 2 commits into
erpipe-org:mainfrom
bitclicklabs:fix/aggregate-order-measure
Open

bitclicklabs wants to merge 2 commits into
erpipe-org:mainfrom
bitclicklabs:fix/aggregate-order-measure

Conversation

@bitclicklabs

Copy link
Copy Markdown

Summary

On Odoo 19, aggregate_records with an order on a summed field (for example
order="amount_untaxed desc" with measures=["amount_untaxed:sum"]) fails with
Order term 'amount_untaxed desc' is not a valid aggregate: formatted_read_group
wants measures in order as field:agg. A bare measure in order is now rewritten
to field:agg (normalize_group_order); group-by fields and explicit field:agg
terms are kept as written. The legacy read_group path (orderby) is unchanged.

Agents write the bare form naturally (it is what read_group accepted), so this
showed up in real use as a failed call followed by a wrong figure.

Coverage

  • Odoo versions tested: 19.0 (live, JSON-2); unit tests cover the legacy path
  • Transports tested: json2

Verification

uv run python -m ruff check .
uv run python -m mypy src
uv run python -m pytest tests/test_tool_helpers.py tests/test_server.py   # 333 passed

Live against Odoo 19: 1.3.2 fails on order="amount_untaxed desc"; this branch
returns the groups sorted by the sum.

The full suite on Windows has two failures unrelated to this change (a symlink
test and a task_queue timing test); they fail on main too.

Checklist

  • Updated README.md / docs/ when behavior changes (no documented behavior changes)
  • Updated CHANGELOG.md under ## Unreleased
  • No credentials, private database names, or production debug traces in diff or logs
  • Write-execution safety gates are unchanged (read-only tool)

Notes for reviewers

Only terms whose name matches a requested measure are rewritten; an order on a
measure that was not requested is left as is, so Odoo still reports it.

Odoo 19 formatted_read_group only accepts order terms that are a groupby field,
__count or an aggregate spec. Clients naturally write the measure field alone
("amount_untaxed desc"), which Odoo rejects with "Order term ... is not a valid
aggregate nor valid groupby". A bare field that is one of the requested
measures is now sent as "field:agg"; other terms are kept, and legacy
read_group keeps the order unchanged.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants