我正在尝试通过自定义模块在res.partner表单视图(base.view_partner_form)上添加一个新按钮来打开一个新的浏览器选项卡,但是我收到以下错误:
Traceback (most recent call last):
File "/opt/odoo/odoo-server/openerp/http.py", line 540, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/opt/odoo/odoo-server/openerp/http.py", line 577, in dispatch
result = self._call_function(**self.params)
File "/opt/odoo/odoo-server/openerp/http.py", line 313, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/opt/odoo/odoo-server/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/opt/odoo/odoo-server/openerp/http.py", line 310, in checked_call
return self.endpoint(*a, **kw)
File "/opt/odoo/odoo-server/openerp/http.py", line 806, in __call__
return self.method(*args, **kw)
File "/opt/odoo/odoo-server/openerp/http.py", line 406, in response_wrap
response = f(*args, **kw)
File "/opt/odoo/odoo-server/addons/web/controllers/main.py", line 948, in call_button
action = self._call_kw(model, method, args, {})
File "/opt/odoo/odoo-server/addons/web/controllers/main.py", line 936, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
AttributeError: 'res.partner' object has no attribute 'g_search'
按钮出现但我遇到了这个错误。这些是我的文件内容:
mymodule.py
import openerp
from openerp.osv import fields, osv, orm
from openerp import models
class cant_neg_gs(osv.osv):
_inherit = 'res.partner'
@api.multi
def g_search(self):
res = {
'type': 'ir.actions.act_url',
'url': 'http://www.myurl.com',
'target': 'new',
}
return res
mymodule.xml
<?xml version="1.0"?>
<openerp>
<data>
<record id="gs_cant_neg_view" model="ir.ui.view">
<field name="name">res.partner.cant_neg_gs.inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='title']" position="after">
<button string="Buscar empresa" type="object" name="g_search" class="oe_highlight"/>
</xpath>
</field>
</record>
</data>
</openerp>
__初始化__。PY
import cant_neg_gs
__的OpenERP __。PY
{
'name': 'My Module,
'version': '1.0',
'category': 'Uncategorized',
'summary': 'Summary',
'sequence': 2,
'description': """
Info
====================================================
More info
Things :
-------------------------------
* Button
""",
'author': 'Name',
'website': 'https://example.com',
'depends': ['base',],
'data': [
'cant_neg_gs.xml',
],
'installable': True,
'application': True,
'auto_install': False,
}
非常感谢您的帮助!
问候。
答案 0 :(得分:1)
您已导入导入cant_neg_gs 类名,但您必须导入文件。名称不是类名Ex-: import mymodule 。
您的代码还有一个问题,您可以按照以下代码进行操作。
from openerp import models,fields,api
class res_partner(models.Model):
_inherit="res.partner"
@api.multi
def g_search(self):
res = {
'type': 'ir.actions.act_url',
'url': 'http://www.myurl.com',
'target': 'new',
}
return res
在您的文件 api 中未导入,您使用了 @ api.multi ,这就是您必须导入api的原因。
这可能会对你有帮助。