@@ -82,6 +82,15 @@ class AuditlogRule(models.Model):
8282 help = ("Select this if you want to keep track of creation on any "
8383 "record of the model of this rule" ),
8484 states = {'subscribed' : [('readonly' , True )]})
85+ log_export_data = fields .Boolean (
86+ "Log Exports" ,
87+ default = True ,
88+ help = (
89+ "Select this if you want to keep track of exports "
90+ "of the model of this rule"
91+ ),
92+ states = {"subscribed" : [("readonly" , True )]},
93+ )
8594 log_type = fields .Selection (
8695 [('full' , "Full log" ),
8796 ('fast' , "Fast log" ),
@@ -179,6 +188,12 @@ def _patch_methods(self):
179188 model_model ._patch_method ('unlink' , rule ._make_unlink ())
180189 setattr (type (model_model ), check_attr , True )
181190 updated = True
191+ # -> export_data
192+ check_attr = 'auditlog_ruled_export_data'
193+ if rule .log_export_data and not hasattr (model_model , check_attr ):
194+ model_model ._patch_method ('export_data' , rule ._make_export_data ())
195+ setattr (type (model_model ), check_attr , True )
196+ updated = True
182197 return updated
183198
184199 @api .multi
@@ -187,7 +202,7 @@ def _revert_methods(self):
187202 updated = False
188203 for rule in self :
189204 model_model = self .env [rule .model_id .model ]
190- for method in ['create' , 'read' , 'write' , 'unlink' ]:
205+ for method in ['create' , 'read' , 'write' , 'unlink' , 'export_data' ]:
191206 if getattr (rule , 'log_%s' % method ) and hasattr (
192207 getattr (model_model , method ), 'origin' ):
193208 model_model ._revert_method (method )
@@ -231,6 +246,28 @@ def get_auditlog_fields(self, model):
231246 if (not f .compute and not f .related ) or f .store
232247 )
233248
249+ def _make_export_data (self ):
250+ """Instanciate a export method that log its calls."""
251+ self .ensure_one ()
252+ log_type = self .log_type
253+
254+ def export_data (self , fields_to_export , raw_data = False ):
255+ res = export_data .origin (self , fields_to_export , raw_data )
256+ self = self .with_context (auditlog_disabled = True )
257+ rule_model = self .env ["auditlog.rule" ]
258+ rule_model .sudo ().create_logs (
259+ self .env .uid ,
260+ self ._name ,
261+ self .ids ,
262+ "export_data" ,
263+ None ,
264+ None ,
265+ {"log_type" : log_type },
266+ )
267+ return res
268+
269+ return export_data
270+
234271 @api .multi
235272 def _make_create (self ):
236273 """Instanciate a create method that log its calls."""
@@ -393,24 +430,27 @@ def create_logs(self, uid, res_model, res_ids, method,
393430 log_model = self .env ['auditlog.log' ]
394431 http_request_model = self .env ['auditlog.http.request' ]
395432 http_session_model = self .env ['auditlog.http.session' ]
433+ model_model = self .env [res_model ]
434+ model_id = self .pool ._auditlog_model_cache [res_model ]
435+ auditlog_rule = self .env ['auditlog.rule' ].search ([('model_id' , '=' , model_id )])
436+ vals = {
437+ 'model_id' : model_id ,
438+ 'method' : method ,
439+ 'user_id' : uid ,
440+ 'http_request_id' : http_request_model .current_http_request (),
441+ 'http_session_id' : http_session_model .current_http_session (),
442+ }
443+ vals .update (additional_log_values or {})
444+ if method == 'export_data' :
445+ vals .update ({'name' : res_model , 'res_ids' : str (res_ids )})
446+ return log_model .create (vals )
447+
448+ log = log_model .create (vals )
396449 for res_id in res_ids :
397- model_model = self .env [res_model ]
398450 name = model_model .browse (res_id ).name_get ()
399- model_id = self .pool ._auditlog_model_cache [res_model ]
400- auditlog_rule = self .env ['auditlog.rule' ].search (
401- [("model_id" , "=" , model_id )])
402451 res_name = name and name [0 ] and name [0 ][1 ]
403- vals = {
404- 'name' : res_name ,
405- 'model_id' : self .pool ._auditlog_model_cache [res_model ],
406- 'res_id' : res_id ,
407- 'method' : method ,
408- 'user_id' : uid ,
409- 'http_request_id' : http_request_model .current_http_request (),
410- 'http_session_id' : http_session_model .current_http_session (),
411- }
412- vals .update (additional_log_values or {})
413- log = log_model .create (vals )
452+ log_vals = {** vals , 'name' : res_name , 'res_id' : res_id }
453+ log = log_model .create (log_vals )
414454 diff = DictDiffer (
415455 new_values .get (res_id , EMPTY_DICT ),
416456 old_values .get (res_id , EMPTY_DICT ))
0 commit comments