diff --git a/auditlog/models/rule.py b/auditlog/models/rule.py index 39bd5bafa..13f7beef4 100644 --- a/auditlog/models/rule.py +++ b/auditlog/models/rule.py @@ -105,6 +105,10 @@ class AuditlogRule(models.Model): action_id = fields.Many2one( 'ir.actions.act_window', string="Action", states={'subscribed': [('readonly', True)]}) + capture_record = fields.Boolean( + "Capture Record", + help="Select this if you want to keep track of Unlink Record", + ) _sql_constraints = [ ('model_uniq', 'unique(model_id)', @@ -382,6 +386,8 @@ class AuditlogRule(models.Model): for res_id in res_ids: model_model = self.env[res_model] name = model_model.browse(res_id).name_get() + model_id = self.pool._auditlog_model_cache[res_model] + auditlog_rule = self.env['auditlog.rule'].search([("model_id", "=", model_id)]) res_name = name and name[0] and name[0][1] vals = { 'name': res_name, @@ -407,6 +413,11 @@ class AuditlogRule(models.Model): elif method is 'write': self._create_log_line_on_write( log, diff.changed(), old_values, new_values) + elif method is 'unlink' and auditlog_rule.capture_record: + self._create_log_line_on_read( + log, + list(old_values.get(res_id, EMPTY_DICT).keys()), old_values + ) def _get_field(self, model, field_name): cache = self.pool._auditlog_field_cache diff --git a/auditlog/readme/CONTRIBUTORS.rst b/auditlog/readme/CONTRIBUTORS.rst index 1567f0b2c..9e70c02fb 100644 --- a/auditlog/readme/CONTRIBUTORS.rst +++ b/auditlog/readme/CONTRIBUTORS.rst @@ -1,3 +1,5 @@ * Sebastien Alix * Holger Brunn * Holden Rehg +* Bhavesh Odedra +* Hardik Suthar diff --git a/auditlog/views/auditlog_view.xml b/auditlog/views/auditlog_view.xml index 2ec7b4808..520e4f799 100644 --- a/auditlog/views/auditlog_view.xml +++ b/auditlog/views/auditlog_view.xml @@ -26,6 +26,7 @@ +