-
product_tmpl_id
-
product_tmpl_id.id
-
id
|
res = defaultdict(lambda: {'moves_in': 0, 'moves_out': 0})
incoming_moves = self.env['stock.move.line']._read_group([
('product_id.product_tmpl_id', 'in', self.ids),
('state', '=', 'done'),
('location_id.warehouse_id', '=', False),
('location_dest_id.warehouse_id', '!=', False),
('date', '>=', fields.Datetime.now() - relativedelta(years=1))
], ['product_id'], ['__count'])
outgoing_moves = self.env['stock.move.line']._read_group([
('product_id.product_tmpl_id', 'in', self.ids),
('state', '=', 'done'),
('location_id.warehouse_id', '!=', False),
('location_dest_id.warehouse_id', '=', False),
('date', '>=', fields.Datetime.now() - relativedelta(years=1))
], ['product_id'], ['__count'])
for product, count in incoming_moves:
product_tmpl_id = product.product_tmpl_id.id
res[product_tmpl_id]['moves_in'] += count
for product, count in outgoing_moves:
product_tmpl_id = product.product_tmpl_id.id
res[product_tmpl_id]['moves_out'] += count
for template in self:
template.nbr_moves_in = res[template.id]['moves_in']
template.nbr_moves_out = res[template.id]['moves_out']
|
|