[FIX] stock_sale: imp lot._compute_sale_order_ids perf.
Improve _compute_sale_order_ids performances by saving stock.move.line search results to defaultdict before going through records in self. closes odoo/odoo#72019 X-original-commit: d908351fbaec8900244a82ec3a2d678e279535cb Signed-off-by: William Henrotin <Whenrow@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from collections import defaultdict
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
|
||||
@@ -155,14 +157,13 @@ class ProductionLot(models.Model):
|
||||
|
||||
@api.depends('name')
|
||||
def _compute_sale_order_ids(self):
|
||||
sale_orders = defaultdict(lambda: self.env['sale.order'])
|
||||
for move_line in self.env['stock.move.line'].search([('lot_id', 'in', self.ids), ('state', '=', 'done')]):
|
||||
move = move_line.move_id
|
||||
if move.picking_id.location_dest_id.usage == 'customer' and move.sale_line_id.order_id:
|
||||
sale_orders[move_line.lot_id.id] |= move.sale_line_id.order_id
|
||||
for lot in self:
|
||||
stock_moves = self.env['stock.move.line'].search([
|
||||
('lot_id', '=', lot.id),
|
||||
('state', '=', 'done')
|
||||
]).mapped('move_id')
|
||||
stock_moves = stock_moves.search([('id', 'in', stock_moves.ids)]).filtered(
|
||||
lambda move: move.picking_id.location_dest_id.usage == 'customer' and move.state == 'done')
|
||||
lot.sale_order_ids = stock_moves.mapped('sale_line_id.order_id')
|
||||
lot.sale_order_ids = sale_orders[lot.id]
|
||||
lot.sale_order_count = len(lot.sale_order_ids)
|
||||
|
||||
def action_view_so(self):
|
||||
|
||||
Reference in New Issue
Block a user