Skip to Content
Menu
This question has been flagged
1784 Views

I was looking for a way to create a new object of a sale line but only in memory and not yet in the database. While searching I came across the new() method.

Although I couldn't find any information on it on the odoo documentation and even on the internet. I tried it and it kind of worked, that the code ran without errors.

res = order.new({"order_line": [(0, 0, {"display_type": False,
"name": "testline write " + str(i),
"order_id": order.id,
"price_unit": str(i),
"product_uom": 1,
'product_id': 2})]})

if I print res I get this: sale.order(<NewId 0x7f9cb5c32ac8>,)

it kind of creates a new sale order and adds the line, but I can't get it to connect to an existing model or to persist it to the database. I tried res.flush() but that didn't changed anything.

Anybody has any ideas on how this works.

The reason I thought about using it is that I want to make new sale order lines in a wizard and only save them after the user added some fields.If the record is saved immediately some required fields are not filled in yet and this results in an error.

If you have other ideas on how to do this, feel free to add them.


Avatar
Discard