← Back to team overview

openerp-india team mailing list archive

[Bug 915541] Re: [Trunk] Procurement request leads to server crash

 

=== modified file 'procurement/schedulers.py'
--- procurement/schedulers.py	2011-01-14 00:11:01 +0000
+++ procurement/schedulers.py	2012-01-18 19:01:57 +0000
@@ -53,13 +53,18 @@
 
             procurement_obj = self.pool.get('procurement.order')
             if not ids:
-                ids = procurement_obj.search(cr, uid, [], order="date_planned")
+                ids = procurement_obj.search(cr, uid,
+                    [('state', '=', 'exception')], order="date_planned")
             for id in ids:
-                wf_service.trg_validate(uid, 'procurement.order', id, 'button_restart', cr)
+                wf_service.trg_validate(uid, 'procurement.order',
+                    id, 'button_restart', cr)
             if use_new_cursor:
                 cr.commit()
-            company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id
-            maxdate = (datetime.today() + relativedelta(days=company.schedule_range)).strftime(tools.DEFAULT_SERVER_DATE_FORMAT)
+            company = self.pool.get('res.users').browse(cr, uid,
+                uid, context=context).company_id
+            maxdate = (datetime.today() + \
+                relativedelta(days=company.schedule_range)).\
+                strftime(tools.DEFAULT_SERVER_DATE_FORMAT)
             start_date = time.strftime('%Y-%m-%d, %Hh %Mm %Ss')
             offset = 0
             report = []
@@ -67,19 +72,25 @@
             report_except = 0
             report_later = 0
             while True:
-                cr.execute("select id from procurement_order where state='confirmed' and procure_method='make_to_order' order by priority,date_planned limit 500 offset %s", (offset,))
-                ids = map(lambda x: x[0], cr.fetchall())
-                for proc in procurement_obj.browse(cr, uid, ids, context=context):
+                ids = procurement_obj.search(cr, uid, [
+                    ('state', '=', 'confirmed'),
+                    ('procure_method', '=', 'make_to_order')
+                    ], offset=offset, limit=500,
+                    order='priority, date_planned', context=context
+                )
+                for proc in procurement_obj.browse(cr, uid, ids,
+                        context=context):
                     if maxdate >= proc.date_planned:
-                        wf_service.trg_validate(uid, 'procurement.order', proc.id, 'button_check', cr)
+                        wf_service.trg_validate(uid, 
+                            'procurement.order', proc.id, 'button_check', cr)
                     else:
-                        offset += 1
                         report_later += 1
-                for proc in procurement_obj.browse(cr, uid, ids, context=context):
+                    offset += 1
+
                     if proc.state == 'exception':
-                        report.append('PROC %d: on order - %3.2f %-5s - %s' % \
-                                (proc.id, proc.product_qty, proc.product_uom.name,
-                                    proc.product_id.name))
+                        report.append(_('PROC %d: on order - %3.2f %-5s - %s') % \
+                            (proc.id, proc.product_qty, proc.product_uom.name,
+                                proc.product_id.name))
                         report_except += 1
                     report_total += 1
                 if use_new_cursor:
@@ -90,20 +101,25 @@
             ids = []
             while True:
                 report_ids = []
-                ids = procurement_obj.search(cr, uid, [('state', '=', 'confirmed'), ('procure_method', '=', 'make_to_stock')], offset=offset)
+                ids = procurement_obj.search(cr, uid, [
+                    ('state', '=', 'confirmed'),
+                    ('procure_method', '=', 'make_to_stock')
+                ], offset=offset)
                 for proc in procurement_obj.browse(cr, uid, ids):
                     if maxdate >= proc.date_planned:
-                        wf_service.trg_validate(uid, 'procurement.order', proc.id, 'button_check', cr)
+                        wf_service.trg_validate(uid,
+                            'procurement.order', proc.id, 'button_check', cr)
                         report_ids.append(proc.id)
                     else:
                         report_later += 1
                     report_total += 1
-                for proc in procurement_obj.browse(cr, uid, report_ids, context=context):
+
                     if proc.state == 'exception':
-                        report.append('PROC %d: from stock - %3.2f %-5s - %s' % \
-                                (proc.id, proc.product_qty, proc.product_uom.name,
-                                    proc.product_id.name,))
+                        report.append(_('PROC %d: from stock - %3.2f %-5s - %s') % \
+                            (proc.id, proc.product_qty, proc.product_uom.name,
+                                proc.product_id.name,))
                         report_except += 1
+
                 if use_new_cursor:
                     cr.commit()
                 offset += len(ids)
@@ -111,22 +127,23 @@
             end_date = time.strftime('%Y-%m-%d, %Hh %Mm %Ss')
             if uid:
                 request = self.pool.get('res.request')
-                summary = '''Here is the procurement scheduling report.
-
-        Start Time: %s
-        End Time: %s
-        Total Procurements processed: %d
-        Procurements with exceptions: %d
-        Skipped Procurements (scheduled date outside of scheduler range) %d
-
-        Exceptions:\n'''% (start_date, end_date, report_total, report_except, report_later)
+                summary = _("""Here is the procurement scheduling report.
+
+        Start Time: %s 
+        End Time: %s 
+        Total Procurements processed: %d 
+        Procurements with exceptions: %d 
+        Skipped Procurements (scheduled date outside of scheduler range) %d 
+
+        Exceptions:\n""") % (start_date, end_date, report_total,
+                    report_except, report_later)
                 summary += '\n'.join(report)
-                request.create(cr, uid,
-                    {'name': "Procurement Processing Report.",
-                        'act_from': uid,
-                        'act_to': uid,
-                        'body': summary,
-                    })
+                request.create(cr, uid, {
+                    'name': "Procurement Processing Report.",
+                    'act_from': uid,
+                    'act_to': uid,
+                    'body': summary,
+                })
 
             if use_new_cursor:
                 cr.commit()
@@ -138,6 +155,7 @@
                     pass
         return {}

-- 
You received this bug notification because you are a member of OpenERP
Indian Team, which is subscribed to OpenERP Addons.
https://bugs.launchpad.net/bugs/915541

Title:
  [Trunk] Procurement request leads to server crash

Status in OpenERP Addons (modules):
  Fix Committed

Bug description:
  I'm using 6.0.3 in a french context and I'm currently filling my
  company database with supplier's products, currently I have 114000
  products in it.

  Some actions cannot be done like "procurement request" or "automatic
  orderpoint" because it results in a 100% python CPU process until my
  server crash, RAM (8Go) and SWAP(8Go) are filled both filled. The
  thread is stuck in get_product_available.

  === FIX ===

  The fix attached allows to check automatic orderpoint on 100.000 products in only 10s, no functionality is lost (technically based on Bug #899470 )
  I know that the 6.1 is next to be release but I think that a fix like this is mandatory.

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-addons/+bug/915541/+subscriptions


References