[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
This commit is contained in:
Lucas Perais (lpe)
2017-12-04 15:42:06 +01:00
parent e0ea17990a
commit 4aef443135
+5 -2
View File
@@ -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):