OpenERP 7:在产品视图上添加按钮

时间:2013-05-18 14:26:24

标签: python xml openerp

我目前正在玩openERP 7.我正在做一些测试,我正在构建我的第一个插件。 我想在每个产品视图上添加一个名为“special”的选项卡上的“同步”按钮,该选项卡由另一个加载项创建(完全正常)。我的按钮显示成功,但当我点击它时,我得到以下错误:

AttributeError: 'product.product' object has no attribute 'custom_export'

如果有人可以解释我为什么会有这个错误以及如何解决它。

我的附加文件夹名称是:custom_synchronizer,我里面有4个文件。

__ init__.py

import product

__ openerp.py __

{
    "name" : "Custom synchronizer",
    "version" : "0.1",
    "author" : "Ajite",
    "category" : "Product",
    "depends" : ["product"],
    "init_xml" : [],
    "demo_xml" : [],
    "update_xml" : ["product_view.xml"],
    "installable": True,
    "active": True
}

product.py

from openerp.osv import orm, fields

class product_product(osv.osv):
        _name = 'product.product'
        _columns = {}

        def custom_export(self, cr, uid, ids, context=None):
            f = open('/home/ajite/faytung.txt','w')
            f.write('Hi there !')
            f.close()
            return True
product_product()

product_view.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record id="product_normal_form_view" model="ir.ui.view">
            <field name="name">product.product.form</field>
            <field name="model">product.product</field>
            <field name="inherit_id" ref="special.product_normal_form_view"/>
            <field name="arch" type="xml">
                <page name="special" position="inside">
                    <button name="custom_export" string="Export" icon="gtk-execute" type="object"/>
                </page>
            </field>
        </record>
    </data>
</openerp>

2 个答案:

答案 0 :(得分:2)

在product_product类定义中将_name更改为_inherit。

答案 1 :(得分:2)

感谢Gurney Alex的建议,我能够解决这个问题。

我需要在班上同时拥有_name和_inherit属性。

product.py

from osv import fields, osv

class product_product(osv.osv):
    _name = 'product.product'
    _inherit = 'product.product'

    def custom_export(self, cr, uid, ids, context=None):

        return True 

product_product()