Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 单击自定义模块添加的新按钮时的AttributeError_Python_Openerp_Odoo 8_Openerp 8 - Fatal编程技术网

Python 单击自定义模块添加的新按钮时的AttributeError

Python 单击自定义模块添加的新按钮时的AttributeError,python,openerp,odoo-8,openerp-8,Python,Openerp,Odoo 8,Openerp 8,我试图通过自定义模块在res.partner表单视图(base.view\u partner\u表单)上添加一个新按钮,以打开新的浏览器选项卡,但出现以下错误: Traceback (most recent call last): File "/opt/odoo/odoo-server/openerp/http.py", line 540, in _handle_exception return super(JsonRequest, self)._handle_excepti

我试图通过自定义模块在res.partner表单视图(base.view\u partner\u表单)上添加一个新按钮,以打开新的浏览器选项卡,但出现以下错误:

    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
import cant_neg_gs
{
    '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,
}
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>
\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu.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
import cant_neg_gs
{
    '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,
}
非常感谢您的帮助


注意。

您已经导入了导入cant\u neg\u gs类名,但必须导入文件。名称不是类名Ex-:导入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的原因

这可能对你有帮助