I am using Odoo v8. Currently I created a pop up (do_action function) with a tree inside.
This is the view.
<record id="view_mcu_record_popup_form" model="ir.ui.view">
<field name="name">mcu.record.popup.form</field>
<field name="model">mcu.record</field>
<field name="context">{'default_parent_mcu_data_id': 479}</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="name" readonly="1" />
</group>
<field name="mcu_data_ids" domain="[('parent_mcu_data_id', '=', 479)]" context="[('default_parent_mcu_data_id', '=', 479)]" widget="one2many_list">
<tree editable="bottom" create="true" delete="true">
<field name="name" />
<field name="val_alphabet" />
<field name="val_float" />
<field name="val_yesno" />
<field name="ref_range" />
<field name="unit" />
<field name="highlight" />
<field name="note" />
</tree>
</field>
</sheet>
<footer>
<button name="save_data" string="Save" type="object" class="oe_highlight" />
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
I wanted to give default value to a field as you can see I put
<field name="context">{'default_parent_mcu_data_id': 479}</field>
<field name="mcu_data_ids" domain="[('parent_mcu_data_id', '=', 479)]" context="[('default_parent_mcu_data_id', '=', 479)]" widget="one2many_list">
These two lines does nothing. The new row parent_mcu_data_id remains empty.
How to give them a default value from view (not from the model please).
Here I put the variable that I give to do_action function
var new_tree_action = {
type: "ir.actions.act_window",
name: act_title,
res_model: "mcu.record",
res_id: this.field_manager.datarecord.id,
view_mode: "form",
view_type: "form",
views: [[false, "form"]],
target: "new",
context: {
"default_patient_mcu_id": this.field_manager.datarecord.id,
"default_parent_mcu_data_id": 479,
"context_id": context_id,
"context_parent_id": context_parent_id,
"variety": context_variety,
"ref_range": context_ref_range,
"note": context_note,
"highlight": context_highlight,
"unit": context_unit,
"res_id": context_res_id,
},
}
I fill view id [[false, "form"]]
later using ir_model_data.call("get_object_reference", ["medical_checkup", view_id]).then(function(results) {
To give more information I decided to give a hint of the model
class McuRecordInherit(models.Model):
_auto = True
_inherit = "mcu.record"
_description ="Medical Checkup Record"
mcu_data_ids = fields.One2many("mcu.data", "patient_mcu_id", string="Medical Checkup Data")