From 4aef4431359f05b08ec91db2c2836ccaf9bcea71 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Fri, 24 Nov 2017 14:04:25 +0100 Subject: [PATCH] [FIX] product: product category smart button: sub categ too Before this commit, the smart button on the form of product category only displayed the number of product for the current category, whereas the list view of products (when you clicked on the smart button) displayed all sub-categories products. After this commit, the behavior is harmonized: all sub-categories products should be accounted for and displayed OPW 782905 --- addons/product/models/product.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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):