[IMP] procurement: track only once the change of state to exception and confirmed
authorMartin Trigaux <mat@openerp.com>
Thu, 17 Oct 2013 11:35:21 +0000 (13:35 +0200)
committerMartin Trigaux <mat@openerp.com>
Thu, 17 Oct 2013 11:35:21 +0000 (13:35 +0200)
bzr revid: mat@openerp.com-20131017113521-5u2k9glb3o7cnmmk

addons/procurement/procurement.py

index 2bc095a..f5d4761 100644 (file)
@@ -128,6 +128,22 @@ class procurement_order(osv.osv):
         'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'procurement.order', context=c)
     }
 
+    def message_track(self, cr, uid, ids, tracked_fields, initial_values, context=None):
+        """ Overwrite message_track to avoid tracking more than once the confirm-exception loop
+        Add '_first_pass_done_' to the note field only the first time stuck in exception state
+        Will avoid getting furthur confirmed and exception change of state messages
+
+        TODO: this hack is necessary for a stable version but should be avoided for the next release.
+        Instead find a more elegant way to prevent redundant messages or entirely stop tracking states on procurement orders
+        """
+        for proc in self.browse(cr, uid, ids, context=context):
+            if not proc.note or '_first_pass_done_' not in proc.note or proc.state not in ('confirmed', 'exception'):
+                super(procurement_order, self).message_track(cr, uid, [proc.id], tracked_fields, initial_values, context=context)
+                if proc.state == 'exception':
+                    cr.execute("""UPDATE procurement_order set note = CONCAT(note, %s) WHERE id = %s""", ('_first_pass_done_',proc.id))
+
+        return True
+
     def unlink(self, cr, uid, ids, context=None):
         procurements = self.read(cr, uid, ids, ['state'], context=context)
         unlink_ids = []