I am creating saleorder from code and need to know how to set the order_line field which is of one2many type.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
1
Reply
6671
Views
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
Thanks
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up