Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.

Module: Key Performance Indicators

Entity: kpi.threshold.range

Compute Method: _compute_max_value

Inputs Method Outputs
for obj in self:
            value = None
            error = None
            try:
                if obj.max_type == "local" and is_sql_or_ddl_statement(obj.max_code):
                    self.env.cr.execute(obj.max_code)
                    dic = self.env.cr.dictfetchall()
                    if is_one_value(dic):
                        value = dic[0]["value"]
                elif (
                    obj.max_type == "external"
                    and obj.max_dbsource_id.id
                    and is_sql_or_ddl_statement(obj.max_code)
                ):
                    dbsrc_obj = obj.max_dbsource_id
                    res = dbsrc_obj.execute(obj.max_code)
                    if is_one_value(res):
                        value = res[0]["value"]
                elif obj.max_type == "python":
                    value = safe_eval(obj.max_code)
                else:
                    value = obj.max_fixed_value
            except Exception as e:
                value = None
                error = str(e)
            obj.max_value = value
            obj.max_error = error

Back to entity