[IMP] Query should pass through orm and as such the refreshes can be removed in the...
[odoo/odoo.git] / addons / procurement / procurement.py
index 5a73ef1..085d620 100644 (file)
@@ -65,7 +65,7 @@ class procurement_group(osv.osv):
     }
     _defaults = {
         'name': lambda self, cr, uid, c: self.pool.get('ir.sequence').get(cr, uid, 'procurement.group') or '',
-        'move_type': lambda self, cr, uid, c: 'one'
+        'move_type': lambda self, cr, uid, c: 'direct'
     }
 
 class procurement_rule(osv.osv):
@@ -110,9 +110,9 @@ class procurement_order(osv.osv):
     _columns = {
         'name': fields.text('Description', required=True),
 
-        'origin': fields.char('Source Document', size=64,
+        'origin': fields.char('Source Document',
             help="Reference of the document that created this Procurement.\n"
-            "This is automatically completed by OpenERP."),
+            "This is automatically completed by Odoo."),
         'company_id': fields.many2one('res.company', 'Company', required=True),
 
         # These two fields are used for shceduling
@@ -135,7 +135,7 @@ class procurement_order(osv.osv):
             ('exception', 'Exception'),
             ('running', 'Running'),
             ('done', 'Done')
-        ], 'Status', required=True, track_visibility='onchange'),
+        ], 'Status', required=True, track_visibility='onchange', copy=False),
     }
 
     _defaults = {
@@ -196,14 +196,13 @@ class procurement_order(osv.osv):
 
     def run(self, cr, uid, ids, autocommit=False, context=None):
         for procurement_id in ids:
-            #we intentionnaly do the browse under the for loop to avoid caching all ids which would be ressource greedy
+            #we intentionnaly do the browse under the for loop to avoid caching all ids which would be resource greedy
             #and useless as we'll make a refresh later that will invalidate all the cache (and thus the next iteration
             #will fetch all the ids again) 
             procurement = self.browse(cr, uid, procurement_id, context=context)
             if procurement.state not in ("running", "done"):
                 try:
                     if self._assign(cr, uid, procurement, context=context):
-                        procurement.refresh()
                         res = self._run(cr, uid, procurement, context=context or {})
                         if res:
                             self.write(cr, uid, [procurement.id], {'state': 'running'}, context=context)
@@ -286,7 +285,7 @@ class procurement_order(osv.osv):
     #
     # Scheduler
     #
-    def run_scheduler(self, cr, uid, use_new_cursor=False, context=None):
+    def run_scheduler(self, cr, uid, use_new_cursor=False, company_id = False, context=None):
         '''
         Call the scheduler to check the procurement order. This is intented to be done for all existing companies at
         the same time, so we're running all the methods as SUPERUSER to avoid intercompany and access rights issues.
@@ -307,9 +306,12 @@ class procurement_order(osv.osv):
                 cr = openerp.registry(cr.dbname).cursor()
 
             # Run confirmed procurements
+            dom = [('state', '=', 'confirmed')]
+            if company_id:
+                dom += [('company_id', '=', company_id)]
             prev_ids = []
             while True:
-                ids = self.search(cr, SUPERUSER_ID, [('state', '=', 'confirmed')], context=context)
+                ids = self.search(cr, SUPERUSER_ID, dom, context=context)
                 if not ids or prev_ids == ids:
                     break
                 else:
@@ -319,9 +321,13 @@ class procurement_order(osv.osv):
                     cr.commit()
 
             # Check if running procurements are done
+            offset = 0
+            dom = [('state', '=', 'running')]
+            if company_id:
+                dom += [('company_id', '=', company_id)]
             prev_ids = []
             while True:
-                ids = self.search(cr, SUPERUSER_ID, [('state', '=', 'running')], context=context)
+                ids = self.search(cr, SUPERUSER_ID, dom, offset=offset, context=context)
                 if not ids or prev_ids == ids:
                     break
                 else: