Browse Source

[ADD] auditlog: enable to track Unlink record

12.0-mig-module_prototyper_last
Hardik Suthar 3 years ago
committed by Bhavesh Odedra
parent
commit
75c92bfcc4
  1. 11
      auditlog/models/rule.py
  2. 2
      auditlog/readme/CONTRIBUTORS.rst
  3. 1
      auditlog/views/auditlog_view.xml

11
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

2
auditlog/readme/CONTRIBUTORS.rst

@ -1,3 +1,5 @@
* Sebastien Alix <sebastien.alix@camptocamp.com>
* Holger Brunn <hbrunn@therp.nl>
* Holden Rehg <holdenrehg@gmail.com>
* Bhavesh Odedra <bodedra@opensourceintegrators.com>
* Hardik Suthar <hsuthar@opensourceintegrators.com>

1
auditlog/views/auditlog_view.xml

@ -26,6 +26,7 @@
<field name="model_id"/>
<field name="log_type"/>
<field name="action_id" readonly="1" groups="base.group_no_one"/>
<field name="capture_record" attrs="{'invisible':['|' ,('log_type','!=', 'full'), ('log_unlink','!=', True)]}"/>
</group>
<group colspan="1">
<field name="log_read"/>

Loading…
Cancel
Save