关于OpenERP里面的线程问题
-
今日研究OpenERP的mrp,想重写下这个方法,因为当我运行mrp的时候会自动生成PO,但是他们是一个个地通过make_po生成,如果我想一次过将这次运行mrp所有缺货的产品,不成功,因为里面调用make_po是逐个id调用的
对于python的线程不是很了解,跟踪代码的时候发现id是一个个传过来,运行下图的代码是这个
问题:如何可以一次过得到所有的Procurement Order<br />class procurement_compute_all(osv.osv_memory):<br /> _name = 'procurement.order.compute.all'<br /> _description = 'Compute all schedulers'<br /><br /> _columns = {<br /> 'automatic': fields.boolean('Automatic orderpoint',help='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.'),<br /> }<br /><br /> _defaults = {<br /> 'automatic': lambda *a: False,<br /> }<br /><br /> def _procure_calculation_all(self, cr, uid, ids, context=None):<br /> """<br /> @param self: The object pointer.<br /> @param cr: A database cursor<br /> @param uid: ID of the user currently logged in<br /> @param ids: List of IDs selected<br /> @param context: A standard dictionary<br /> """<br /> proc_obj = self.pool.get('procurement.order')<br /> for proc in self.browse(cr, uid, ids, context=context):<br /> proc_obj.run_scheduler(cr, uid, automatic=proc.automatic, use_new_cursor=cr.dbname,\<br /> context=context)<br /> return {}<br /><br /> def procure_calculation(self, cr, uid, ids, context=None):<br /> """<br /> @param self: The object pointer.<br /> @param cr: A database cursor<br /> @param uid: ID of the user currently logged in<br /> @param ids: List of IDs selected<br /> @param context: A standard dictionary<br /> """<br /> threaded_calculation = threading.Thread(target=self._procure_calculation_all, args=(cr, uid, ids, context))<br /> threaded_calculation.start()<br /> return {'type': 'ir.actions.act_window_close'}<br /><br />procurement_compute_all()<br /><br /># vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:<br />
[attachimg=1] -
应该与 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 -
的确与线程无关。make_po是procurement order的一个方法, 而每个procuement order只与一个产品相关,生成的PO必然是:一个产品一个PO
一个简单的解决方法,也是给当前客户实施采用的方法是:重载run_scheduler, 在其中增加merge po的逻辑(可以调用purchase.order中的do_merge方法),将生成的单个产品的PO按照产品对应的供应商设置进行合并。