跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(Flatly)
  • 不使用皮肤
折叠

Odoo 中文社区

  1. 主页
  2. 版块
  3. Odoo 开发与实施交流
  4. 如何删除sql_constraints?

如何删除sql_constraints?

已定时 已固定 已锁定 已移动 Odoo 开发与实施交流
6 帖子 3 发布者 5.6k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • wjfonhandW 离线
    wjfonhandW 离线
    wjfonhand
    写于 最后由 编辑
    #1

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

    GoodERP -- Odoo China fork

    1 条回复 最后回复
    0
    • O 离线
      O 离线
      onetown
      写于 最后由 编辑
      #2

      试了一下用继承的方式, 没效果, 看了一下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里面的去掉

      1 条回复 最后回复
      0
      • wjfonhandW 离线
        wjfonhandW 离线
        wjfonhand
        写于 最后由 编辑
        #3

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

        GoodERP -- Odoo China fork

        1 条回复 最后回复
        0
        • O 离线
          O 离线
          onetown
          写于 最后由 编辑
          #4

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

          1 条回复 最后回复
          0
          • mrshellyM 离线
            mrshellyM 离线
            mrshelly
            写于 最后由 编辑
            #5

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

            1 条回复 最后回复
            0

            • 登录

            • 没有帐号? 注册

            • 登录或注册以进行搜索。
            • 第一个帖子
              最后一个帖子
            0
            • 版块
            • 标签
            • 热门
            • 用户
            • 群组