Reputation: 86
I am currently playing with openERP 7. I am doing some testing and I am building my first add-on. I want to add on every product view a "synchronize" button on a tab named "special" that has been created by another add-on (which works perfectly fine). My button displays successfully but when I click on it I obtain the following error:
AttributeError: 'product.product' object has no attribute 'custom_export'
If someone can explain me why do I have that error and how to fix it.
My add-on folder name is: custom_synchronizer, I have 4 files inside.
__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>
Upvotes: 3
Views: 2641
Reputation: 86
Thanks to Gurney Alex suggestion i was able to fix that problem.
I needed to have both _name and _inherit attributes in my class.
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()
Upvotes: 2
Reputation: 13645
change _name to _inherit in your product_product class definition.
Upvotes: 2