Odoo 中文社区

    • 注册
    • 登录
    • 搜索
    • 版块
    • 标签
    • 热门
    • 用户
    • 群组

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

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

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

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

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

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

    Odoo 开发与实施交流
    3
    8
    4903
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • J
      jerry79 最后由 编辑

      此问题已经参考此页面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
        wangpc 最后由 编辑

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

        1 条回复 最后回复 回复 引用 0
        • J
          jerry79 最后由 编辑

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

          1 条回复 最后回复 回复 引用 0
          • mrshelly
            mrshelly 最后由 编辑

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

            能分享一下 结果吗?

            1 条回复 最后回复 回复 引用 0
            • W
              wangpc 最后由 编辑

              [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
                jerry79 最后由 编辑

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

                1 条回复 最后回复 回复 引用 0
                • J
                  jerry79 最后由 编辑

                  [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
                  • First post
                    Last post