diff --git a/stock_reserve/model/product.py b/stock_reserve/model/product.py index 46e394e57..1f6c42333 100644 --- a/stock_reserve/model/product.py +++ b/stock_reserve/model/product.py @@ -29,15 +29,10 @@ class ProductTemplate(models.Model): compute='_reservation_count', string='# Sales') - @api.multi + @api.one def _reservation_count(self): - StockReservation = self.env['stock.reservation'] - product_ids = self._get_products() - domain = [('product_id', 'in', product_ids), - ('state', 'in', ['draft', 'assigned'])] - reservations = StockReservation.search(domain) - self.reservation_count = sum(reserv.product_qty - for reserv in reservations) + self.reservation_count = sum(variant.reservation_count + for variant in self.product_variant_ids) @api.multi def action_view_reservations(self): @@ -62,11 +57,9 @@ class ProductProduct(models.Model): @api.one def _reservation_count(self): - StockReservation = self.env['stock.reservation'] - product_id = self._ids[0] - domain = [('product_id', '=', product_id), + domain = [('product_id', '=', self.id), ('state', 'in', ['draft', 'assigned'])] - reservations = StockReservation.search(domain) + reservations = self.env['stock.reservation'].search(domain) self.reservation_count = sum(reserv.product_qty for reserv in reservations)