I have an object with field state (draft and done), and field compteur, i want to increment compteur until the the field change the state to done,
The problem is when i valid the state, the field compteur become zero, and i want to stay in last value
this is my code :
def my_function(self, cr, uid, ids, field_name, arg, context):
res = {}
for cons in self.browse(cr, uid, ids, context=context):
if cons.state == 'draft' :
compteur_mtn = 0
date_creation_repertoire= cons.date_creation_repertoire
date_mtn= time.strftime('%Y-%m-%d')
date_creation_repertoire = date_creation_repertoire.split('-')
date_mtn= date_mtn.split('-')
jours1 = 0
jours2 = 0
jours1 = ((int(date_mtn[0]) * 365) + (int(date_mtn[1]) * 30) + int((date_mtn[2])))
print jours1
jours2 = ((int(date_creation_repertoire[0]) * 365) + (int(date_creation_repertoire[1]) * 30) + int((date_creation_repertoire[2])))
print jours2
compteur = (jours1 - jours2)
print compteur
res[cons.id] = compteur
else :
res[cons.id] = False
return res
'compteur': fields.function(my_function, type="float", string='Délai en j'),