[IMP] mrp: show boms in which a product has been used as a component
This commit is contained in:
@@ -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'])
|
||||
|
||||
@@ -49,6 +49,10 @@
|
||||
attrs="{'invisible':[('type', 'not in', ['product', 'consu'])]}" icon="fa-flask">
|
||||
<field string="Bill of Materials" name="bom_count" widget="statinfo" />
|
||||
</button>
|
||||
<button class="oe_stat_button" name="action_used_in_bom" type="object"
|
||||
attrs="{'invisible':['|',('type', 'not in', ['product', 'consu']), ('used_in_bom_count', '=', 0)]}" icon="fa-level-up">
|
||||
<field string="BoM Where Used" name="used_in_bom_count" widget="statinfo" />
|
||||
</button>
|
||||
<button class="oe_stat_button" name="action_view_mos" type="object"
|
||||
attrs="{'invisible':[('type', 'not in', ['product', 'consu'])]}" icon="fa-list-alt">
|
||||
<field string="Manufacturing" name="mo_count" widget="statinfo" />
|
||||
@@ -68,6 +72,10 @@
|
||||
attrs="{'invisible':[('type', 'not in', ['product', 'consu'])]}" icon="fa-flask">
|
||||
<field string="Bill of Materials" name="bom_count" widget="statinfo" />
|
||||
</button>
|
||||
<button class="oe_stat_button" name="action_used_in_bom" type="object"
|
||||
attrs="{'invisible':['|',('type', 'not in', ['product', 'consu']), ('used_in_bom_count', '=', 0)]}" icon="fa-level-up">
|
||||
<field string="BoM Where Used" name="used_in_bom_count" widget="statinfo" />
|
||||
</button>
|
||||
<button class="oe_stat_button" name="%(act_product_mrp_production)d" type="action"
|
||||
attrs="{'invisible':[('type', 'not in', ['product', 'consu'])]}" icon="fa-list-alt">
|
||||
<field string="Manufacturing" name="mo_count" widget="statinfo" />
|
||||
|
||||
Reference in New Issue
Block a user