开发openerp模块时如何修复'对象没有属性'错误?

时间:2013-07-12 04:42:30

标签: python eclipse openerp

您好我一直在开发自定义openerp模块。我在我的领域创建了一个按钮,我也宣布了它的一个活动。但我得到一个错误“'my_form'对象没有属性'add_field'”?

这是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>

这是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)
              }

1 个答案:

答案 0 :(得分:0)

你的对象中必须有add_field方法 即     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')
    }

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