[MIG] auditlog: Migration to 11.0
parent
ccf3984952
commit
fe82a64ac4
|
@ -1,5 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# © 2015 ABF OSIELL <http://osiell.com>
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# © 2015 ABF OSIELL <http://osiell.com>
|
# © 2015 ABF OSIELL <http://osiell.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': "Audit Log",
|
'name': "Audit Log",
|
||||||
'version': "10.0.1.0.0",
|
'version': "11.0.1.0.0",
|
||||||
'author': "ABF OSIELL,Odoo Community Association (OCA)",
|
'author': "ABF OSIELL,Odoo Community Association (OCA)",
|
||||||
'license': "AGPL-3",
|
'license': "AGPL-3",
|
||||||
'website': "http://www.osiell.com",
|
'website': "http://www.osiell.com",
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
<field name="numbercall">-1</field>
|
<field name="numbercall">-1</field>
|
||||||
<field name="active" eval="False"/>
|
<field name="active" eval="False"/>
|
||||||
<field name="doall" eval="False"/>
|
<field name="doall" eval="False"/>
|
||||||
<field name="model">auditlog.autovacuum</field>
|
<field name="code">model.autovacuum(180)</field>
|
||||||
<field name="function">autovacuum</field>
|
<field name="state">code</field>
|
||||||
<field name="args">(180,)</field>
|
<field name="model_id" ref="model_auditlog_autovacuum"/>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# © 2015 ABF OSIELL <http://osiell.com>
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from . import rule
|
from . import rule
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# © 2016 ABF OSIELL <http://osiell.com>
|
# © 2016 ABF OSIELL <http://osiell.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
import logging
|
import logging
|
||||||
|
@ -36,6 +35,6 @@ class AuditlogAutovacuum(models.TransientModel):
|
||||||
nb_records = len(records)
|
nb_records = len(records)
|
||||||
records.unlink()
|
records.unlink()
|
||||||
_logger.info(
|
_logger.info(
|
||||||
u"AUTOVACUUM - %s '%s' records deleted",
|
"AUTOVACUUM - %s '%s' records deleted",
|
||||||
nb_records, data_model)
|
nb_records, data_model)
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -10,20 +10,20 @@ from odoo.http import request
|
||||||
|
|
||||||
class AuditlogHTTPRequest(models.Model):
|
class AuditlogHTTPRequest(models.Model):
|
||||||
_name = 'auditlog.http.request'
|
_name = 'auditlog.http.request'
|
||||||
_description = u"Auditlog - HTTP request log"
|
_description = "Auditlog - HTTP request log"
|
||||||
_order = "create_date DESC"
|
_order = "create_date DESC"
|
||||||
|
|
||||||
display_name = fields.Char(
|
display_name = fields.Char(
|
||||||
u"Name", compute="_compute_display_name", store=True)
|
"Name", compute="_compute_display_name", store=True)
|
||||||
name = fields.Char(u"Path")
|
name = fields.Char("Path")
|
||||||
root_url = fields.Char(u"Root URL")
|
root_url = fields.Char("Root URL")
|
||||||
user_id = fields.Many2one(
|
user_id = fields.Many2one(
|
||||||
'res.users', string=u"User")
|
'res.users', string="User")
|
||||||
http_session_id = fields.Many2one(
|
http_session_id = fields.Many2one(
|
||||||
'auditlog.http.session', string=u"Session")
|
'auditlog.http.session', string="Session")
|
||||||
user_context = fields.Char(u"Context")
|
user_context = fields.Char("Context")
|
||||||
log_ids = fields.One2many(
|
log_ids = fields.One2many(
|
||||||
'auditlog.log', 'http_request_id', string=u"Logs")
|
'auditlog.log', 'http_request_id', string="Logs")
|
||||||
|
|
||||||
@api.depends('create_date', 'name')
|
@api.depends('create_date', 'name')
|
||||||
def _compute_display_name(self):
|
def _compute_display_name(self):
|
||||||
|
@ -31,7 +31,7 @@ class AuditlogHTTPRequest(models.Model):
|
||||||
create_date = fields.Datetime.from_string(httprequest.create_date)
|
create_date = fields.Datetime.from_string(httprequest.create_date)
|
||||||
tz_create_date = fields.Datetime.context_timestamp(
|
tz_create_date = fields.Datetime.context_timestamp(
|
||||||
httprequest, create_date)
|
httprequest, create_date)
|
||||||
httprequest.display_name = u"%s (%s)" % (
|
httprequest.display_name = "%s (%s)" % (
|
||||||
httprequest.name or '?',
|
httprequest.name or '?',
|
||||||
fields.Datetime.to_string(tz_create_date))
|
fields.Datetime.to_string(tz_create_date))
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# © 2015 ABF OSIELL <http://osiell.com>
|
# © 2015 ABF OSIELL <http://osiell.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
@ -8,16 +7,16 @@ from odoo.http import request
|
||||||
|
|
||||||
class AuditlogtHTTPSession(models.Model):
|
class AuditlogtHTTPSession(models.Model):
|
||||||
_name = 'auditlog.http.session'
|
_name = 'auditlog.http.session'
|
||||||
_description = u"Auditlog - HTTP User session log"
|
_description = "Auditlog - HTTP User session log"
|
||||||
_order = "create_date DESC"
|
_order = "create_date DESC"
|
||||||
|
|
||||||
display_name = fields.Char(
|
display_name = fields.Char(
|
||||||
u"Name", compute="_compute_display_name", store=True)
|
"Name", compute="_compute_display_name", store=True)
|
||||||
name = fields.Char(u"Session ID", index=True)
|
name = fields.Char("Session ID", index=True)
|
||||||
user_id = fields.Many2one(
|
user_id = fields.Many2one(
|
||||||
'res.users', string=u"User", index=True)
|
'res.users', string="User", index=True)
|
||||||
http_request_ids = fields.One2many(
|
http_request_ids = fields.One2many(
|
||||||
'auditlog.http.request', 'http_session_id', string=u"HTTP Requests")
|
'auditlog.http.request', 'http_session_id', string="HTTP Requests")
|
||||||
|
|
||||||
@api.depends('create_date', 'user_id')
|
@api.depends('create_date', 'user_id')
|
||||||
def _compute_display_name(self):
|
def _compute_display_name(self):
|
||||||
|
@ -25,7 +24,7 @@ class AuditlogtHTTPSession(models.Model):
|
||||||
create_date = fields.Datetime.from_string(httpsession.create_date)
|
create_date = fields.Datetime.from_string(httpsession.create_date)
|
||||||
tz_create_date = fields.Datetime.context_timestamp(
|
tz_create_date = fields.Datetime.context_timestamp(
|
||||||
httpsession, create_date)
|
httpsession, create_date)
|
||||||
httpsession.display_name = u"%s (%s)" % (
|
httpsession.display_name = "%s (%s)" % (
|
||||||
httpsession.user_id and httpsession.user_id.name or '?',
|
httpsession.user_id and httpsession.user_id.name or '?',
|
||||||
fields.Datetime.to_string(tz_create_date))
|
fields.Datetime.to_string(tz_create_date))
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# © 2015 ABF OSIELL <http://osiell.com>
|
# © 2015 ABF OSIELL <http://osiell.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
from odoo import models, fields
|
from odoo import models, fields
|
||||||
|
@ -11,22 +10,22 @@ class AuditlogLog(models.Model):
|
||||||
|
|
||||||
name = fields.Char("Resource Name", size=64)
|
name = fields.Char("Resource Name", size=64)
|
||||||
model_id = fields.Many2one(
|
model_id = fields.Many2one(
|
||||||
'ir.model', string=u"Model")
|
'ir.model', string="Model")
|
||||||
res_id = fields.Integer(u"Resource ID")
|
res_id = fields.Integer("Resource ID")
|
||||||
user_id = fields.Many2one(
|
user_id = fields.Many2one(
|
||||||
'res.users', string=u"User")
|
'res.users', string="User")
|
||||||
method = fields.Char(u"Method", size=64)
|
method = fields.Char("Method", size=64)
|
||||||
line_ids = fields.One2many(
|
line_ids = fields.One2many(
|
||||||
'auditlog.log.line', 'log_id', string=u"Fields updated")
|
'auditlog.log.line', 'log_id', string="Fields updated")
|
||||||
http_session_id = fields.Many2one(
|
http_session_id = fields.Many2one(
|
||||||
'auditlog.http.session', string=u"Session")
|
'auditlog.http.session', string="Session")
|
||||||
http_request_id = fields.Many2one(
|
http_request_id = fields.Many2one(
|
||||||
'auditlog.http.request', string=u"HTTP Request")
|
'auditlog.http.request', string="HTTP Request")
|
||||||
log_type = fields.Selection(
|
log_type = fields.Selection(
|
||||||
[('full', u"Full log"),
|
[('full', "Full log"),
|
||||||
('fast', u"Fast log"),
|
('fast', "Fast log"),
|
||||||
],
|
],
|
||||||
string=u"Type")
|
string="Type")
|
||||||
|
|
||||||
|
|
||||||
class AuditlogLogLine(models.Model):
|
class AuditlogLogLine(models.Model):
|
||||||
|
@ -34,13 +33,13 @@ class AuditlogLogLine(models.Model):
|
||||||
_description = "Auditlog - Log details (fields updated)"
|
_description = "Auditlog - Log details (fields updated)"
|
||||||
|
|
||||||
field_id = fields.Many2one(
|
field_id = fields.Many2one(
|
||||||
'ir.model.fields', ondelete='cascade', string=u"Field", required=True)
|
'ir.model.fields', ondelete='cascade', string="Field", required=True)
|
||||||
log_id = fields.Many2one(
|
log_id = fields.Many2one(
|
||||||
'auditlog.log', string=u"Log", ondelete='cascade', index=True)
|
'auditlog.log', string="Log", ondelete='cascade', index=True)
|
||||||
old_value = fields.Text(u"Old Value")
|
old_value = fields.Text("Old Value")
|
||||||
new_value = fields.Text(u"New Value")
|
new_value = fields.Text("New Value")
|
||||||
old_value_text = fields.Text(u"Old value Text")
|
old_value_text = fields.Text("Old value Text")
|
||||||
new_value_text = fields.Text(u"New value Text")
|
new_value_text = fields.Text("New value Text")
|
||||||
field_name = fields.Char(u"Technical name", related='field_id.name')
|
field_name = fields.Char("Technical name", related='field_id.name')
|
||||||
field_description = fields.Char(
|
field_description = fields.Char(
|
||||||
u"Description", related='field_id.field_description')
|
"Description", related='field_id.field_description')
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# © 2015 ABF OSIELL <http://osiell.com>
|
# © 2015 ABF OSIELL <http://osiell.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from odoo import models, fields, api, modules, _, sql_db
|
from odoo import models, fields, api, modules, _
|
||||||
|
|
||||||
FIELDS_BLACKLIST = [
|
FIELDS_BLACKLIST = [
|
||||||
'id', 'create_uid', 'create_date', 'write_uid', 'write_date',
|
'id', 'create_uid', 'create_date', 'write_uid', 'write_date',
|
||||||
|
@ -45,42 +44,42 @@ class AuditlogRule(models.Model):
|
||||||
_name = 'auditlog.rule'
|
_name = 'auditlog.rule'
|
||||||
_description = "Auditlog - Rule"
|
_description = "Auditlog - Rule"
|
||||||
|
|
||||||
name = fields.Char(u"Name", size=32, required=True)
|
name = fields.Char("Name", size=32, required=True)
|
||||||
model_id = fields.Many2one(
|
model_id = fields.Many2one(
|
||||||
'ir.model', u"Model", required=True,
|
'ir.model', "Model", required=True,
|
||||||
help=u"Select model for which you want to generate log.")
|
help="Select model for which you want to generate log.")
|
||||||
user_ids = fields.Many2many(
|
user_ids = fields.Many2many(
|
||||||
'res.users',
|
'res.users',
|
||||||
'audittail_rules_users',
|
'audittail_rules_users',
|
||||||
'user_id', 'rule_id',
|
'user_id', 'rule_id',
|
||||||
string=u"Users",
|
string="Users",
|
||||||
help=u"if User is not added then it will applicable for all users")
|
help="if User is not added then it will applicable for all users")
|
||||||
log_read = fields.Boolean(
|
log_read = fields.Boolean(
|
||||||
u"Log Reads",
|
"Log Reads",
|
||||||
help=(u"Select this if you want to keep track of read/open on any "
|
help=("Select this if you want to keep track of read/open on any "
|
||||||
u"record of the model of this rule"))
|
"record of the model of this rule"))
|
||||||
log_write = fields.Boolean(
|
log_write = fields.Boolean(
|
||||||
u"Log Writes", default=True,
|
"Log Writes", default=True,
|
||||||
help=(u"Select this if you want to keep track of modification on any "
|
help=("Select this if you want to keep track of modification on any "
|
||||||
u"record of the model of this rule"))
|
"record of the model of this rule"))
|
||||||
log_unlink = fields.Boolean(
|
log_unlink = fields.Boolean(
|
||||||
u"Log Deletes", default=True,
|
"Log Deletes", default=True,
|
||||||
help=(u"Select this if you want to keep track of deletion on any "
|
help=("Select this if you want to keep track of deletion on any "
|
||||||
u"record of the model of this rule"))
|
"record of the model of this rule"))
|
||||||
log_create = fields.Boolean(
|
log_create = fields.Boolean(
|
||||||
u"Log Creates", default=True,
|
"Log Creates", default=True,
|
||||||
help=(u"Select this if you want to keep track of creation on any "
|
help=("Select this if you want to keep track of creation on any "
|
||||||
u"record of the model of this rule"))
|
"record of the model of this rule"))
|
||||||
log_type = fields.Selection(
|
log_type = fields.Selection(
|
||||||
[('full', u"Full log"),
|
[('full', "Full log"),
|
||||||
('fast', u"Fast log"),
|
('fast', "Fast log"),
|
||||||
],
|
],
|
||||||
string=u"Type", required=True, default='full',
|
string="Type", required=True, default='full',
|
||||||
help=(u"Full log: make a diff between the data before and after "
|
help=("Full log: make a diff between the data before and after "
|
||||||
u"the operation (log more info like computed fields which were "
|
"the operation (log more info like computed fields which were "
|
||||||
u"updated, but it is slower)\n"
|
"updated, but it is slower)\n"
|
||||||
u"Fast log: only log the changes made through the create and "
|
"Fast log: only log the changes made through the create and "
|
||||||
u"write operations (less information, but it is faster)"))
|
"write operations (less information, but it is faster)"))
|
||||||
# log_action = fields.Boolean(
|
# log_action = fields.Boolean(
|
||||||
# "Log Action",
|
# "Log Action",
|
||||||
# help=("Select this if you want to keep track of actions on the "
|
# help=("Select this if you want to keep track of actions on the "
|
||||||
|
@ -91,7 +90,7 @@ class AuditlogRule(models.Model):
|
||||||
# "record of the model of this rule"))
|
# "record of the model of this rule"))
|
||||||
state = fields.Selection(
|
state = fields.Selection(
|
||||||
[('draft', "Draft"), ('subscribed', "Subscribed")],
|
[('draft', "Draft"), ('subscribed', "Subscribed")],
|
||||||
string=u"State", required=True, default='draft')
|
string="State", required=True, default='draft')
|
||||||
action_id = fields.Many2one(
|
action_id = fields.Many2one(
|
||||||
'ir.actions.act_window', string="Action")
|
'ir.actions.act_window', string="Action")
|
||||||
|
|
||||||
|
@ -169,16 +168,14 @@ class AuditlogRule(models.Model):
|
||||||
delattr(type(model_model), 'auditlog_ruled_%s' % method)
|
delattr(type(model_model), 'auditlog_ruled_%s' % method)
|
||||||
updated = True
|
updated = True
|
||||||
if updated:
|
if updated:
|
||||||
modules.registry.RegistryManager.signal_registry_change(
|
modules.registry.Registry(self.env.cr.dbname).signal_changes()
|
||||||
self.env.cr.dbname)
|
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def create(self, vals):
|
def create(self, vals):
|
||||||
"""Update the registry when a new rule is created."""
|
"""Update the registry when a new rule is created."""
|
||||||
new_record = super(AuditlogRule, self).create(vals)
|
new_record = super(AuditlogRule, self).create(vals)
|
||||||
if new_record._register_hook():
|
if new_record._register_hook():
|
||||||
modules.registry.RegistryManager.signal_registry_change(
|
modules.registry.Registry(self.env.cr.dbname).signal_changes()
|
||||||
self.env.cr.dbname)
|
|
||||||
return new_record
|
return new_record
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
|
@ -186,8 +183,7 @@ class AuditlogRule(models.Model):
|
||||||
"""Update the registry when existing rules are updated."""
|
"""Update the registry when existing rules are updated."""
|
||||||
super(AuditlogRule, self).write(vals)
|
super(AuditlogRule, self).write(vals)
|
||||||
if self._register_hook():
|
if self._register_hook():
|
||||||
modules.registry.RegistryManager.signal_registry_change(
|
modules.registry.Registry(self.env.cr.dbname).signal_changes()
|
||||||
self.env.cr.dbname)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
|
@ -237,8 +233,8 @@ class AuditlogRule(models.Model):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
log_type = self.log_type
|
log_type = self.log_type
|
||||||
|
|
||||||
def read(self, *args, **kwargs):
|
def read(self, fields=None, load='_classic_read', **kwargs):
|
||||||
result = read.origin(self, *args, **kwargs)
|
result = read.origin(self, fields, load, **kwargs)
|
||||||
# Sometimes the result is not a list but a dictionary
|
# Sometimes the result is not a list but a dictionary
|
||||||
# Also, we can not modify the current result as it will break calls
|
# Also, we can not modify the current result as it will break calls
|
||||||
result2 = result
|
result2 = result
|
||||||
|
@ -246,34 +242,18 @@ class AuditlogRule(models.Model):
|
||||||
result2 = [result]
|
result2 = [result]
|
||||||
read_values = dict((d['id'], d) for d in result2)
|
read_values = dict((d['id'], d) for d in result2)
|
||||||
# Old API
|
# Old API
|
||||||
if args and isinstance(args[0], sql_db.Cursor):
|
|
||||||
cr, uid, ids = args[0], args[1], args[2]
|
# If the call came from auditlog itself, skip logging:
|
||||||
if isinstance(ids, (int, long)):
|
# avoid logs on `read` produced by auditlog during internal
|
||||||
ids = [ids]
|
# processing: read data of relevant records, 'ir.model',
|
||||||
# If the call came from auditlog itself, skip logging:
|
# 'ir.model.fields'... (no interest in logging such operations)
|
||||||
# avoid logs on `read` produced by auditlog during internal
|
if self.env.context.get('auditlog_disabled'):
|
||||||
# processing: read data of relevant records, 'ir.model',
|
return result
|
||||||
# 'ir.model.fields'... (no interest in logging such operations)
|
self = self.with_context(auditlog_disabled=True)
|
||||||
if kwargs.get('context', {}).get('auditlog_disabled'):
|
rule_model = self.env['auditlog.rule']
|
||||||
return result
|
rule_model.sudo().create_logs(
|
||||||
env = api.Environment(cr, uid, {'auditlog_disabled': True})
|
self.env.uid, self._name, self.ids,
|
||||||
rule_model = env['auditlog.rule']
|
'read', read_values, None, {'log_type': log_type})
|
||||||
rule_model.sudo().create_logs(
|
|
||||||
env.uid, self._name, ids,
|
|
||||||
'read', read_values, None, {'log_type': log_type})
|
|
||||||
# New API
|
|
||||||
else:
|
|
||||||
# If the call came from auditlog itself, skip logging:
|
|
||||||
# avoid logs on `read` produced by auditlog during internal
|
|
||||||
# processing: read data of relevant records, 'ir.model',
|
|
||||||
# 'ir.model.fields'... (no interest in logging such operations)
|
|
||||||
if self.env.context.get('auditlog_disabled'):
|
|
||||||
return result
|
|
||||||
self = self.with_context(auditlog_disabled=True)
|
|
||||||
rule_model = self.env['auditlog.rule']
|
|
||||||
rule_model.sudo().create_logs(
|
|
||||||
self.env.uid, self._name, self.ids,
|
|
||||||
'read', read_values, None, {'log_type': log_type})
|
|
||||||
return result
|
return result
|
||||||
return read
|
return read
|
||||||
|
|
||||||
|
@ -307,7 +287,7 @@ class AuditlogRule(models.Model):
|
||||||
# afterwards as it could not represent the real state
|
# afterwards as it could not represent the real state
|
||||||
# of the data in the database
|
# of the data in the database
|
||||||
vals2 = dict(vals)
|
vals2 = dict(vals)
|
||||||
old_vals2 = dict.fromkeys(vals2.keys(), False)
|
old_vals2 = dict.fromkeys(list(vals2.keys()), False)
|
||||||
old_values = dict((id_, old_vals2) for id_ in self.ids)
|
old_values = dict((id_, old_vals2) for id_ in self.ids)
|
||||||
new_values = dict((id_, vals2) for id_ in self.ids)
|
new_values = dict((id_, vals2) for id_ in self.ids)
|
||||||
result = write_fast.origin(self, vals, **kwargs)
|
result = write_fast.origin(self, vals, **kwargs)
|
||||||
|
@ -382,7 +362,9 @@ class AuditlogRule(models.Model):
|
||||||
self._create_log_line_on_create(log, diff.added(), new_values)
|
self._create_log_line_on_create(log, diff.added(), new_values)
|
||||||
elif method is 'read':
|
elif method is 'read':
|
||||||
self._create_log_line_on_read(
|
self._create_log_line_on_read(
|
||||||
log, old_values.get(res_id, EMPTY_DICT).keys(), old_values)
|
log,
|
||||||
|
list(old_values.get(res_id, EMPTY_DICT).keys()), old_values
|
||||||
|
)
|
||||||
elif method is 'write':
|
elif method is 'write':
|
||||||
self._create_log_line_on_write(
|
self._create_log_line_on_write(
|
||||||
log, diff.changed(), old_values, new_values)
|
log, diff.changed(), old_values, new_values)
|
||||||
|
@ -527,49 +509,30 @@ class AuditlogRule(models.Model):
|
||||||
to view logs on that model.
|
to view logs on that model.
|
||||||
"""
|
"""
|
||||||
act_window_model = self.env['ir.actions.act_window']
|
act_window_model = self.env['ir.actions.act_window']
|
||||||
model_ir_values = self.env['ir.values']
|
|
||||||
for rule in self:
|
for rule in self:
|
||||||
# Create a shortcut to view logs
|
# Create a shortcut to view logs
|
||||||
domain = "[('model_id', '=', %s), ('res_id', '=', active_id)]" % (
|
domain = "[('model_id', '=', %s), ('res_id', '=', active_id)]" % (
|
||||||
rule.model_id.id)
|
rule.model_id.id)
|
||||||
vals = {
|
vals = {
|
||||||
'name': _(u"View logs"),
|
'name': _("View logs"),
|
||||||
'res_model': 'auditlog.log',
|
'res_model': 'auditlog.log',
|
||||||
'src_model': rule.model_id.model,
|
'src_model': rule.model_id.model,
|
||||||
|
'binding_model_id': rule.model_id.id,
|
||||||
'domain': domain,
|
'domain': domain,
|
||||||
}
|
}
|
||||||
act_window = act_window_model.sudo().create(vals)
|
act_window = act_window_model.sudo().create(vals)
|
||||||
rule.write({'state': 'subscribed', 'action_id': act_window.id})
|
rule.write({'state': 'subscribed', 'action_id': act_window.id})
|
||||||
keyword = 'client_action_relate'
|
|
||||||
value = 'ir.actions.act_window,%s' % act_window.id
|
|
||||||
model_ir_values.sudo().set_action(
|
|
||||||
'View_log_' + rule.model_id.model,
|
|
||||||
action_slot=keyword,
|
|
||||||
model=rule.model_id.model,
|
|
||||||
action=value)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def unsubscribe(self):
|
def unsubscribe(self):
|
||||||
"""Unsubscribe Auditing Rule on model."""
|
"""Unsubscribe Auditing Rule on model."""
|
||||||
act_window_model = self.env['ir.actions.act_window']
|
|
||||||
ir_values_model = self.env['ir.values']
|
|
||||||
# Revert patched methods
|
# Revert patched methods
|
||||||
self._revert_methods()
|
self._revert_methods()
|
||||||
for rule in self:
|
for rule in self:
|
||||||
# Remove the shortcut to view logs
|
# Remove the shortcut to view logs
|
||||||
act_window = act_window_model.search(
|
act_window = rule.action_id
|
||||||
[('name', '=', 'View Log'),
|
|
||||||
('res_model', '=', 'auditlog.log'),
|
|
||||||
('src_model', '=', rule.model_id.model)])
|
|
||||||
if act_window:
|
if act_window:
|
||||||
value = 'ir.actions.act_window,%s' % act_window.id
|
|
||||||
act_window.unlink()
|
act_window.unlink()
|
||||||
ir_value = ir_values_model.search(
|
|
||||||
[('model', '=', rule.model_id.model),
|
|
||||||
('value', '=', value)])
|
|
||||||
if ir_value:
|
|
||||||
ir_value.unlink()
|
|
||||||
self.write({'state': 'draft'})
|
self.write({'state': 'draft'})
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# © 2015 Therp BV <http://therp.nl>
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
from . import test_auditlog
|
from . import test_auditlog
|
||||||
from . import test_autovacuum
|
from . import test_autovacuum
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# © 2015 Therp BV <http://therp.nl>
|
# © 2015 Therp BV <http://therp.nl>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
from odoo.tests.common import TransactionCase
|
from odoo.tests.common import TransactionCase
|
||||||
|
@ -8,6 +7,9 @@ class TestAuditlog(object):
|
||||||
|
|
||||||
def test_LogCreation(self):
|
def test_LogCreation(self):
|
||||||
"""First test, caching some data."""
|
"""First test, caching some data."""
|
||||||
|
|
||||||
|
self.groups_rule.subscribe()
|
||||||
|
|
||||||
auditlog_log = self.env['auditlog.log']
|
auditlog_log = self.env['auditlog.log']
|
||||||
group = self.env['res.groups'].create({
|
group = self.env['res.groups'].create({
|
||||||
'name': 'testgroup1',
|
'name': 'testgroup1',
|
||||||
|
@ -32,6 +34,9 @@ class TestAuditlog(object):
|
||||||
|
|
||||||
def test_LogCreation2(self):
|
def test_LogCreation2(self):
|
||||||
"""Second test, using cached data of the first one."""
|
"""Second test, using cached data of the first one."""
|
||||||
|
|
||||||
|
self.groups_rule.subscribe()
|
||||||
|
|
||||||
auditlog_log = self.env['auditlog.log']
|
auditlog_log = self.env['auditlog.log']
|
||||||
testgroup2 = self.env['res.groups'].create({
|
testgroup2 = self.env['res.groups'].create({
|
||||||
'name': 'testgroup2',
|
'name': 'testgroup2',
|
||||||
|
@ -48,6 +53,8 @@ class TestAuditlog(object):
|
||||||
of a 'write' log with a deleted resource (so with no text
|
of a 'write' log with a deleted resource (so with no text
|
||||||
representation).
|
representation).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
self.groups_rule.subscribe()
|
||||||
auditlog_log = self.env['auditlog.log']
|
auditlog_log = self.env['auditlog.log']
|
||||||
testgroup3 = testgroup3 = self.env['res.groups'].create({
|
testgroup3 = testgroup3 = self.env['res.groups'].create({
|
||||||
'name': 'testgroup3',
|
'name': 'testgroup3',
|
||||||
|
@ -86,7 +93,6 @@ class TestAuditlogFull(TransactionCase, TestAuditlog):
|
||||||
'log_create': True,
|
'log_create': True,
|
||||||
'log_write': True,
|
'log_write': True,
|
||||||
'log_unlink': True,
|
'log_unlink': True,
|
||||||
'state': 'subscribed',
|
|
||||||
'log_type': 'full',
|
'log_type': 'full',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -107,7 +113,6 @@ class TestAuditlogFast(TransactionCase, TestAuditlog):
|
||||||
'log_create': True,
|
'log_create': True,
|
||||||
'log_write': True,
|
'log_write': True,
|
||||||
'log_unlink': True,
|
'log_unlink': True,
|
||||||
'state': 'subscribed',
|
|
||||||
'log_type': 'fast',
|
'log_type': 'fast',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# © 2016 ABF OSIELL <http://osiell.com>
|
# © 2016 ABF OSIELL <http://osiell.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
import time
|
import time
|
||||||
|
|
Loading…
Reference in New Issue