跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • 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. 关于OpenERP里面的线程问题

关于OpenERP里面的线程问题

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

    今日研究OpenERP的mrp,想重写下这个方法,因为当我运行mrp的时候会自动生成PO,但是他们是一个个地通过make_po生成,如果我想一次过将这次运行mrp所有缺货的产品,不成功,因为里面调用make_po是逐个id调用的
    对于python的线程不是很了解,跟踪代码的时候发现id是一个个传过来,运行下图的代码是这个
    问题:如何可以一次过得到所有的Procurement Order

    <br />class procurement_compute_all(osv.osv_memory):<br />&nbsp; &nbsp; _name = &#039;procurement.order.compute.all&#039;<br />&nbsp; &nbsp; _description = &#039;Compute all schedulers&#039;<br /><br />&nbsp; &nbsp; _columns = {<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;automatic&#039;: fields.boolean(&#039;Automatic orderpoint&#039;,help=&#039;Triggers an automatic procurement for all products that have a virtual stock under 0. You should probably not use this option, we suggest using a MTO configuration on products.&#039;),<br />&nbsp; &nbsp; }<br /><br />&nbsp; &nbsp; _defaults = {<br />&nbsp; &nbsp; &nbsp; &nbsp;  &#039;automatic&#039;: lambda *a: False,<br />&nbsp; &nbsp; }<br /><br />&nbsp; &nbsp; def _procure_calculation_all(self, cr, uid, ids, context=None):<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; @param self: The object pointer.<br />&nbsp; &nbsp; &nbsp; &nbsp; @param cr: A database cursor<br />&nbsp; &nbsp; &nbsp; &nbsp; @param uid: ID of the user currently logged in<br />&nbsp; &nbsp; &nbsp; &nbsp; @param ids: List of IDs selected<br />&nbsp; &nbsp; &nbsp; &nbsp; @param context: A standard dictionary<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; proc_obj = self.pool.get(&#039;procurement.order&#039;)<br />&nbsp; &nbsp; &nbsp; &nbsp; for proc in self.browse(cr, uid, ids, context=context):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proc_obj.run_scheduler(cr, uid, automatic=proc.automatic, use_new_cursor=cr.dbname,\<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; context=context)<br />&nbsp; &nbsp; &nbsp; &nbsp; return {}<br /><br />&nbsp; &nbsp; def procure_calculation(self, cr, uid, ids, context=None):<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; @param self: The object pointer.<br />&nbsp; &nbsp; &nbsp; &nbsp; @param cr: A database cursor<br />&nbsp; &nbsp; &nbsp; &nbsp; @param uid: ID of the user currently logged in<br />&nbsp; &nbsp; &nbsp; &nbsp; @param ids: List of IDs selected<br />&nbsp; &nbsp; &nbsp; &nbsp; @param context: A standard dictionary<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; threaded_calculation = threading.Thread(target=self._procure_calculation_all, args=(cr, uid, ids, context))<br />&nbsp; &nbsp; &nbsp; &nbsp; threaded_calculation.start()<br />&nbsp; &nbsp; &nbsp; &nbsp; return {&#039;type&#039;: &#039;ir.actions.act_window_close&#039;}<br /><br />procurement_compute_all()<br /><br /># vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:<br />
    


    [attachimg=1]

    【上海先安科技】(joshua AT openerp.cn),欢迎关注公众号:openerp_cn

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

      应该与 python 线程无关...

      参考 
      addons\procurement\schedulers.py (OE server 6.0.2)

                  procurement_obj = self.pool.get('procurement.order')
                  if not ids:
                      ids = procurement_obj.search(cr, uid, [], order="date_planned")

      可以得到 需要处理的 procurement.order

      1 条回复 最后回复
      0
      • digitalsatoriD 离线
        digitalsatoriD 离线
        digitalsatori 管理员
        写于 最后由 编辑
        #3

        的确与线程无关。make_po是procurement order的一个方法, 而每个procuement order只与一个产品相关,生成的PO必然是:一个产品一个PO

        一个简单的解决方法,也是给当前客户实施采用的方法是:重载run_scheduler, 在其中增加merge po的逻辑(可以调用purchase.order中的do_merge方法),将生成的单个产品的PO按照产品对应的供应商设置进行合并。

        【上海先安科技】(tony AT openerp.cn)

        1 条回复 最后回复
        0
        • JoshuaJ 离线
          JoshuaJ 离线
          Joshua 管理员
          写于 最后由 编辑
          #4

          谢谢各位回复,确实与线程无关。 :-[

          【上海先安科技】(joshua AT openerp.cn),欢迎关注公众号:openerp_cn

          1 条回复 最后回复
          0

          • 登录

          • 没有帐号? 注册

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