字段不只存在于树视图中

Field does not exists only in tree view

所以我遇到了树视图的问题。

如果我想添加字段名称="work_order_id",我发现该字段不存在。但如果我点击记录,它会打开我的表单视图,该字段是否存在?我的树视图有什么问题?

<record id="mrp_workorder_view_form" model="ir.ui.view">
    <field name="name">mrp.workorder.view.form</field>
    <field name="model">mrp.workorder</field>
    <field name="priority">15</field>
    <field name="inherit_id" ref="mrp.mrp_production_workorder_form_view_inherit"/>
    <field name="arch" type="xml">
        <field name="name" position="before">
            <field name="work_order_lots_ids" widget="one2many_list"/>
                <tree  editable="bottom">
                    <!--<field name="work_order_id"/>-->
                </tree>
        </field>
    </field>
</record>
class WorkOrderLots(models.Model):
    _name = 'work.order.lots'
    _description = 'Work Order Lots'

    work_order_id = fields.Many2one('mrp.workorder')
    work_order_lot_id = fields.Many2one(
        'stock.production.lot', string='Work Order Lot',
    )
    quantity = fields.Float(string='Quantity', digits=(6, 2), required=False)

class MrpWorkorder(models.Model):
    _inherit = 'mrp.workorder'


    work_order_lots_ids = fields.One2many(
        'work.order.lots', 'work_order_id',
        string='Field Names',
        )

从字段 work_order_lots_ids

中删除 widget="one2many_list" 个属性

替换以下来自

的代码
<field name="work_order_lots_ids" widget="one2many_list"/>
    <tree  editable="bottom">
        <!--<field name="work_order_id"/>-->
    </tree>
</field>

<field name="work_order_lots_ids"/>
    <tree  editable="bottom">
        <field name="work_order_lot_id"/>
        <field name="quantity"/>
    </tree>
</field>

这对我有用。刚刚将视图更改为此。

<record id="mrp_workorder_view_form" model="ir.ui.view">
            <field name="name">mrp.workorder.view.form</field>
            <field name="model">mrp.workorder</field>
            <field name="priority">15</field>
            <field name="inherit_id" ref="mrp.mrp_production_workorder_form_view_inherit"/>
            <field name="arch" type="xml">
                <notebook position="inside">
                    <page string="Work Order Lots" name="work_order_lots">
                        <field name="work_order_lots_ids" widget="section_and_note_one2many" >
                            <form>
                                <group>
                                    <field name="work_order_lot_id"/>
                                    <field name="quantity" />
                                </group>
                            </form>
                            <tree string="Work Order Lotss" editable="bottom" >
                                <field name="work_order_lot_id"/>
                                <field name="quantity" />
                            </tree>
                        </field>
                    </page>
                </notebook>
            </field>
        </record>