Skip to content

Commit

Permalink
Merge PR OCA#1521 into 13.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Nov 26, 2023
2 parents 851a619 + 8577db7 commit 3b9a350
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
27 changes: 17 additions & 10 deletions web_environment_ribbon/models/web_environment_ribbon_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models
from odoo.tools.safe_eval import safe_eval


class WebEnvironmentRibbonBackend(models.AbstractModel):
Expand All @@ -14,23 +15,29 @@ def _prepare_ribbon_format_vals(self):
return {"db_name": self.env.cr.dbname}

@api.model
def _prepare_ribbon_name(self):
name_tmpl = self.env["ir.config_parameter"].sudo().get_param("ribbon.name")
def _prepare_ribbon_eval_environment(self):
return {"env": self.env}

@api.model
def _get_ribbon_value(self, name):
ir_config_model = self.env["ir.config_parameter"].sudo()
code = ir_config_model.get_param("ribbon.%s.code" % name)
if code:
return safe_eval(
code, globals_dict=self._prepare_ribbon_eval_environment(),
)
value_tmpl = ir_config_model.get_param("ribbon.%s" % name)
vals = self._prepare_ribbon_format_vals()
return name_tmpl and name_tmpl.format(**vals) or name_tmpl
return value_tmpl and value_tmpl.format(**vals) or value_tmpl

@api.model
def get_environment_ribbon(self):
"""
This method returns the ribbon data from ir config parameters
:return: dictionary
"""
ir_config_model = self.env["ir.config_parameter"]
name = self._prepare_ribbon_name()
return {
"name": name,
"color": ir_config_model.sudo().get_param("ribbon.color"),
"background_color": ir_config_model.sudo().get_param(
"ribbon.background.color"
),
"name": self._get_ribbon_value("name"),
"color": self._get_ribbon_value("color"),
"background_color": self._get_ribbon_value("background.color"),
}
3 changes: 3 additions & 0 deletions web_environment_ribbon/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
colors or just set to "False" to use default values.
* You can add the database name in the ribbon by adding "{db_name}" in the
system parameter "ribbon.name".
* By appending ".code", you can fill in a Python expression to generate the
ribbon name or colors: "ribbon.name.code" could contain "env.cr.dbname",
which just returns the current database's name.

0 comments on commit 3b9a350

Please sign in to comment.