From 0ea3404c0fe6f36b3f84d50c53c5e08df8ac95cc Mon Sep 17 00:00:00 2001 From: Pani-k-folk Date: Tue, 23 Jul 2024 19:53:25 +0700 Subject: [PATCH] [ADD] usability_webhooks: can choose whether to keep log --- usability_webhooks/controllers/main.py | 15 ++++++++++++++- usability_webhooks/data/config_parameter.xml | 16 ++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/usability_webhooks/controllers/main.py b/usability_webhooks/controllers/main.py index f14d60c..7cfaad6 100644 --- a/usability_webhooks/controllers/main.py +++ b/usability_webhooks/controllers/main.py @@ -1,6 +1,7 @@ # Copyright 2022 Ecosoft Co., Ltd (http://ecosoft.co.th/) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) +import ast import json import traceback @@ -37,25 +38,37 @@ def _create_api_logs(self, model, vals, function): # Error from odoo exception, rollback all data (if config in system parameter) if rollback_except: request.env.cr.rollback() - request.env["api.log"].create(data_dict) + if vals["is_create_log"]: + request.env["api.log"].create(data_dict) return res + def _set_create_logs(self, param, vals): + ICP = request.env["ir.config_parameter"] + is_create_log = ICP.sudo().get_param(param) + # convert str to bool + is_create_log = ast.literal_eval(is_create_log.capitalize()) + vals.update({"is_create_log": is_create_log}) + @http.route("/api/create_data", type="json", auth="user") def create_data(self, model, vals): + self._set_create_logs("webhook.create_data_log", vals) res = self._create_api_logs(model, vals, "create_data") return res @http.route("/api/update_data", type="json", auth="user") def update_data(self, model, vals): + self._set_create_logs("webhook.update_data_log", vals) res = self._create_api_logs(model, vals, "update_data") return res @http.route("/api/create_update_data", type="json", auth="user") def create_update_data(self, model, vals): + self._set_create_logs("webhook.create_update_data_log", vals) res = self._create_api_logs(model, vals, "create_update_data") return res @http.route("/api/search_data", type="json", auth="user") def search_data(self, model, vals): + self._set_create_logs("webhook.search_data_log", vals) res = self._create_api_logs(model, vals, "search_data") return res diff --git a/usability_webhooks/data/config_parameter.xml b/usability_webhooks/data/config_parameter.xml index e49460b..edf3d17 100644 --- a/usability_webhooks/data/config_parameter.xml +++ b/usability_webhooks/data/config_parameter.xml @@ -8,4 +8,20 @@ webhook.rollback_except 1 + + webhook.create_data_log + True + + + webhook.update_data_log + True + + + webhook.create_update_data_log + True + + + webhook.search_data_log + True +