0

Here I adding product_id to vals dict but problem is that if there is more than 1 product, how can I add product_id of each line to this dict vals. Probably I need to make a list of product_ids and then add it to dict but struggling a bit

@api.multi
    def button_details(self):

        domain = [
            ('product_tmpl_id', '=', self.product_id.id)
        ]
        vals = {}

        bom_products = self.env['mrp.bom'].search(domain)
             for bom_line in bom_products.bom_line_ids:
                  vals['product_id'] = bom_line.product_id.id
                  vals['product_uom_qty'] = bom_line.product_qty

    context = self.env.context.copy()
    context['view_buttons'] = True
    view_id = self.env.ref('config.view_order_line_form_view').id
    view = {
        'name': _('Details'),
        'view_type': 'form',
        'view_mode': 'tree, form',
        'res_model': 'sale.order.line',
        'views' : [(view_id,'tree')],
        'type': 'ir.actions.act_window',
        'target': 'new',
        'readonly': True,
   #     'res_id': ,
        'context': context
    }
    return view

Updated the ultimate goal is to open a view that triggered by button with products and qty that i'm trying to extract from bom.line

Chaban33
  • 1,362
  • 11
  • 38
  • May i know, what is the purpose of creating dictionary values of product ids ? Because you already have object of product model and you can create a list product ids by using `bom_line.product_id.ids`. – KbiR Jun 26 '18 at 09:54
  • updated my question – Chaban33 Jun 26 '18 at 10:00

1 Answers1

2
  • Please change this code may it's help you.
    bom_products = self.env['mrp.bom'].search(domain)

    vals['product_id'] = bom_products.bom_line_ids.mapped('product_id.id')
  • And remove for loop it's not necessary.
KbiR
  • 4,047
  • 6
  • 37
  • 103
Bhoomi Vaishnani
  • 718
  • 4
  • 19