[IMP] procurement: better workflow
authorMartin Trigaux <mat@openerp.com>
Wed, 16 Oct 2013 15:03:35 +0000 (17:03 +0200)
committerMartin Trigaux <mat@openerp.com>
Wed, 16 Oct 2013 15:03:35 +0000 (17:03 +0200)
bzr revid: mat@openerp.com-20131016150335-oikqm6twbukp666t

addons/procurement/procurement.py
addons/procurement/procurement_workflow.xml
addons/procurement/schedulers.py
addons/purchase/purchase.py

index 2bc095a..a39b2d7 100644 (file)
@@ -371,7 +371,7 @@ class procurement_order(osv.osv):
                     #temporary context passed in write to prevent an infinite loop
                     ctx_wkf = dict(context or {})
                     ctx_wkf['workflow.trg_write.%s' % self._name] = False
-                    self.write(cr, uid, [procurement.id], {'message': message},context=ctx_wkf)
+                    self.write(cr, uid, [procurement.id], {'message': message, 'state': 'exception'},context=ctx_wkf)
         return ok
 
     def _workflow_trigger(self, cr, uid, ids, trigger, context=None):
index 76b5437..8ddd619 100644 (file)
@@ -29,8 +29,6 @@
         <record id="act_confirm_wait" model="workflow.activity">
             <field name="wkf_id" ref="wkf_procurement"/>
             <field name="name">confirm_wait</field>
-            <field name="kind">function</field>
-            <field name="action">write({'state':'exception'})</field>
         </record>
         <record id="act_confirm_mts" model="workflow.activity">
             <field name="wkf_id" ref="wkf_procurement"/>
index 07280b3..cf08cb9 100644 (file)
@@ -72,10 +72,6 @@ class procurement_order(osv.osv):
             maxdate = (datetime.today() + relativedelta(days=company.schedule_range)).strftime(tools.DEFAULT_SERVER_DATE_FORMAT)
             start_date = fields.datetime.now()
             offset = 0
-            report = []
-            report_total = 0
-            report_except = 0
-            report_later = 0
             while True:
                 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):
@@ -83,14 +79,7 @@ class procurement_order(osv.osv):
                         wf_service.trg_validate(uid, 'procurement.order', proc.id, 'button_check', cr)
                     else:
                         offset += 1
-                        report_later += 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_except += 1
-                    report_total += 1
                 if use_new_cursor:
                     cr.commit()
                 if not ids:
@@ -98,22 +87,10 @@ class procurement_order(osv.osv):
             offset = 0
             ids = []
             while True:
-                report_ids = []
                 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)
-                        report_ids.append(proc.id)
-                    else:
-                        report_later += 1
-                    report_total += 1
-
-                    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_except += 1
-
 
                 if use_new_cursor:
                     cr.commit()
index 992af37..04b380e 100644 (file)
@@ -1044,10 +1044,9 @@ class procurement_order(osv.osv):
                 message = _('No default supplier defined for this product')
             elif not partner_obj.address_get(cr, uid, [partner.id], ['delivery'])['delivery']:
                 message = _('No address defined for the supplier')
-
             if message:
                 if procurement.message != message:
-                    cr.execute('update procurement_order set message=%s where id=%s', (message, procurement.id))
+                    cr.execute("update procurement_order set message=%s, state='exception' where id=%s", (message, procurement.id))
                 return False
 
             if user.company_id and user.company_id.partner_id: