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 | etc.
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:
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)
As far as I understood the new logic:
In V8 one can forget about rec.write().
(New better .write() is .create() & .update() )
If you do operations in on_change() you just can ENV['MODEL'].create() records.
They will be shown in the view but not written to DB unless you save the parent record.
When it comes to creating twoway child-parent relations from the parent'onchange you just have to:
(In parent onchange)
#(virtuately, unless parent saved) Create a new child:
#add new child to existing children of parent:
#Tell the parent all its children including the newly created:
When the user is happy with what she sees jn the view now and saves it he parent and children will be written to the DB.
About This Community
This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 3/7/16, 12:39 PM|
|Seen: 378 times|
|Last updated: 3/15/16, 4:49 AM|