sequence = -1
if opportunity.stage_id and opportunity.stage_id.state != 'cancel':
sequence = opportunity.stage_id.sequence
- sequenced_opps.append(((int(opportunity.type == 'opportunity'), sequence, -opportunity.id), opportunity))
+ sequenced_opps.append(((int(sequence != -1 and opportunity.type == 'opportunity'), sequence, -opportunity.id), opportunity))
sequenced_opps.sort(reverse=True)
opportunities = map(itemgetter(1), sequenced_opps)