为什么在按钮单击OpenERP时插入命令

时间:2014-12-31 08:37:09

标签: python openerp-7

我正在研究模块。它有一个按钮,其名称是创建的,如下面的代码所示。

<button name="creates" string="Create" type="object" groups="base.group_erp_manager" />

def creates(self,cr,uid,ids,context=None):
    for id in ids:
        deg_obj=self.pool.get('deg.form').browse(cr,uid,id)
    pr=int(deg_obj.categg_temp)
    ctx=dict(context)
    ctx.update({'default_pr':pr})

    return{
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'product.product',
        'context': ctx,
        'type': 'ir.actions.act_window',
        'target': 'current',
    }

当我点击此按钮时,我得到了

Integrity Error

The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it
- creation/update: a mandatory field is not correctly set

[object with reference: name - name] 

在我的服务器日志中我有

2014-12-31 08:18:40,566 7407 ERROR new_db openerp.sql_db: bad query: insert into "product_template" (id,"supply_method","list_price","standard_price","mes_type","uom_id","cost_method","categ_id","uos_coeff","sale_delay","procure_method","sale_ok","company_id","produce_delay","uom_po_id","rental","type",create_uid,create_date,write_uid,write_date) values (639,'buy','1.00','0.00','fixed',1,'standard','9','1.000',7.0,'make_to_stock','True',1,1.0,1,'False','consu',1,(now() at time zone 'UTC'),1,(now() at time zone 'UTC'))
Traceback (most recent call last):
  File "/opt/openerp/server/openerp/sql_db.py", line 226, in execute
    res = self._obj.execute(query, params)
IntegrityError: null value in column "name" violates not-null constraint
DETAIL:  Failing row contains (639, 1, 2014-12-31 08:18:40.463017, 2014-12-31 08:18:40.463017, 1, null, null, 1.00, null, null, null, 0.00, fixed, 1, null, standard, 9, null, 1.000, null, t, null, null, 1, null, 1, 1, f, consu, null, null, 7, null, buy, make_to_stock).

2014-12-31 08:18:40,569 7407 ERROR new_db openerp.netsvc: Integrity Error
The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it
- creation/update: a mandatory field is not correctly set

[object with reference: name - name]
Traceback (most recent call last):
  File "/opt/openerp/server/openerp/netsvc.py", line 296, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/opt/openerp/server/openerp/service/web_services.py", line 626, in dispatch
    res = fn(db, uid, *params)
  File "/opt/openerp/server/openerp/osv/osv.py", line 190, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/opt/openerp/server/openerp/osv/osv.py", line 174, in wrapper
    netsvc.abort_response(1, _('Integrity Error'), 'warning', msg)
  File "/opt/openerp/server/openerp/netsvc.py", line 71, in abort_response
    raise openerp.osv.osv.except_osv(description, details)
except_osv: ('Integrity Error', 'The operation cannot be completed, probably due to the following:\n- deletion: you may be trying to delete a record while other records still reference it\n- creation/update: a mandatory field is not correctly set\n\n[object with reference: name - name]')

我的第一个问题是。为什么我的sql insert命令出错,尽管没有像creates方法那样的插入。它只是打开一个表单,我将按下保存按钮或其他东西以节省价值。 其次,我如何绕过这个并转到我可以创建项目的下一步。

注意:我也有编辑,查看方法和按钮,只需在查看和编辑模式下打开值。但也有同样的问题。

修改

有一点我必须提到。我有print "\n\n Inside Create Method"  在creater方法。它永远不会显示在我的服务器控制台/终端上。

EDIT1 deg_form有`_inherit ='product.product'

1 个答案:

答案 0 :(得分:1)

我很确定你班上的_inherit='product.product'打破了这些事情。

您的原始表单(不是您尝试使用按钮打开的表单)正在尝试在执行按钮操作之前保存对象。由于此表单处理的是继承产品。产品&#39;,您的表单正在尝试使用&product;产品&#39; (并分别在 - &lt; product_template&#39;)表中。我认为您的表单没有提供足够的字段来满足所需的产品_模板&#39;字段。

您确定需要继承吗?在我看来,你不需要它。

建议:在代码中使用print()代替使用PDB:

import pdb; pdb.set_trace()

它非常强大,并且对OpenERP有很大的帮助。