Skip to Content
Menu
This question has been flagged
1 Reply
6671 Views

I am creating saleorder from code and need to know how to set the order_line field which is of one2many type.

Avatar
Discard
Best Answer

Hi,

First you can create the sale order like this,

sale_id = self.env['sale.order'].create(    
                    {'partner_id': 1,
                    'date_order': 'value_for_date',
                    'picking_policy': 'direcr'
                    })

Add all the necessary/required fields when creating the record.


Now the sale order will get created. Then we have to create the order lines for this sale order,

sale_order_line = self.env['sale.order.line'].create({  
                            'product_id': 1,           
                              'order_id': sale_id.id
                            })

In the above code you can see that on creating the order lines the value passed to the order_id is the id of the sale order we have created.

Thanks

Avatar
Discard
Author

Thanks