Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
17582 Widoki

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 !

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Autor

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) }" ?

Najlepsza odpowiedź

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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', }

 

 

 

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
3
kwi 25
4378
2
gru 23
4656
5
lis 23
42721
3
wrz 23
9305
2
sty 23
2341