简体   繁体   English

开发openerp模块时如何解决“对象无属性”错误?

[英]how to fix 'object has no attribute ' error while developing openerp module?

Hi I have been developing a custom openerp module. 嗨,我一直在开发自定义的openerp模块。 I have created a button in my field and I have also declared an acvtion for it. 我在自己的字段中创建了一个按钮,并为此声明了一个按钮。 But I am getting an error " 'my_form' object has no attribute 'add_field' "? 但是我收到一个错误“'my_form'对象没有属性'add_field'“?

here is myform_view.xml 这是myform_view.xml

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data>

        <record model="ir.ui.view" id="from_view_form">
            <field name="name">form.view.form</field>
            <field name="model">my.form</field>
            <field name="arch" type="xml">
                <form string="Form" version="7.0">
                    <group>
                        <field name="name" />
                        <field name="project" />
                        <button name="add_field" string="Add Field" type="object" />
                    </group>
                </form>
            </field>
        </record>

        <record model="ir.ui.view" id="from_view_tree">
            <field name="name">form.view.tree</field>
            <field name="model">my.form</field>
            <field name="arch" type="xml">
                <tree string="Form">
                    <field name="name" />
                </tree>
            </field>
        </record>    

        <record model='ir.actions.act_window' id='add_field'>
            <field name="name">Form</field>
            <field name="res_model">my.form2</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
            <field name="context">{}</field>
            <field name="help" type="html">
                <p class="oe_view_nocontent_create">
                    Click to create a new record.
                </p>
                <p>This is a test class developed to learn Openerp.</p>
            </field>
        </record>













        <record model='ir.actions.act_window' id='form_view_action'>
            <field name="name">Form</field>
            <field name="res_model">my.form</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="context">{}</field>
            <field name="help" type="html">
                <p class="oe_view_nocontent_create">
                    Click to create a new record.
                </p>
                <p>This is a test class developed to learn Openerp.</p>
            </field>
        </record>

        <menuitem id="myform_ID" name="myforms" />

        <menuitem id="myform_menu_ID" name="myform" parent="myform_ID"  />

        <menuitem id="myform_menu2_ID" name="myform" parent="myform_menu_ID"  action='form_view_action' />

    </data>
</openerp>

here is myform.py 这是myform.py

from osv import fields, osv
import time


class my_form(osv.osv):

    _name = "my.form"
    _description = 'Formview Module'
    _columns = {
        'name': fields.char('Name', size=64),
        'project': fields.char('Project', size=64),
        'image': fields.binary('Image'),
        'file':fields.binary('attach file')
    }



class my_form2(osv.osv):

    _name="my.form2"
    _description="new form"
    _columns={
              'add':fields.char('Address',size=64)
              }

there must have add_field method in your object like ie class my_form(osv.osv): 对象中必须有add_field方法,例如类my_form(osv.osv):

    _name = "my.form"
    _description = 'Formview Module'
    _columns = {
        'name': fields.char('Name', size=64),
        'project': fields.char('Project', size=64),
        'image': fields.binary('Image'),
        'file':fields.binary('attach file')
    }

    def add_field(self, cr, uid, ids, context={}):
        #YOUR CODE
        return True
`

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复错误“AttributeError:&#39;module&#39;对象在python3中没有属性&#39;client&#39;? - How to fix error "AttributeError: 'module' object has no attribute 'client' in python3? 模块对象没有属性声音。 不断收到此错误,不知道如何解决? - module object has no attribute sound. keep getting this error do not know how to fix it? 如何修复 pip 错误“查找 'pip' 的模块规范时出错(AttributeError:模块 '__main__' 没有属性 '__file__')”? - How to fix pip error "Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__')"? 如何修复 AttributeError: &#39;module&#39; 对象没有属性 &#39;function&#39;? - How to fix AttributeError: 'module' object has no attribute 'function'? 如何修复“AttributeError:‘module’对象没有属性‘x’”? - how to fix "AttributeError: 'module' object has no attribute 'x' "? 如何修复“未找到模块”和“ int对象没有属性”样条线”? - How to fix 'No module found' and 'int object has no attribute 'splitlines'? openerp错误AttributeError:&#39;int&#39;对象没有属性&#39;iteritems&#39; - openerp error AttributeError: 'int' object has no attribute 'iteritems' Openerp8启动错误:AttributeError:&#39;bool&#39;对象没有属性&#39;endswith&#39; - Openerp8 startup error: AttributeError: 'bool' object has no attribute 'endswith' 如何修复属性错误:'None type' object has no attribute next - how to fix attribute error : 'None type' object has no attribute next 如何修复此属性对象在Django中没有属性错误? - How to fix this attribute object has no attribute error in django?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM