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

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.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions Bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Nov 1, 2026
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.
@miquelrosell99
miquelrosell99 force-pushed the 17.0-kpi-add-get-eval-context-hook branch from 939e293 to 2de3f33 Compare November 2, 2026 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:kpi Module kpi series:17.0 stale PR/Issue without recent activity, it'll be soon closed automatically.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants