I want to create a new register, but I need to put the value of a parent field as a default value of a child field.
I know that you can send parent values through context from XML and whenever a new form is opened, "default_get" of that object will be executed.
Example, [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.
My problem now is:
How can I access to those values in the default_get method?
I have tried this:
@api.model
def default_get(self, vals):
context = dict(self.env.context)
variable1 = context.get('variable1', False)
print ' variable1'
But this has not worked.