Comment 5 for bug 915541

Revision history for this message
Kyle Waid (midwest) wrote :

=== 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 {}