Odoo中文社区可以通过以下三个域名访问:shine-it.net , odoocn.org,odoo.net.cn

原论坛用户的基本信息和发帖这里都予以保留,请注意:原论坛用户无需重新注册新用户,但是您的密码需要重置

开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

如果您登录系统碰到问题,请在微信公众号留言:

如何删除sql_constraints?



  • HornERP2.0的测试者提出系统不支持负数凭证,这对于中国会计来说是个比较大的问题。经分析发现accoun.py中有<br />('credit_debit2', 'CHECK (credit+debit>=0)', 'Wrong credit or debit value in model !'),<br />这样一句,也就是说金额小于零就会报错。<br />这样设计估计是为了集成过账方便设计,但总账这边手工输入凭证的话不能负数确实不太合理。所以请大家帮忙想一下如何不修改原有account模块通过继承的方式去掉这个sql_constraints



  • 试了一下用继承的方式, 没效果, 看了一下orm.py里面对sql_constraint是这么处理的<br />

    <br />&nbsp; &nbsp; &nbsp; &nbsp; for (key, con, _) in self._sql_constraints:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conname = &#039;%s_%s&#039; % (self._table, key)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cr.execute(&quot;SELECT conname FROM pg_constraint where conname=%s&quot;, (conname,))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if not cr.dictfetchall():<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; query = &#039;ALTER TABLE &quot;%s&quot; ADD CONSTRAINT &quot;%s&quot; %s&#039; % (self._table, conname, con,)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cr.execute(query)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cr.commit()<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; except:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.notifyChannel(&#039;orm&#039;, netsvc.LOG_WARNING, &#039;unable to add \&#039;%s\&#039; constraint on table %s !\n If you want to have it, you should update the records and execute manually:\n%s&#039; % (con, self._table, query))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cr.rollback()<br /><br />
    

    <br /><br />就是先前的check如果存在的话是不会被覆盖掉的, 最简单就是改account.py里面的, 然后手动把pg里面的去掉



  • 用ir.actions.todo暴力删除了。<br />            if o.allow == 'yes':<br />                cr.execute("ALTER TABLE account_move_line DROP CONSTRAINT account_move_line_credit_debit2")<br />                cr.commit()



  • 暴力删除也是个方案。 呵呵, 俺没想到



  • 这个需求可以到官方发个.