Skip to content

[17.0][IMP] kpi: add _get_eval_context hook#1177

Open
miquelrosell99 wants to merge 1 commit into
OCA:17.0from
miquelrosell99:17.0-kpi-add-get-eval-context-hook
Open

[17.0][IMP] kpi: add _get_eval_context hook#1177
miquelrosell99 wants to merge 1 commit into
OCA:17.0from
miquelrosell99:17.0-kpi-add-get-eval-context-hook

Conversation

@miquelrosell99

Copy link
Copy Markdown
Contributor

This PR introduces a _get_eval_context hook on the kpi model.

Currently, any module that wants to inject additional safe globals into Python KPI formulas has to override the entire _get_kpi_value method. This is fragile and duplicates core logic.

By extracting the safe_eval context into a dedicated method, other modules can simply inherit from kpi and override _get_eval_context to add their own helpers (e.g. dateutil, mean, domain-specific functions).

Changes:

  • Add kpi._get_eval_context() returning the default context.
  • Use self._get_eval_context() inside _get_kpi_value for Python KPIs.
  • Add a test verifying the default context contains self and datetime, and that it is used during KPI evaluation.

Extracts the safe_eval context into a dedicated method so other
modules can extend it without overriding the whole _get_kpi_value
method. This makes the KPI engine more extensible for custom
safe-eval globals.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants