33
44import copy
55
6- from odoo import Command , _ , api , fields , models
6+ from odoo import Command , api , fields , models
7+ from odoo .api import NewId
78from odoo .exceptions import UserError
89
910FIELDS_BLACKLIST = [
@@ -104,8 +105,7 @@ class AuditlogRule(models.Model):
104105 "Log Exports" ,
105106 default = True ,
106107 help = (
107- "Select this if you want to keep track of exports "
108- "of the model of this rule"
108+ "Select this if you want to keep track of exports of the model of this rule"
109109 ),
110110 )
111111 log_type = fields .Selection (
@@ -146,16 +146,11 @@ class AuditlogRule(models.Model):
146146 string = "Fields to Exclude" ,
147147 )
148148
149- _sql_constraints = [
150- (
151- "model_uniq" ,
152- "unique(model_id)" ,
153- (
154- "There is already a rule defined on this model\n "
155- "You cannot define another: please edit the existing one."
156- ),
157- )
158- ]
149+ _model_uniq = models .Constraint (
150+ "unique(model_id)" ,
151+ "There is already a rule defined on this model\n You cannot define another: "
152+ "please edit the existing one." ,
153+ )
159154
160155 def _register_hook (self ):
161156 """Get all rules and apply them to log method calls."""
@@ -245,7 +240,7 @@ def create(self, vals_list):
245240 """Update the registry when a new rule is created."""
246241 for vals in vals_list :
247242 if "model_id" not in vals or not vals ["model_id" ]:
248- raise UserError (_ ("No model defined to create line." ))
243+ raise UserError (self . env . _ ("No model defined to create line." ))
249244 model = self .env ["ir.model" ].sudo ().browse (vals ["model_id" ])
250245 vals .update ({"model_name" : model .name , "model_model" : model .model })
251246 new_records = super ().create (vals_list )
@@ -258,7 +253,7 @@ def write(self, vals):
258253 """Update the registry when existing rules are updated."""
259254 if "model_id" in vals :
260255 if not vals ["model_id" ]:
261- raise UserError (_ ("Field 'model_id' cannot be empty." ))
256+ raise UserError (self . env . _ ("Field 'model_id' cannot be empty." ))
262257 model = self .env ["ir.model" ].sudo ().browse (vals ["model_id" ])
263258 vals .update ({"model_name" : model .name , "model_model" : model .model })
264259 res = super ().write (vals )
@@ -291,7 +286,6 @@ def _make_create(self):
291286 users_to_exclude = self .mapped ("users_to_exclude_ids" )
292287
293288 @api .model_create_multi
294- @api .returns ("self" , lambda value : value .id )
295289 def create_full (self , vals_list , ** kwargs ):
296290 self = self .with_context (auditlog_disabled = True )
297291 rule_model = self .env ["auditlog.rule" ]
@@ -324,7 +318,6 @@ def create_full(self, vals_list, **kwargs):
324318 return new_records
325319
326320 @api .model_create_multi
327- @api .returns ("self" , lambda value : value .id )
328321 def create_fast (self , vals_list , ** kwargs ):
329322 self = self .with_context (auditlog_disabled = True )
330323 rule_model = self .env ["auditlog.rule" ]
@@ -398,7 +391,7 @@ def write_full(self, vals, **kwargs):
398391 self = self .with_context (auditlog_disabled = True )
399392 rule_model = self .env ["auditlog.rule" ]
400393 fields_list = rule_model .get_auditlog_fields (self )
401- records_write = self .filtered (lambda r : not isinstance (r .id , models . NewId ))
394+ records_write = self .filtered (lambda r : not isinstance (r .id , NewId ))
402395 if not records_write :
403396 return write_full .origin (self , vals , ** kwargs )
404397 old_values = {
@@ -408,8 +401,6 @@ def write_full(self, vals, **kwargs):
408401 .read (fields_list )
409402 }
410403 # invalidate_recordset method must be called with existing fields
411- if self ._name == "res.users" :
412- vals = self ._remove_reified_groups (vals )
413404 # Prevent the cache of modified fields from being poisoned by
414405 # x2many items inaccessible to the current user.
415406 self .invalidate_recordset (vals .keys ())
@@ -775,7 +766,7 @@ def subscribe(self):
775766 f"[('model_id', '=', { rule .model_id .id } ), ('res_id', '=', active_id)]"
776767 )
777768 vals = {
778- "name" : _ ("View logs" ),
769+ "name" : self . env . _ ("View logs" ),
779770 "res_model" : "auditlog.log" ,
780771 "binding_model_id" : rule .model_id .id ,
781772 "domain" : domain ,
0 commit comments