Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
17466 Vistas

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
Descartar
Mejor respuesta

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

Mejor respuesta

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
Descartar
Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
3
abr 25
4161
2
dic 23
4563
5
nov 23
42516
3
sept 23
9166
2
ene 23
2230