Skip to content

[17.0][IMP] kpi: expose dateutil and mean in safe_eval context#1176

Open
miquelrosell99 wants to merge 2 commits into
OCA:17.0from
miquelrosell99:17.0-add-dateutil-and-mean-to-kpi-safe-eval
Open

[17.0][IMP] kpi: expose dateutil and mean in safe_eval context#1176
miquelrosell99 wants to merge 2 commits into
OCA:17.0from
miquelrosell99:17.0-add-dateutil-and-mean-to-kpi-safe-eval

Conversation

@miquelrosell99

Copy link
Copy Markdown
Contributor

This PR extends the Python KPI safe_eval context with two additional helpers:

  • dateutil: useful for date arithmetic, especially relativedelta, in time-based KPI formulas.
  • mean: convenience function from the statistics module to compute averages directly in KPI formulas.

Both are commonly needed in real-world KPI definitions and avoid requiring custom modules just to expose these utilities.

Commits:

  1. [IMP] kpi: expose dateutil in safe_eval context
  2. [IMP] kpi: expose mean function in safe_eval context

Includes tests for both helpers.

Allows KPI Python expressions to reference the dateutil module,
which is essential for date arithmetic (e.g. relativedelta) in
KPI formulas.
Allows KPI Python expressions to use the mean() function from the
statistics module, making it easy to compute averages in KPI
formulas without requiring a custom module.
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