Merge lp:~openerp-dev/openobject-addons/6.1-opw-590227 into lp:openobject-addons/6.1

Proposed by Ravish(OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-addons/6.1-opw-590227
Merge into: lp:openobject-addons/6.1
Diff against target: 97 lines (+56/-3)
2 files modified
mrp/procurement.py (+51/-1)
procurement/schedulers.py (+5/-2)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/6.1-opw-590227
Reviewer Review Type Date Requested Status
Naresh(OpenERP) Pending
Review via email: mp+155174@code.launchpad.net

Description of the change

Hello,

Fix the issue of : "Need to run scheduler multiple times"

Thank you..

To post a comment you must log in.

Unmerged revisions

7191. By Ravish(OpenERP)

[MERGE]Merged with 6.1

7190. By Sylvain Garancher

[FIX] Need to run scheduler many time

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'mrp/procurement.py'
--- mrp/procurement.py 2011-09-17 16:41:25 +0000
+++ mrp/procurement.py 2013-03-25 06:48:22 +0000
@@ -25,6 +25,8 @@
25from osv import osv25from osv import osv
26from tools.translate import _26from tools.translate import _
27import netsvc27import netsvc
28import itertools
29from collections import defaultdict
2830
29class procurement_order(osv.osv):31class procurement_order(osv.osv):
30 _inherit = 'procurement.order'32 _inherit = 'procurement.order'
@@ -104,7 +106,55 @@
104 move_obj.write(cr, uid, [res_id],106 move_obj.write(cr, uid, [res_id],
105 {'location_id': procurement.location_id.id})107 {'location_id': procurement.location_id.id})
106 return res108 return res
107 109
110 def _procure_orderpoint_confirm(self, cr, uid, automatic=False, use_new_cursor=False, \
111 context=None, user_id=False, orderpoint_ids=None):
112 orderpoint_obj = self.pool.get('stock.warehouse.orderpoint')
113 mrp_bom_obj = self.pool.get('mrp.bom')
114
115 # List all components of each product
116 bom_ids = mrp_bom_obj.search(cr, uid, [('bom_id', '=', False), ('method', '=', 'stock')], context=context)
117 bom_contents = defaultdict(set)
118 for bom in mrp_bom_obj.browse(cr, uid, bom_ids, context=context):
119 bom_contents[bom.product_id.id] |= set([tmp_bom.product_id.id for tmp_bom in bom.bom_lines])
120
121 # Order product by level of bom
122 product_by_level = {}
123 current_level = 0
124 while bom_contents:
125 # List all produced products to process
126 current_product_ids = set(bom_contents.keys())
127 # List all components to process
128 current_product_components = set(itertools.chain.from_iterable(bom_contents.values()))
129 # List products to process for the current level
130 current_product_level = current_product_ids - current_product_components
131 # Protect against recursive boms : Add products which are in products AND components to current level
132 current_product_level |= current_product_ids & current_product_components
133 product_by_level[current_level] = list(current_product_level)
134 current_level += 1
135 # Remove the processed products from the list
136 for product_id in current_product_level:
137 del bom_contents[product_id]
138
139 # Compute all bom products, ordered by level
140 for level, product_ids in sorted(product_by_level.items()):
141 orderpoint_ids = orderpoint_obj.search(cr, uid, [('product_id', 'in', product_ids)], context=context)
142 super(procurement_order, self)._procure_orderpoint_confirm(
143 cr, uid, automatic=automatic, use_new_cursor=use_new_cursor, \
144 context=context, user_id=user_id, orderpoint_ids=orderpoint_ids)
145
146 # Confirm all new procurements
147 self._procure_confirm(cr, uid, use_new_cursor=use_new_cursor, context=context)
148
149 # Compute non bom products
150 product_ids = list(set(itertools.chain.from_iterable(product_by_level.values())))
151 orderpoint_ids = orderpoint_obj.search(cr, uid, [('product_id', 'not in', product_ids)], context=context)
152 ret = super(procurement_order, self)._procure_orderpoint_confirm(
153 cr, uid, automatic=automatic, use_new_cursor=use_new_cursor, \
154 context=context, user_id=user_id, orderpoint_ids=orderpoint_ids)
155
156 return ret
157
108procurement_order()158procurement_order()
109159
110# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:160# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
111161
=== modified file 'procurement/schedulers.py'
--- procurement/schedulers.py 2012-03-16 13:40:52 +0000
+++ procurement/schedulers.py 2013-03-25 06:48:22 +0000
@@ -217,7 +217,7 @@
217 'origin': orderpoint.name}217 'origin': orderpoint.name}
218218
219 def _procure_orderpoint_confirm(self, cr, uid, automatic=False,\219 def _procure_orderpoint_confirm(self, cr, uid, automatic=False,\
220 use_new_cursor=False, context=None, user_id=False):220 use_new_cursor=False, context=None, user_id=False, orderpoint_ids=None):
221 '''221 '''
222 Create procurement based on Orderpoint222 Create procurement based on Orderpoint
223 use_new_cursor: False or the dbname223 use_new_cursor: False or the dbname
@@ -242,10 +242,13 @@
242 report = []242 report = []
243 offset = 0243 offset = 0
244 ids = [1]244 ids = [1]
245 orderpoint_domain = []
246 if orderpoint_ids is not None:
247 orderpoint_domain = [('id', 'in', orderpoint_ids)]
245 if automatic:248 if automatic:
246 self.create_automatic_op(cr, uid, context=context)249 self.create_automatic_op(cr, uid, context=context)
247 while ids:250 while ids:
248 ids = orderpoint_obj.search(cr, uid, [], offset=offset, limit=100)251 ids = orderpoint_obj.search(cr, uid, orderpoint_domain, offset=offset, limit=100)
249 for op in orderpoint_obj.browse(cr, uid, ids, context=context):252 for op in orderpoint_obj.browse(cr, uid, ids, context=context):
250 if op.procurement_id.state != 'exception':253 if op.procurement_id.state != 'exception':
251 if op.procurement_id and op.procurement_id.purchase_id and op.procurement_id.purchase_id.state in ('draft', 'confirmed'):254 if op.procurement_id and op.procurement_id.purchase_id and op.procurement_id.purchase_id.state in ('draft', 'confirmed'):