Search code examples
pythonodooodoo-14

Pass list records to many2many field in odoo


I've created a wiz to get the product which are in the field "catagory_select" please look the code below:

class CategorySelect(models.TransientModel):
    _name = 'product.group'
    category_select = fields.Many2many('product.category', string='Category')

    def start_search_product(self):
        wiz_form = self.env.ref('product_filter.get_products_form_all', False)
        for rec in self.category_select:
            product_res = self.env['product.product'].search([('categ_id', '=', rec.ids)])
        print('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^', product_res)
        return {
            'type': 'ir.actions.act_window',
            'name': "Product Filtered",
            'res_model': 'product.selection',
            'target': 'new',
            'view_id': wiz_form.id,
            'view_mode': 'form',
            }
        }

here what i done is i have created a method which returns a wizard but i am not getting a way that how shoud i pass the "product_res" to a many2many field in another wizard which is called the return menu.

"Any help will be appreciated"


Solution

  • You can set on context with default fields set with your values.

    ctx = self._context.copy()
    ctx.update({'default_m2m_fields': [(6, 0, IDS)]}) # on new wizard the m2m fields set with default on context