From 72c1f07d538dc922a97e5d2d84e376f03e72184f Mon Sep 17 00:00:00 2001 From: Kirti Choudhary Date: Wed, 30 Aug 2017 17:12:08 +0530 Subject: [PATCH] [IMP] mrp: show boms in which a product has been used as a component --- addons/mrp/models/product.py | 26 ++++++++++++++++++++++++++ addons/mrp/views/product_views.xml | 8 ++++++++ 2 files changed, 34 insertions(+) diff --git a/addons/mrp/models/product.py b/addons/mrp/models/product.py index 25ef11da9a3..ab606ace979 100644 --- a/addons/mrp/models/product.py +++ b/addons/mrp/models/product.py @@ -9,6 +9,7 @@ class ProductTemplate(models.Model): bom_ids = fields.One2many('mrp.bom', 'product_tmpl_id', 'Bill of Materials') bom_count = fields.Integer('# Bill of Material', compute='_compute_bom_count') + used_in_bom_count = fields.Integer('# BoM Where Used', compute='_compute_used_in_bom_count') mo_count = fields.Integer('# Manufacturing Orders', compute='_compute_mo_count') produce_delay = fields.Float( 'Manufacturing Lead Time', default=0.0, @@ -20,6 +21,19 @@ class ProductTemplate(models.Model): for product in self: product.bom_count = mapped_data.get(product.id, 0) + @api.multi + def _compute_used_in_bom_count(self): + for template in self: + template.used_in_bom_count = self.env['mrp.bom'].search_count( + [('bom_line_ids.product_id', 'in', template.product_variant_ids.ids)]) + + @api.multi + def action_used_in_bom(self): + self.ensure_one() + action = self.env.ref('mrp.mrp_bom_form_action').read()[0] + action['domain'] = [('bom_line_ids.product_id', 'in', self.product_variant_ids.ids)] + return action + @api.one def _compute_mo_count(self): # TDE FIXME: directly use a read_group @@ -38,6 +52,7 @@ class ProductProduct(models.Model): _inherit = "product.product" bom_count = fields.Integer('# Bill of Material', compute='_compute_bom_count') + used_in_bom_count = fields.Integer('# BoM Where Used', compute='_compute_used_in_bom_count') mo_count = fields.Integer('# Manufacturing Orders', compute='_compute_mo_count') def _compute_bom_count(self): @@ -50,6 +65,17 @@ class ProductProduct(models.Model): bom_count = mapped_data.get(product.id, 0) product.bom_count = bom_count + @api.multi + def _compute_used_in_bom_count(self): + for product in self: + product.used_in_bom_count = self.env['mrp.bom'].search_count([('bom_line_ids.product_id', '=', product.id)]) + + @api.multi + def action_used_in_bom(self): + self.ensure_one() + action = self.env.ref('mrp.mrp_bom_form_action').read()[0] + action['domain'] = [('bom_line_ids.product_id', '=', self.id)] + return action def _compute_mo_count(self): read_group_res = self.env['mrp.production'].read_group([('product_id', 'in', self.ids)], ['product_id'], ['product_id']) diff --git a/addons/mrp/views/product_views.xml b/addons/mrp/views/product_views.xml index 8893e5a54f9..e66973953e5 100644 --- a/addons/mrp/views/product_views.xml +++ b/addons/mrp/views/product_views.xml @@ -49,6 +49,10 @@ attrs="{'invisible':[('type', 'not in', ['product', 'consu'])]}" icon="fa-flask"> + +