Skip to content

Commit

Permalink
Merge pull request #194 from ecosoft-odoo/15.0-add-usability_webhooks…
Browse files Browse the repository at this point in the history
…-is_create_logs

[15.0][ADD] usability_webhooks: can choose whether to keep log.
  • Loading branch information
Saran440 authored Aug 21, 2024
2 parents 5552782 + 0ea3404 commit d9f812f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
15 changes: 14 additions & 1 deletion usability_webhooks/controllers/main.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
16 changes: 16 additions & 0 deletions usability_webhooks/data/config_parameter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,20 @@
<field name="key">webhook.rollback_except</field>
<field name="value">1</field>
</record>
<record id="webhook_create_data_log" model="ir.config_parameter">
<field name="key">webhook.create_data_log</field>
<field name="value">True</field>
</record>
<record id="webhook_update_data_log" model="ir.config_parameter">
<field name="key">webhook.update_data_log</field>
<field name="value">True</field>
</record>
<record id="webhook_create_update_data_log" model="ir.config_parameter">
<field name="key">webhook.create_update_data_log</field>
<field name="value">True</field>
</record>
<record id="webhook_search_data_log" model="ir.config_parameter">
<field name="key">webhook.search_data_log</field>
<field name="value">True</field>
</record>
</odoo>

0 comments on commit d9f812f

Please sign in to comment.