默认值

2024-04-19 21:02:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我用的是奥多v8。目前我创建了一个弹出窗口(dou action函数),里面有一个树。你知道吗

这就是风景。你知道吗

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

我想给一个字段设置默认值,正如我所说的

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

这两条线没用。新行父数据id保持为空。你知道吗

如何给他们一个默认值从视图(不是从模型请)。你知道吗

在这里,我把变量,我给做动作函数

        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,
            },
        }

我稍后使用ir_model_data.call("get_object_reference", ["medical_checkup", view_id]).then(function(results) {填充视图id [[false, "form"]]

为了提供更多的信息,我决定给一个模型的提示

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")

Tags: nameformviewiddefaultfielddatamodel
2条回答

如果在mcu.record模型中声明了parent_mcu_data_id字段,@CZoellner的答案是正确的。但如果它位于关系字段mcu_data_ids所指的模型中,请执行以下操作:

将字段parent_mcu_data_id添加到树视图,否则domaincontextdefault_键将不起作用:

<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" />
        <field name="parent_mcu_data_id" />
    </tree>
</field>

并删除上面写的字段context(是record标记的子项)。它在ir.ui.view中什么也不做。你知道吗

必须更新不在视图中的操作的上下文。在渲染视图时,已计算默认值。你知道吗

如果从另一个视图的按钮打开窗体视图,请更新其上下文:

<button name="do_action" string="Action"
    context="{'default_field_another_model': 'default'}" />

相关问题 更多 >