From 6e4be30e3abfc8cd34dfc568bb1c3e6cc59047ea Mon Sep 17 00:00:00 2001 From: git_admin Date: Mon, 27 Apr 2026 08:46:55 +0000 Subject: [PATCH] Tower: upload rpc_helper 16.0.1.0.0 (via marketplace) --- addons/rpc_helper/patch.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 addons/rpc_helper/patch.py diff --git a/addons/rpc_helper/patch.py b/addons/rpc_helper/patch.py new file mode 100644 index 0000000..c3a0569 --- /dev/null +++ b/addons/rpc_helper/patch.py @@ -0,0 +1,30 @@ +# Copyright 2022 Camptocamp SA +# @author: Simone Orsi +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +import odoo +from odoo.exceptions import UserError +from odoo.tools.translate import _ + + +def protected__execute_cr(cr, uid, obj, method, *args, **kw): + # Same as original func in odoo.service.model.execute_cr + cr.reset() + recs = odoo.api.Environment(cr, uid, {}).get(obj) + if recs is None: + raise UserError(_("Object %s doesn't exist", obj)) + # custom code starts here + if not _rpc_allowed(recs, method): + raise UserError(_("RPC call on %s is not allowed", obj)) + return protected__execute_cr._orig__execute_cr(cr, uid, obj, method, *args, **kw) + + +def _rpc_allowed(recordset, method): + config = getattr(recordset, "_disable_rpc", None) + if config is None: + config = ( + recordset.env["ir.model"]._get_rpc_config(recordset._name).get("disable") + ) + if config is None: + return True + return "all" not in config and method not in config