Hi folks.
In V8 I am trying to find out how i can create child records in the Edit view of a parent object but only create the children in the database when the parent is saved.
Some pseudo code to clarify
I have the following classes:
class OrderLine:
part=Many2One('product')
amount=Integer()
maintenanceOrder_id= Many2One('maintenanceOrder')
class MaintenanceOrder:
assembly=Many2One('assembly')
parts=Many2Many( 'products')
orderLines=One2Many('orderline', 'maintenanceOrder_id')
@api.on_change(assembly)
def create_order_lines(self):
self.parts = assembly.product_ids
#this populates the view with potential Spareparts assigned to the selected assembly
Now I want to to "convert" the MaintenanceOrder.parts to MaintenanceOrder.orderlines ON THE FLY (in the view) adding a default amount of 1 and link it to the current maintenanceOrder.
The only way I see now is:
1. Getting an env in on_change
2. env.write('maintenanceOrder.orderlines'..tuple) to the db directly.
3. Link the just created Orderline to the current MaintenanceOrder
But what if the user decides to cancel creating a maintenance order mid-way?
What happens to the orderlines I just env.wrote to the db?
As far as I understood it from existing examples and modules (which are all still V7 api) people then have to handle all "Unlinks" etc. manually.
Is there a way to create and link child objects "virtually" in the on_change method? So all stuff is written to the DB only when the parent object(maintenance order) is saved.
(orderlines should not exist in the db if user clicks cancel)
My question seems pretty odd to me too.
I am propably missing somekind of "inbuilt" concept of odoo.
Would be glad if someone explained what the correct V8api-way of doing this is.
(Without manually handling creation and unlinkage of the children like in v7)