summaryrefslogtreecommitdiff
path: root/auditlog/models/auditlog_log_line_view.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-02-06 15:29:55 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-02-06 15:29:55 +0700
commit7cfed1e19f2e340d966ed2068176d21a0e8e9834 (patch)
treeec9077cb4f89d23378ef09f9da0adb7135548081 /auditlog/models/auditlog_log_line_view.py
parent4b3b2d8b1a9a7a72fbe3d623e93dea3802ef0e56 (diff)
add audit log
Diffstat (limited to 'auditlog/models/auditlog_log_line_view.py')
-rw-r--r--auditlog/models/auditlog_log_line_view.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/auditlog/models/auditlog_log_line_view.py b/auditlog/models/auditlog_log_line_view.py
new file mode 100644
index 0000000..4703b95
--- /dev/null
+++ b/auditlog/models/auditlog_log_line_view.py
@@ -0,0 +1,69 @@
+from odoo import fields, models, tools
+
+
+class AuditlogLogLineView(models.Model):
+ _name = "auditlog.log.line.view"
+ _inherit = "auditlog.log.line"
+ _description = "Auditlog - Log details (fields updated)"
+ _auto = False
+ _log_access = True
+
+ name = fields.Char()
+ model_id = fields.Many2one("ir.model")
+ model_name = fields.Char()
+ model_model = fields.Char()
+ res_id = fields.Integer()
+ user_id = fields.Many2one("res.users")
+ method = fields.Char()
+ http_session_id = fields.Many2one(
+ "auditlog.http.session", string="Session", index=True
+ )
+ http_request_id = fields.Many2one(
+ "auditlog.http.request", string="HTTP Request", index=True
+ )
+ log_type = fields.Selection(
+ selection=lambda r: r.env["auditlog.rule"]._fields["log_type"].selection,
+ string="Type",
+ )
+
+ def _select_query(self):
+ return """
+ alogl.id,
+ alogl.create_date,
+ alogl.create_uid,
+ alogl.write_uid,
+ alogl.write_date,
+ alogl.field_id,
+ alogl.log_id,
+ alogl.old_value,
+ alogl.new_value,
+ alogl.old_value_text,
+ alogl.new_value_text,
+ alogl.field_name,
+ alogl.field_description,
+ alog.name,
+ alog.model_id,
+ alog.model_name,
+ alog.model_model,
+ alog.res_id,
+ alog.user_id,
+ alog.method,
+ alog.http_session_id,
+ alog.http_request_id,
+ alog.log_type
+ """
+
+ def _from_query(self):
+ return """
+ auditlog_log_line alogl
+ JOIN auditlog_log alog ON alog.id = alogl.log_id
+ """
+
+ def _query(self):
+ return "SELECT %s FROM %s" % (self._select_query(), self._from_query())
+
+ def init(self):
+ tools.drop_view_if_exists(self.env.cr, self._table)
+ self.env.cr.execute(
+ """CREATE or REPLACE VIEW %s as (%s)""" % (self._table, self._query())
+ )