' cannot be located in parent view-6ren"> ' cannot be located in parent view-我在 python 代码 bom.py(请参见下文)中创建了一个计算字段,并将该字段添加到 View bom_view.xml 中。字段名称是“old_default_code”,python 代码中-6ren">
gpt4 book ai didi

python - 错误 : Element '' cannot be located in parent view

转载 作者:太空宇宙 更新时间:2023-11-04 08:08:14 25 4
gpt4 key购买 nike

我在 python 代码 bom.py(请参见下文)中创建了一个计算字段,并将该字段添加到 View bom_view.xml 中。字段名称是“old_default_code”,python 代码中的关联函数是_old_default_code()。但是,当我尝试更新(刷新)模块时出现错误:

"Error details: "Field `old_default_code" does not exist"

我做错了什么?

这是来自 bom.py 的代码片段:

class mrp_bom(osv.osv):
_inherit = 'mrp.bom'

def _old_default_code(self, cr, uid, ids, name, arg, context=None):
return True

_columns = {'x_roll_material': fields.float('Standard Material Cost', digits=(16, 4), readonly=True),
'x_bom_time_average': fields.float('Average BOM Lead Time', digits=(16, 4), readonly=True),
'x_bom_time_last': fields.float('Last BOM Lead Time', digits=(16, 4), readonly=True),
'old_default_code' : fields.function(_old_default_code, type='char', size=32, method=True, store=False, multi=False) }

这是 XML 代码:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- mrp_bom -->
<record id="adamson_mrp_bom_form_view" model="ir.ui.view">
<field name="name">adamson.mrp.bom.form.view</field>
<field name="model">mrp.bom</field>
<field name="type">form</field>
<field name="inherit_id" ref="mrp.mrp_bom_form_view" />
<field name="arch" type="xml">
<field name="old_default_code" />
<xpath expr="//notebook/page[@string='Components']/field/tree[@string='Components']/field[@name='sequence']" position="before" >

<button class="oe_inline oe_stat_button" type="object" string="Go!" icon="gtk-go-forward" name="action_go"
attrs="{'invisible':[('old_default_code','=', False)]}" />
</xpath>

最佳答案

当您继承 View 时,这意味着您可以将字段引用到父 View 中存在的元素。

您在此处显示的 View ,因为您试图直接放置字段 old_default_code 而不引用现有字段。

例如,当您通过继承将新字段放入模型时,然后在 View 中您需要引用父 View 中存在的字段并使用具有以下值的选项 position 'after', 'before', 'attributes',您可以定位您新添加的字段。

在这里,您试图直接放置字段 old_default_code,因此尝试在父 View 中找到该字段,但该字段不存在,因此您面临错误。

关于python - 错误 : Element '<field name="x y z">' cannot be located in parent view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27626242/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com