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
1=== modified file 'mrp/procurement.py'
2--- mrp/procurement.py 2011-09-17 16:41:25 +0000
3+++ mrp/procurement.py 2013-03-25 06:48:22 +0000
4@@ -25,6 +25,8 @@
5 from osv import osv
6 from tools.translate import _
7 import netsvc
8+import itertools
9+from collections import defaultdict
10
11 class procurement_order(osv.osv):
12 _inherit = 'procurement.order'
13@@ -104,7 +106,55 @@
14 move_obj.write(cr, uid, [res_id],
15 {'location_id': procurement.location_id.id})
16 return res
17-
18+
19+ def _procure_orderpoint_confirm(self, cr, uid, automatic=False, use_new_cursor=False, \
20+ context=None, user_id=False, orderpoint_ids=None):
21+ orderpoint_obj = self.pool.get('stock.warehouse.orderpoint')
22+ mrp_bom_obj = self.pool.get('mrp.bom')
23+
24+ # List all components of each product
25+ bom_ids = mrp_bom_obj.search(cr, uid, [('bom_id', '=', False), ('method', '=', 'stock')], context=context)
26+ bom_contents = defaultdict(set)
27+ for bom in mrp_bom_obj.browse(cr, uid, bom_ids, context=context):
28+ bom_contents[bom.product_id.id] |= set([tmp_bom.product_id.id for tmp_bom in bom.bom_lines])
29+
30+ # Order product by level of bom
31+ product_by_level = {}
32+ current_level = 0
33+ while bom_contents:
34+ # List all produced products to process
35+ current_product_ids = set(bom_contents.keys())
36+ # List all components to process
37+ current_product_components = set(itertools.chain.from_iterable(bom_contents.values()))
38+ # List products to process for the current level
39+ current_product_level = current_product_ids - current_product_components
40+ # Protect against recursive boms : Add products which are in products AND components to current level
41+ current_product_level |= current_product_ids & current_product_components
42+ product_by_level[current_level] = list(current_product_level)
43+ current_level += 1
44+ # Remove the processed products from the list
45+ for product_id in current_product_level:
46+ del bom_contents[product_id]
47+
48+ # Compute all bom products, ordered by level
49+ for level, product_ids in sorted(product_by_level.items()):
50+ orderpoint_ids = orderpoint_obj.search(cr, uid, [('product_id', 'in', product_ids)], context=context)
51+ super(procurement_order, self)._procure_orderpoint_confirm(
52+ cr, uid, automatic=automatic, use_new_cursor=use_new_cursor, \
53+ context=context, user_id=user_id, orderpoint_ids=orderpoint_ids)
54+
55+ # Confirm all new procurements
56+ self._procure_confirm(cr, uid, use_new_cursor=use_new_cursor, context=context)
57+
58+ # Compute non bom products
59+ product_ids = list(set(itertools.chain.from_iterable(product_by_level.values())))
60+ orderpoint_ids = orderpoint_obj.search(cr, uid, [('product_id', 'not in', product_ids)], context=context)
61+ ret = super(procurement_order, self)._procure_orderpoint_confirm(
62+ cr, uid, automatic=automatic, use_new_cursor=use_new_cursor, \
63+ context=context, user_id=user_id, orderpoint_ids=orderpoint_ids)
64+
65+ return ret
66+
67 procurement_order()
68
69 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
70
71=== modified file 'procurement/schedulers.py'
72--- procurement/schedulers.py 2012-03-16 13:40:52 +0000
73+++ procurement/schedulers.py 2013-03-25 06:48:22 +0000
74@@ -217,7 +217,7 @@
75 'origin': orderpoint.name}
76
77 def _procure_orderpoint_confirm(self, cr, uid, automatic=False,\
78- use_new_cursor=False, context=None, user_id=False):
79+ use_new_cursor=False, context=None, user_id=False, orderpoint_ids=None):
80 '''
81 Create procurement based on Orderpoint
82 use_new_cursor: False or the dbname
83@@ -242,10 +242,13 @@
84 report = []
85 offset = 0
86 ids = [1]
87+ orderpoint_domain = []
88+ if orderpoint_ids is not None:
89+ orderpoint_domain = [('id', 'in', orderpoint_ids)]
90 if automatic:
91 self.create_automatic_op(cr, uid, context=context)
92 while ids:
93- ids = orderpoint_obj.search(cr, uid, [], offset=offset, limit=100)
94+ ids = orderpoint_obj.search(cr, uid, orderpoint_domain, offset=offset, limit=100)
95 for op in orderpoint_obj.browse(cr, uid, ids, context=context):
96 if op.procurement_id.state != 'exception':
97 if op.procurement_id and op.procurement_id.purchase_id and op.procurement_id.purchase_id.state in ('draft', 'confirmed'):