11# Copyright 2025 Akretion (http://www.akretion.com).
22# @author Florian Mounier <florian.mounier@akretion.com>
3+ # Copyright 2025 Simone Rubino - PyTech
34# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
5+
46import base64
57import json
68import time
@@ -15,6 +17,21 @@ class APILog(models.Model):
1517 _name = "api.log"
1618 _description = "Log for API"
1719
20+ collection_ref = fields .Reference (
21+ selection = "_selection_collection_ref" ,
22+ index = True ,
23+ )
24+ collection_model = fields .Char (
25+ compute = "_compute_collection" ,
26+ store = True ,
27+ index = True ,
28+ )
29+ collection_id = fields .Integer (
30+ compute = "_compute_collection" ,
31+ store = True ,
32+ index = True ,
33+ )
34+
1835 # Request
1936 request_url = fields .Char ()
2037 request_method = fields .Char ()
@@ -59,6 +76,25 @@ class APILog(models.Model):
5976 compute = "_compute_response_headers_derived" , store = True
6077 )
6178
79+ @api .model
80+ def _selection_collection_ref (self ):
81+ return []
82+
83+ @api .depends (
84+ "collection_ref" ,
85+ )
86+ def _compute_collection (self ):
87+ for log in self :
88+ collection = log .collection_ref
89+ if collection :
90+ collection_model = collection ._name
91+ collection_id = collection .id
92+ else :
93+ collection_model = False
94+ collection_id = False
95+ log .collection_model = collection_model
96+ log .collection_id = collection_id
97+
6298 @api .model
6399 def _headers_hidden_keys (self ):
64100 """Header keys that should not be logged.
0 commit comments