[FIX] procurement: avoid getting loop of state change when a procurement is stuck in an exception and retried by the scheduler (opw 598606)

bzr revid: mat@openerp.com-20131017113736-inell5fxydr71xyk
This commit is contained in:
Martin Trigaux 2013-10-17 13:37:36 +02:00
commit 20f63f6e36
1 changed files with 16 additions and 0 deletions

View 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 = []