Skip to Content
Menu
This question has been flagged
3 Replies
17435 Views

Hi,

 

In the tree view, I can 'Add an item' that pops up the window of the related object I want to create.

How can i set a default value for a field in the window opened for this related object using data from the former object ?

I don't know if I am clear enough...

 

Thanks for your help !

Avatar
Discard
Best Answer

If am not wrong, you are trying to set data from former object to New object... So in your case it should be parent and child objects...

If yes, then you can set in 2 ways...

1. Context : In XML by using context you set the value, or access the context value in your Child Object defaults method in Py Class..

2. Parent: In XML, by using the parent keyword also you can set value of its  parent data...

(Ex. <field name="O2M_lines" context={'default_CHILD_FIELD' : parent.PARENT_FIELD })
 

Tips: use Ctrl + H, if you are using studio, to perform search action in the entire standard addons module for more examples

Avatar
Discard
Author

Thank you I manage to work it out with your explanation. Last question : is it possible to concatenate such as : context="{'default_CHILD_FIELD' : '%s -%s'%(parent.PARENT_FIELD1,parent.PARENT_FIELD2) }" ?

Best Answer

Hi,

You can set default value for any of field from selected form view. Just see the below screen. User can set default value from "debug" mode.

second way to manage default value of any model from python code is that we can define _defaults = {} into that model from .py file.

I hope this will help you.

Avatar
Discard
Best Answer

you can use database constrain as well.. if i want to set default value for one of the field in table then class claim(osv.osv): _name = "test" _description = "test" _columns = { 'claimed_amount':fields.integer('Amount claimed'),} _defaults = { 'claimed_amount': '1000', }

 

 

 

Avatar
Discard
Related Posts Replies Views Activity
3
Apr 25
4045
2
Dec 23
4518
5
Nov 23
42400
3
Sep 23
9085
2
Jan 23
2182