Skip to Content
Menu
This question has been flagged
3869 Views

v : 10.0

  • I have defined a window action on the mrp.bom form to display a kanban of the products in inventory and pass the bom_id as context :

@api.multi
def action_show_catalogue(self):
self.ensure_one()
return {
'name': _('Catalogue'),
'type': 'ir.actions.act_window',
'res_model': 'product.template',
'view_mode': 'kanban',
'view_id': self.env.ref('ciment_mrp.mrp_product_select').id,
'context': {
'bom_id': self.id,
},
'domain': [
],
}

  • I have defined a button action on the product Kanban to get the bom_id from context and add the product as a mrp.bom.line to the bom: 

def add_to_bom(self):
ctx = dict(self.env.context)
bom = ctx.get('bom_id')
bom_lines = self.env['mrp.bom.line']

if bom:
vals = {
'bom_id': bom,
'product_id': self.id,
}
bom_lines.create(vals)
return

The code works but the behaviour is erratic. The products being added to the bill of material are not always the products that you 'click' on...  

It seems to be a problem with defining the proper active_id .. ?

So here are my questions :

  • What is 'self' in the context of a Kanban view ?

  • How to define the chosen record as the active_id to pass to the python method ?

Regards

EDIT :  Fixed it... 

def add_to_bom(self):
ctx = dict(self.env.context)
bom = ctx.get('bom_id')
bom_lines = self.env['mrp.bom.line']
if bom:
vals = {
'bom_id': bom,
'product_id': self.product_variant_id.id,
}
bom_lines.create(vals)
return


I need to use the product.product id to populate the mrp.bom.line table....

Avatar
Discard
Related Posts Replies Views Activity
3
Feb 17
7732
0
Feb 16
3959
0
Mar 15
3710
0
Jul 24
387
0
Nov 24
68