This question has been flagged
1 Reply
13429 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

Avatar
Discard
Best Answer

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

 

Avatar
Discard
Author

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

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

Author

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

I am trying to access to any of these 3 values in default_get method, but I don't know how to do it. I am working with Odoo 9