This question has been flagged
1 Reply
3459 Views

Is it possible to add additional information when field is tracked? For example let say there are two fields:

_track = {
  'field1': {},
  'field2': {},
}

I need to track those fields if anything is changed in those fields. And that is ok, but the problem is that those fields labels are the same for example like this:

_columns = {
  'field1': fields.integer('Number'), 
   'field2': fields.integer('Number'),

}

I don't want to change it's name, because those names should be the same as they represent same thing but in different time. But is it possible to add aditional infor when tracking occurs, for example instead of just showing like this:

Number: 1 - > 2

It would show like this:

Number: 1 -> 2 "before field" #when field1 is changed

Number: 2 -> 3 "after field" #when field2 is changed

Avatar
Discard
Best Answer

If you mean you already using the track_visibility and you want a more customized note messages, then you might need to hook into the write method.

The customized method would be ran each time the model writes to database, a comparison made between old and new records would track any changes to specific fields, if any then let's log a note.

Add this to your model class (change ClassName with your model class name, message body as you wish):

    @api.multi
def write(self, vals):
old_field1 = self.field1
old_field2 = self.field2

super(ClassName, self).write(vals)

new_field1 = self.field1
new_field2 = self.field2

if old_field1 != new_field1:
self.message_post(body="<b>Field1 Title:</b> %s &#8594; %s" % (old_field1, new_field1))

if old_field2 != new_field2:
self.message_post(body="<b>Field2 Title:</b> %s &#8594; %s" % (old_field2, new_field2))

return True
Avatar
Discard