@ -130,7 +130,7 @@ class auditlog_rule(models.Model):
if not self . pool . get ( rule . model_id . model ) :
if not self . pool . get ( rule . model_id . model ) :
# ignore rules for models not loadable currently
# ignore rules for models not loadable currently
continue
continue
model_cache [ rule . model_id . model ] = rule . model_id
model_cache [ rule . model_id . model ] = rule . model_id . id
model_model = self . env [ rule . model_id . model ]
model_model = self . env [ rule . model_id . model ]
# CRUD
# CRUD
# -> create
# -> create
@ -297,7 +297,7 @@ class auditlog_rule(models.Model):
res_name = model_model . browse ( res_id ) . name_get ( )
res_name = model_model . browse ( res_id ) . name_get ( )
vals = {
vals = {
' name ' : res_name and res_name [ 0 ] and res_name [ 0 ] [ 1 ] or False ,
' name ' : res_name and res_name [ 0 ] and res_name [ 0 ] [ 1 ] or False ,
' model_id ' : self . pool . _auditlog_model_cache [ res_model ] . id ,
' model_id ' : self . pool . _auditlog_model_cache [ res_model ] ,
' res_id ' : res_id ,
' res_id ' : res_id ,
' method ' : method ,
' method ' : method ,
' user_id ' : uid ,
' user_id ' : uid ,
@ -315,12 +315,13 @@ class auditlog_rule(models.Model):
cache = self . pool . _auditlog_field_cache
cache = self . pool . _auditlog_field_cache
if field_name not in cache . get ( model . model , { } ) :
if field_name not in cache . get ( model . model , { } ) :
cache . setdefault ( model . model , { } )
cache . setdefault ( model . model , { } )
cache [ model . model ] [ field_name ] = self . env [ ' ir.model.fields ' ] \
. search (
[
( ' model_id ' , ' = ' , model . id ) ,
( ' name ' , ' = ' , field_name ) ,
] )
# We use 'search()' then 'read()' instead of the 'search_read()'
# to take advantage of the 'classic_write' loading
field_model = self . env [ ' ir.model.fields ' ]
field = field_model . search (
[ ( ' model_id ' , ' = ' , model . id ) , ( ' name ' , ' = ' , field_name ) ] )
field_data = field . read ( load = ' _classic_write ' ) [ 0 ]
cache [ model . model ] [ field_name ] = field_data
return cache [ model . model ] [ field_name ]
return cache [ model . model ] [ field_name ]
def _create_log_line_on_write (
def _create_log_line_on_write (
@ -341,19 +342,19 @@ class auditlog_rule(models.Model):
' write ' operation .
' write ' operation .
"""
"""
vals = {
vals = {
' field_id ' : field . id ,
' field_id ' : field [ ' id ' ] ,
' log_id ' : log . id ,
' log_id ' : log . id ,
' old_value ' : old_values [ log . res_id ] [ field . name ] ,
' old_value_text ' : old_values [ log . res_id ] [ field . name ] ,
' new_value ' : new_values [ log . res_id ] [ field . name ] ,
' new_value_text ' : new_values [ log . res_id ] [ field . name ] ,
' old_value ' : old_values [ log . res_id ] [ field [ ' name ' ] ] ,
' old_value_text ' : old_values [ log . res_id ] [ field [ ' name ' ] ] ,
' new_value ' : new_values [ log . res_id ] [ field [ ' name ' ] ] ,
' new_value_text ' : new_values [ log . res_id ] [ field [ ' name ' ] ] ,
}
}
# for *2many fields, log the name_get
# for *2many fields, log the name_get
if field . relation and ' 2many ' in field . ttype :
old_value_text = self . env [ field . relation ] . browse (
if field [ ' relation ' ] and ' 2many ' in field [ ' ttype ' ] :
old_value_text = self . env [ field [ ' relation ' ] ] . browse (
vals [ ' old_value ' ] ) . name_get ( )
vals [ ' old_value ' ] ) . name_get ( )
vals [ ' old_value_text ' ] = old_value_text
vals [ ' old_value_text ' ] = old_value_text
new_value_text = self . env [ field . relation ] . browse (
new_value_text = self . env [ field [ ' relation ' ] ] . browse (
vals [ ' new_value ' ] ) . name_get ( )
vals [ ' new_value ' ] ) . name_get ( )
vals [ ' new_value_text ' ] = new_value_text
vals [ ' new_value_text ' ] = new_value_text
return vals
return vals
@ -375,15 +376,15 @@ class auditlog_rule(models.Model):
' create ' operation .
' create ' operation .
"""
"""
vals = {
vals = {
' field_id ' : field . id ,
' field_id ' : field [ ' id ' ] ,
' log_id ' : log . id ,
' log_id ' : log . id ,
' old_value ' : False ,
' old_value ' : False ,
' old_value_text ' : False ,
' old_value_text ' : False ,
' new_value ' : new_values [ log . res_id ] [ field . name ] ,
' new_value_text ' : new_values [ log . res_id ] [ field . name ] ,
' new_value ' : new_values [ log . res_id ] [ field [ ' name ' ] ] ,
' new_value_text ' : new_values [ log . res_id ] [ field [ ' name ' ] ] ,
}
}
if field . relation and ' 2many ' in field . ttype :
new_value_text = self . env [ field . relation ] . browse (
if field [ ' relation ' ] and ' 2many ' in field [ ' ttype ' ] :
new_value_text = self . env [ field [ ' relation ' ] ] . browse (
vals [ ' new_value ' ] ) . name_get ( )
vals [ ' new_value ' ] ) . name_get ( )
vals [ ' new_value_text ' ] = new_value_text
vals [ ' new_value_text ' ] = new_value_text
return vals
return vals