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

由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

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

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

如何删除sql_constraints?



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



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

    <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 />
    



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



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



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



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


Log in to reply