Hello All,
I have a many2many field Sales order lines and i want to return multiple fields values from wizard to many2many field. So, What should i do? in Below code pack_id is many2many field and i want to return values for this field from wizard( for One2many, many2one and selection). Now, I am successfully return the values for one2many. And want to return values for many2one and selection field.
My Python Code is here:
Wizard Code:
product_id = fields.Many2one('product.product', string="Product Pack", required=True, domain="[('is_pack','=',True)]")
qty = fields.Float(string='Quantity', digits=dp.get_precision('Product Unit of Measure'), required=True, default=1.0)
ashes_containerr = fields.Many2one('gold.service')
space = fields.Selection([('1', 'Ashes Storing Space (1yr)'),
('2', 'Planting Space (1yr)')], string='Space')
@api.multi
def action_salepack_add(self):
rec = self._context.get('active_ids', [])
print "REC", rec, self.product_id.categ_id #product_uom
if rec:
line_values = {'product_id': self.product_id.id,
#'design_id':self.design_id.id,
#'product_pack': self.product_id.name,
'pack_id': [(6, 0, [v.id for v in self.product_id.product_pack])] and self.ashes_containerr.gold_service,
'category_id':self.product_id.categ_id.id,
'order_id':rec[0],
'product_uom_qty':self.qty,
}
sale_order_line = self.env['sale.order.line'].create(line_values)
Field in sales order line:
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
products_id = fields.Many2many('product.template', string='Extra products')
pack_id = fields.Many2many('product.pack', string='Pack Products',change_default=True, default=_onchange_product_pack_name)