Odoo Help

0

How to add set default value from tree view edition

By
Victor Godayer
on 3/4/15, 12:33 PM 3,615 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 !

1
deep
On 3/5/15, 5:09 AM

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

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

Victor Godayer
on 3/5/15, 12:12 PM
1
Alby Antony
On 3/5/15, 3:40 AM

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

 

 

 

1

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.

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

Question tools

1 follower(s)

Stats

Asked: 3/4/15, 12:33 PM
Seen: 3615 times
Last updated: 3/16/15, 8:10 AM