콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
4573 화면

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

아바타
취소
베스트 답변

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
아바타
취소
관련 게시물 답글 화면 활동
0
5월 20
6228
1
6월 16
11279
1
12월 16
3393
0
3월 15
3602
1
2월 25
1048