Odoo Help

Welcome!

This community 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.

1

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

By
Pau Ubach
on 10/22/14, 12:35 AM 2,701 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?

Thanks,
Pau

4

deep

--deep--
1617
| 5 4 7
Bengaluru, India
--deep--

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

deep
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...

deep
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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

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