diff --git a/addons/product/models/product.py b/addons/product/models/product.py index 549aa9e4de3..9d7e268df66 100644 --- a/addons/product/models/product.py +++ b/addons/product/models/product.py @@ -32,10 +32,13 @@ class ProductCategory(models.Model): help="The number of products under this category (Does not consider the children categories)") def _compute_product_count(self): - read_group_res = self.env['product.template'].read_group([('categ_id', 'in', self.ids)], ['categ_id'], ['categ_id']) + read_group_res = self.env['product.template'].read_group([('categ_id', 'child_of', self.ids)], ['categ_id'], ['categ_id']) group_data = dict((data['categ_id'][0], data['categ_id_count']) for data in read_group_res) for categ in self: - categ.product_count = group_data.get(categ.id, 0) + product_count = 0 + for sub_categ_id in categ.search([('id', 'child_of', categ.id)]).ids: + product_count += group_data.get(sub_categ_id, 0) + categ.product_count = product_count @api.constrains('parent_id') def _check_category_recursion(self):