1

嗨,我一直在开发自定义 openerp 模块。我在我的字段中创建了一个按钮,并且我还为它声明了一个 acvtion。但是我收到一个错误“'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)
              }
4

1 回答 1

0

您的对象中必须有 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
`
于 2013-07-12T11:07:37.367 回答