产品类别不能删除的Bug
-
产品类别下的所有产品已经删除,但该类别不能删除,错误日志:
Traceback (most recent call last):
File "modules\gui\main.pyo", line 1334, in _sig_child_call
File "modules\gui\window\form.pyo", line 263, in sig_remove
File "widget\screen\screen.pyo", line 522, in remove
File "rpc.pyo", line 349, in call
File "rpc.pyo", line 170, in rpc_exec_auth
File "rpc.pyo", line 113, in exec_auth
File "rpc.pyo", line 119, in execute
File "tiny_socket.pyo", line 81, in myreceive
tiny_socket.Myexception: ('warning -- Integrity Error\n\nnull value in column "categ_id" violates not-null constraint\nCONTEXT: SQL statement "UPDATE ONLY "public"."product_template" SET "categ_id" = NULL WHERE $1 OPERATOR(pg_catalog.=) "categ_id""\n', 'Traceback (most recent call last):\n File "netsvc.pyo", line 256, in dispatch\n File "netsvc.pyo", line 76, in call\n File "service\web_services.pyo", line 577, in execute\n File "osv\osv.pyo", line 70, in wrapper\n File "netsvc.pyo", line 61, in abortResponse\nException: warning -- Integrity Error\n\nnull value in column "categ_id" violates not-null constraint\nCONTEXT: SQL statement "UPDATE ONLY "public"."product_template" SET "categ_id" = NULL WHERE $1 OPERATOR(pg_catalog.=) "categ_id""\n\n')
原因是当product.product记录删除后,product.template并没有跟着删除
附修复记录的脚本,请在执行时先做好备份,本人不对该脚本产生的任何后果负责。<br /># -*- encoding: utf-8 -*-<br />#修复删除产品后product.template记录没有删除的数据<br /><br />import xmlrpclib #导入xmlrpc库,这个库是python的标准库。<br />#dbname = raw_input(u"输入帐套:\n")<br />dbname = 'xxxxxx'<br />username ='admin' #用户登录名<br />pwd = 'xxxxxxx' #用户的登录密码,测试时请换成自己的密码<br /><br /># 第一步,取得uid<br />sock_common = xmlrpclib.ServerProxy ('http://127.0.0.1:8069/xmlrpc/common')<br />uid = sock_common.login(dbname, username, pwd)<br />sock = xmlrpclib.ServerProxy('http://127.0.0.1:8069/xmlrpc/object')<br /><br />p_ids = sock.execute(dbname, uid, pwd, 'product.product', 'search',[],0,20000,'id')<br />print p_ids<br />vals = sock.execute(dbname, uid, pwd,'product.product', 'read', p_ids,['id','name','product_tmpl_id'])<br />t_idok=[]<br />for v in vals:<br /> t_idok.append(v['product_tmpl_id'][0])<br />print u'product_tmpl_id 列表'<br />print t_idok<br /><br />del_t=sock.execute(dbname, uid, pwd, 'product.template', 'search',[('id','not in',t_idok)])<br />ok_t=sock.execute(dbname, uid, pwd, 'product.template', 'search',[('id','in',t_idok)])<br />print '正常的 product_tmpl_id 列表'<br />print ok_t<br />print '不存在的 product_tmpl_id 列表-'<br />print del_t<br />sock.execute(dbname, uid, pwd, 'product.template', 'unlink',del_t)<br />print u"设置完成"<br /><br />
修复记录不是最终的解决方案,请哪位大虾提供下修复的方案!!! -
最简单的莫过于 去数据库里, 修改 product_template 表结构 中的 categ_id 字段 把"非空"的勾选去掉...
或者修改 addons\product\product.py 文件中 product.template 对象的 categ_id 字段的 required="True" 去掉, 或者改为 "False" 然后 重新更新模块(是否更新有效, 需要小白鼠测试")