On the PR https://github.com/odoo/odoo/pull/107558 some performance improvements were made when computing the weights.
Unfortunately, this caused some slowdown on other cases.
This PR keeps the read_group introduced on https://github.com/odoo/odoo/pull/107558 but reduces the number of 'get' by taking all the information needed only once before entering the for loop.
For comparison, these are the differences on _compute_bulk_weight when going to Inventory/Receipts:
| Before PR 107558 | After PR 107558 | After this PR
| ------------- | ------------- | ------------- |
| 550 ms | 10.30 s | 560ms |
And these when removing the filter by default (leading it to fetch heavier records):
| Before PR 107558 | After PR 107558 | After this PR
| ------------- | ------------- | ------------- |
| 2.27 s | 24.48 s | 1.89 s |
OPW-3107540
closesodoo/odoo#109481
X-original-commit: 4bbf782505e72761c7c77abfe4fbd53e151e5bf0
Signed-off-by: William Henrotin (whe) <whe@odoo.com>