[FIX] mrp: Display correct BoM count on state button

- Display correct bom count for product, before this commit it was
 not displaying the bom count when we have bom for template without variant.

task-39561
This commit is contained in:
Sanjay Jamod
2018-04-09 15:39:19 +02:00
committed by Arnold Moyaux
parent 49af604c20
commit 030f454fab
+2 -13
View File
@@ -16,10 +16,8 @@ class ProductTemplate(models.Model):
help="Average lead time in days to manufacture this product. In the case of multi-level BOM, the manufacturing lead times of the components will be added.")
def _compute_bom_count(self):
read_group_res = self.env['mrp.bom'].read_group([('product_tmpl_id', 'in', self.ids)], ['product_tmpl_id'], ['product_tmpl_id'])
mapped_data = dict([(data['product_tmpl_id'][0], data['product_tmpl_id_count']) for data in read_group_res])
for product in self:
product.bom_count = mapped_data.get(product.id, 0)
product.bom_count = self.env['mrp.bom'].search_count([('product_tmpl_id', '=', product.id)])
@api.multi
def _compute_used_in_bom_count(self):
@@ -56,17 +54,8 @@ class ProductProduct(models.Model):
mo_count = fields.Integer('# Manufacturing Orders', compute='_compute_mo_count')
def _compute_bom_count(self):
# read_group_res: BOM where product_id is set
# read_group_res_tmpl: BOM where product_tmpl_id is set and product_id is not set
# The total count is the sum of both.
read_group_res = self.env['mrp.bom'].read_group([('product_id', 'in', self.ids)], ['product_id'], ['product_id'])
mapped_data = dict([(data['product_id'][0], data['product_id_count']) for data in read_group_res])
read_group_res_tmpl = self.env['mrp.bom'].read_group([
('product_tmpl_id', 'in', self.mapped('product_tmpl_id.id')), ('product_id', '=', False)
], ['product_tmpl_id'], ['product_tmpl_id'])
mapped_data_tmpl = dict([(data['product_tmpl_id'][0], data['product_tmpl_id_count']) for data in read_group_res_tmpl])
for product in self:
product.bom_count = mapped_data.get(product.id, 0) + mapped_data_tmpl.get(product.product_tmpl_id.id, 0)
product.bom_count = self.env['mrp.bom'].search_count(['|', ('product_id', '=', product.id), '&', ('product_id', '=', False), ('product_tmpl_id', '=', product.product_tmpl_id.id)])
@api.multi
def _compute_used_in_bom_count(self):