[FIX] stock_landed_cost: improve performance read

Improve performance of SQL in  `_compute_allowed_picking_ids`.
This one can be costly for a simple read of the `allowed_picking_ids`.
Grouping the result to avoid useless big thoughtput and a
add a where clause on company_id to filter out useless row.

opw-2374405
odoo/odoo#64011

Forward-port-of: odoo/odoo#63742
X-original-commit: 209f421b7360a42ab43c09d9aacec6b53ad24917
This commit is contained in:
Rémy Voet (ryv)
2021-01-05 07:54:32 +00:00
parent 19383af210
commit 1f11d968e0
@@ -84,7 +84,8 @@ class StockLandedCost(models.Model):
self.env.cr.execute("""SELECT sm.picking_id, sm.company_id
FROM stock_move AS sm
INNER JOIN stock_valuation_layer AS svl ON svl.stock_move_id = sm.id
WHERE sm.picking_id IS NOT NULL""")
WHERE sm.picking_id IS NOT NULL AND sm.company_id IN %s
GROUP BY sm.picking_id, sm.company_id""", [tuple(self.company_id.ids)])
valued_picking_ids_per_company = defaultdict(list)
for res in self.env.cr.fetchall():
valued_picking_ids_per_company[res[1]].append(res[0])