From 2231c129208a5dfdb2ffbf1ad06e5e93a11ee961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 11 May 2016 16:01:29 +0200 Subject: [PATCH] [FIX] stock: a gnome stole my methods. --- addons/stock/models/product.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/addons/stock/models/product.py b/addons/stock/models/product.py index 6d4c32cef2d..d9161040658 100644 --- a/addons/stock/models/product.py +++ b/addons/stock/models/product.py @@ -68,6 +68,26 @@ class Product(models.Model): reordering_min_qty = fields.Float(compute='_compute_nbr_reordering_rules') reordering_max_qty = fields.Float(compute='_compute_nbr_reordering_rules') + def _compute_reception_count(self): + move_data = self.env['stock.move'].read_group([ + ('product_id', 'in', self.ids), + ('location_id.usage', '!=', 'internal'), + ('location_dest_id.usage', '=', 'internal'), + ('state', 'in', ('confirmed', 'assigned', 'pending'))], ['product_id'], ['product_id']) + res = dict((data['product_id'][0], data['product_id_count']) for data in move_data) + for move in self: + move.reception_count = res.get(move.id, 0) + + def _compute_delivery_count(self): + move_data = self.env['stock.move'].read_group([ + ('product_id', 'in', self.ids), + ('location_id.usage', '=', 'internal'), + ('location_dest_id.usage', '!=', 'internal'), + ('state', 'in', ('confirmed', 'assigned', 'pending'))], ['product_id'], ['product_id']) + res = dict((data['product_id'][0], data['product_id_count']) for data in move_data) + for move in self: + move.delivery_count = res.get(move.id, 0) + @api.depends('stock_quant_ids', 'stock_move_ids') def _compute_quantities(self): res = self._compute_quantities_dict(self._context.get('lot_id'), self._context.get('owner_id'), self._context.get('package_id'), self._context.get('from_date'), self._context.get('to_date'))