diff options
| author | Laurent Mignon (ACSONE) <laurent.mignon@acsone.eu> | 2019-01-25 10:30:59 +0000 |
|---|---|---|
| committer | Laurent Mignon (ACSONE) <laurent.mignon@acsone.eu> | 2019-02-26 08:32:50 +0000 |
| commit | 28f33dc1507ee2428029efdbcb86a86f0aef5136 (patch) | |
| tree | b4c3ceb129f716e36bf78864ed65fdc3515cd56b /addons | |
| parent | 1c5c762f3cd6329ad56149616f836b39efe68148 (diff) | |
[IMP] stock: performance on _compute_product_availability
Improve performance (*3) on _compute_product_availability
`mapped` makes use of orm prefetch, which is inefficient in this use
case when facing high volume.
closes odoo/odoo#30545
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/stock/models/stock_move.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 43a51a03831..9ffc2d0df88 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -193,8 +193,8 @@ class StockMove(models.Model): if self.state == 'done': self.availability = self.product_qty else: - quants = self.env['stock.quant'].search([('location_id', 'child_of', self.location_id.id), ('product_id', '=', self.product_id.id), ('reservation_id', '=', False)]) - self.availability = min(self.product_qty, sum(quants.mapped('qty'))) + qty_tot = self.env['stock.quant'].read_group([('location_id', 'child_of', self.location_id.id), ('product_id', '=', self.product_id.id), ('reservation_id', '=', False)], ['qty'], [])[0] + self.availability = min(self.product_qty, qty_tot['qty'] or 0) @api.multi def _compute_string_qty_information(self): |
