Odoo Help


[SOLVED] How to get parent values in default_get function?

Pau Ubach
on 10/22/14, 12:35 AM 5,132 views

I have a one2many field represented as a tree in a form. When "Add an item" button is clicked, it opens a form, and I'd like to be able to import some field information of the parent and show as default, but default_get doesn't have the parent ID anywhere, so I don't know how to access.

I'm thinking about sending this value by context, but I don't know what method is called when clicking here. Any suggestion?



Techno-Functional Associate with 7+ years of experience in Odoo (formerly known as OpenERP).

On 10/22/14, 1:19 AM

Hi, I seem to be coming across your questions now and then :) :)

Anyways coming to this, Sure you can send parent values through context from XML... and whenever a new form is opened, "default_get" of that object will be executed without fail...

Example,  In your case, [In XML view]:

<field name="one2many_ids" context="{'variable1' : name, 'variable2' : active_id, 'default_column1' : 'samplevalue'}" />

Note: [There are 3 ways of setting default value]

 1. Variable1: you can pass parent value, which you can retrieve in default_get method..
 2. Variable2: "active_id" is a keyvalue, which provides ID of its immediate parent object, so in default_get you can browse and fetch the parent record , provided parent record must be saved in order to get it...
 3. default_column: straight away setting default values for a column..


Thanks deep, I really don't know how to pay you :). What would I do without you here?

Pau Ubach
on 10/22/14, 2:21 AM

Ha Ha... that's a wonderful compliment... I just share my tips and knowledge like others... Just go ahead and keep rocking in Odoo...

on 10/22/14, 2:34 AM

Yes, I see you do... But it's really nice that you spend so much time helping others sharing your knowledge.

Pau Ubach
on 10/22/14, 2:36 AM

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.


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

2 follower(s)


Asked: 10/22/14, 12:35 AM
Seen: 5132 times
Last updated: 3/16/15, 8:10 AM