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

原论坛用户的基本信息和发帖这里都予以保留,请注意:原论坛用户无需重新注册新用户,但是您的密码需要重置

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

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

关于OpenERP里面的线程问题


  • 管理员

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

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

    <br />[attachimg=1]



  • 应该与 python 线程无关...<br /><br />参考  <br />addons\procurement\schedulers.py (OE server 6.0.2)<br /><br />            procurement_obj = self.pool.get('procurement.order')<br />            if not ids:<br />                ids = procurement_obj.search(cr, uid, [], order="date_planned")<br /><br />可以得到 需要处理的 procurement.order


  • 管理员

    的确与线程无关。make_po是procurement order的一个方法, 而每个procuement order只与一个产品相关,生成的PO必然是:一个产品一个PO<br /><br />一个简单的解决方法,也是给当前客户实施采用的方法是:重载run_scheduler, 在其中增加merge po的逻辑(可以调用purchase.order中的do_merge方法),将生成的单个产品的PO按照产品对应的供应商设置进行合并。<br />


  • 管理员

    谢谢各位回复,确实与线程无关。 😞