Odoo Help

1

_track with additional information

By
Andrius Laukavičius
on 2/25/14, 4:10 AM 1,290 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

0
Ahmed Kordy
On 9/12/15, 12:49 PM

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

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)

Stats

Asked: 2/25/14, 4:10 AM
Seen: 1290 times
Last updated: 9/12/15, 12:49 PM