跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • 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. 工作流trigger问题求助(已改用subflow方式,已补充流程说明)

工作流trigger问题求助(已改用subflow方式,已补充流程说明)

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

    此问题已经参考此页面http://cn.openerp.cn/workflow%E4%B8%AD%E7%9A%84%E9%9D%9E%E5%85%B8%E5%9E%8B%E8%87%AA%E5%8A%A8%E8%A7%A6%E5%8F%91%E5%99%A8trigger_model/

    问题描述:我希望实现的功能是,在sale.order流程中,progress状态下,当发票状态为paid,同时合同(自定义类)状态为done时,sale.order状态自动变为done。
    参考上述页面,首先实现一个状态的trigger,代码实现如下:
    workflow.xml

    <br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;!--活动定义--&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;record id=&quot;act_progress&quot; model=&quot;workflow.activity&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;wkf_id&quot; ref=&quot;wkf_sale&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;name&quot;&gt;progress&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;kind&quot;&gt;function&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;action&quot;&gt;action_validate()&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;/record&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;record id=&quot;act_done&quot; model=&quot;workflow.activity&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;wkf_id&quot; ref=&quot;wkf_sale&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;name&quot;&gt;done&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;flow_stop&quot;&gt;True&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;kind&quot;&gt;function&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;action&quot;&gt;action_done()&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;/record&gt;<br />&nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;!--迁移--&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;record id=&quot;trans_progress_done&quot; model=&quot;workflow.transition&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;act_from&quot; ref=&quot;act_progress&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;act_to&quot; ref=&quot;act_done&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;condition&quot;&gt;check_progress_state(&#039;done&#039;)&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;trigger_model&quot;&gt;account.invoice&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;trigger_expr_id&quot;&gt;invoice_id and [invoice_id.id] or &#91;]&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;/record&gt;<br />
    



    sale.py

    <br /> #字段定义<br />&nbsp; &#039;invoice_id&#039;: fields.many2one(&#039;account.invoice&#039;, &#039;关联付款&#039;),<br /> <br /> #函数定义<br /> def action_done(self, cr, uid, ids, context=None):<br />&nbsp; &nbsp; &nbsp; &nbsp; wf_service = netsvc.LocalService(&quot;workflow&quot;)<br />&nbsp; &nbsp; &nbsp; &nbsp; for o_id in ids:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wf_service.trg_trigger(uid, &#039;sale.order&#039;, o_id, cr)<br />&nbsp; &nbsp; &nbsp; &nbsp; self.write(cr, uid, ids, {&#039;state&#039;: &#039;done&#039;})<br />&nbsp; &nbsp; &nbsp; &nbsp; return True<br />
    



    现在的问题还是,trigger执行了一次就不在执行第二次了,请问应该是哪里的问题呢?
    另外,如果我想实现两个状态的trigger,应该怎么做呢?
    谢谢!

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

      楼主为何要执迷用trg_trigger这个方法来做触发器呢,在sale.order的工作中被关联的对象account.invoice中有定义subflow,通过信号subflow.pad和sale.orde通信,你可以修改sale.order.basic这个工作流来完成你的要求,楼主可以一试

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

        非常感谢,使用subflow的方式成功实现了,而且思路和方法非常清晰。
        trgger的思路理论上应该更简单,但是实现上确实有迷惑的地方。

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

          [quote author=jerry79 link=topic=12684.msg23044#msg23044 date=1382261337]
          非常感谢,使用subflow的方式成功实现了,而且思路和方法非常清晰。
          trgger的思路理论上应该更简单,但是实现上确实有迷惑的地方。
          [/quote]

          能分享一下 结果吗?

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

            [quote author=jerry79 link=topic=12684.msg22995#msg22995 date=1381995871]
            问题描述:我希望实现的功能是,在sale.order流程中,progress状态下,当发票状态为paid,同时合同(自定义类)状态为done时,sale.order状态自动变为done。
            [/quote]

            LZ 你描述的这个问题不够清楚合同(自定义类)状态为done时,请问这个合同是什么?在sale.order.basic中,sale.order状态自动变为done的这个节点中定义了Join Mode 为and ,也就是说这个and就是判断了只有在Delivered和发票状态为paid时候sale.order状态自动变为done。望解释一下你自定义的合同(自定义类)是什么,我们一起探讨一下怎么使用workflow.wkf_service的方法来实现,
            [检测到链接无效,已移除]

            1 条回复 最后回复
            0
            • J 离线
              J 离线
              jerry79
              写于 最后由 编辑
              #6

              因时间关系,现在才完成流程的说明文字,放在我的博客:http://www.cnblogs.com/jerry2005/p/3392302.html ,欢迎拍砖。

              1 条回复 最后回复
              0
              • J 离线
                J 离线
                jerry79
                写于 最后由 编辑
                #7

                [quote author=baggiow link=topic=12684.msg23050#msg23050 date=1382322465]
                [quote author=jerry79 link=topic=12684.msg22995#msg22995 date=1381995871]
                问题描述:我希望实现的功能是,在sale.order流程中,progress状态下,当发票状态为paid,同时合同(自定义类)状态为done时,sale.order状态自动变为done。
                [/quote]

                LZ 你描述的这个问题不够清楚合同(自定义类)状态为done时,请问这个合同是什么?在sale.order.basic中,sale.order状态自动变为done的这个节点中定义了Join Mode 为and ,也就是说这个and就是判断了只有在Delivered和发票状态为paid时候sale.order状态自动变为done。望解释一下你自定义的合同(自定义类)是什么,我们一起探讨一下怎么使用workflow.wkf_service的方法来实现,
                [检测到链接无效,已移除]
                [/quote]

                我补充了我的流程的简化版,我想实现的也是希望合同和发票都完成后,订单才变为done,请参考我的博客的说明。
                另外,经过两种方法的比较,我现在觉得subflow模式更加清晰明了,而trigger方式还需要修改py文件,比较麻烦。

                1 条回复 最后回复
                0

                • 登录

                • 没有帐号? 注册

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