我无法在one2many树中添加字段(在表单视图中)。为什么呢?

时间:2015-07-16 11:26:37

标签: xml odoo odoo-8

我想在/stock/stock_view.xml

中的这个one2many中插入一个新字段
<field name="pack_operation_ids" context="{'default_picking_id': active_id, 'default_location_id': location_id, 'default_location_dest_id': location_dest_id}">
    <tree editable="top">
        <field name="package_id" groups="stock.group_tracking_lot"/>
        <field name="product_id" on_change="product_id_change(product_id, product_uom_id, product_qty)"/>
        <field name="product_uom_id" groups="product.group_uom"/>
        <field name="lot_id" domain="[('product_id','=?', product_id)]" context="{'product_id': product_id}" groups="stock.group_production_lot"/>
        <field name="picking_id" invisible="1"/>
        <field name="owner_id" groups="stock.group_tracking_owner"/>
        <field name="product_qty" attrs="{'required': [('product_id', '!=', False)]}"/>
        <field name="location_id" domain="[('id', 'child_of', parent.location_id)]"/>
        <field name="location_dest_id" domain="[('id', 'child_of', parent.location_dest_id)]"/>
        <field name="result_package_id" groups="stock.group_tracking_lot" context="{'location_id': location_dest_id}"/>
    </tree>
</field>

我试过这个:

<xpath expr="/form/sheet/notebook/page[@string='Operations']/field[@name='pack_operation_ids']/tree/field[@name=result_package_id]" position="after">
    <field name="label_qty" />
</xpath>

但它不起作用。我收到这个错误:

Error details:
Field `label_qty` does not exist

我认为这是因为它没有检测到pack_operation_ids

的模型

我的python代码

class StockPackOperation(models.Model):
    _inherit = 'stock.pack.operation'

    label_qty = fields.Integer(
        string='Label quantity',
        required=True,
        # default=lambda self: self._get_default_qty,
    )

我也试过更换整个领域并且它不能很好地工作,它复制了笔记本外面的字段而没有别的。

还有其他办法吗?

1 个答案:

答案 0 :(得分:1)

您只需尝试正确升级模块,然后更改xml

中的以下代码

首先,您将检查您创建的字段是否在Odoo的数据库模型结构中完全创建成功。 首先检查这个,然后将该字段放入视图.xml文件中。

<xpath expr="//page[@string='Operations']/field[@name='pack_operation_ids']/tree/field[@name='result_package_id']" position="after">
    <field name="label_qty" />
</xpath>

我希望我的回答可以帮到你:)。

相关问题