odoo/odoo#132585

Created by Walravens Mathieu (wama)
Merged at 8dcad6e4259342ae6838e4698586b94e8577c4cf

Statuses:

label
odoo-dev:14.0-delivery-compute-packages-read_group-wama
head
bd6a04573576758781f68828a0af4b519c2cb4b6
merged
3 years ago by Logistics, Arnold Moyaux (arm)
odoo/odoo
14.0 #132585
15.0 #134556
saas-15.2 #134575
16.0 #134581
saas-16.1 #134593
saas-16.2 #134600
saas-16.3 #134607
17.0
18.0
saas-18.2
saas-18.3
saas-18.4
19.0
saas-19.1
saas-19.2
saas-19.3
master

[FIX] delivery: speed up _compute_packages using read_group

Before this commit:

Packages were computed using a for loop, skipping any picking without any packages.

After this commit:

Packages are computed using a read_group, speeding up the computed method for large pickings with hundreds of stock move lines.

Benchmark

This benchmark comes from a 16.3 database with the new _read_group, but the results should be similar in 14.0.
| Move lines | Before | After |
| ---------: | -------: | ------: |
| 10 | 3.55ms | 3.93ms |
| 20 | 3.12ms | 5.99ms |
| 476 | 17.61ms | 6.94ms |
| 1000 | 145.59ms | 8.16ms |
| 2000 | 301.20ms | 10.23ms |
| 6000 | 0.93s | 20.55ms |
| 15000 | 2.39s | 22.29ms |
| 30000 | 4.82s | 40.94ms |
| 60000 | 10.29s | 62.76ms |

Note: All stock move lines have the same result_package_id. Further improvement could be done with ARRAY_AGG(DISTINCT ...), but it's not possible to do with read_group.

opw-3461706