我在python代码bom.py中创建了一个计算字段(请参见下面),并在视图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>I have created a computed field in python code, bom.py (please see below) and added that field in the view bom_view.xml. The field name is "old_default_code" and associated function in python code is _old_default_code(). However, when I try to update (refresh) the module I am getting an error:
"Error details: "Field `old_default_code" does not exist"What am I doing wrong?
Here is the code snippet from 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) }and here is the XML code:
<?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>最满意答案
继承视图时,这意味着您可以将字段引用到父视图中存在的元素。
您在此处显示的视图,因为您试图直接放置字段old_default_code而不引用现有字段。
例如,当您通过继承将新字段放入模型时,在视图中您需要引用父视图中的字段并使用具有“之后”,“之前”,“属性”等值的选项position ',您可以定位新添加的字段。
在这里,您试图直接放置字段old_default_code ,因此尝试在父视图中找到该字段,该字段不存在,并且由于您正面临错误。
When you inherit a view, that means you can put field in reference to the elements present in the parent view.
The view that you have shown here, in that you tried to put the field old_default_code straight away without any reference to existing field.
For example, when you put new field to a model by inheritance, then in the view you need to refer to field which is there in the parent view and using the option position having the values like 'after', 'before', 'attributes', you can position your newly added field.
Here you are trying to put the field old_default_code straight away, so tries to find that field in the parent view, which is not there and due to that you are facing the error.
更多推荐
发布评论