|
|
incoming_moves = self.env['stock.move.line']._read_group([
('product_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', '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'])
res_incoming = {product.id: count for product, count in incoming_moves}
res_outgoing = {product.id: count for product, count in outgoing_moves}
for product in self:
product.nbr_moves_in = res_incoming.get(product.id, 0)
product.nbr_moves_out = res_outgoing.get(product.id, 0)
|
|