Skip to content

[19.0][FIX] kpi: compute recurring KPIs more than once - #1249

Open
miquelrosell99 wants to merge 3 commits into
OCA:19.0from
miquelrosell99:19.0-fix-kpi-scheduler
Open

miquelrosell99 wants to merge 3 commits into
OCA:19.0from
miquelrosell99:19.0-fix-kpi-scheduler

Conversation

@miquelrosell99

Copy link
Copy Markdown
Contributor

The scheduler domain

["&", "|", ("active", "=", True), ("next_execution_date", "<=", now), ("next_execution_date", "=", False)]

parses as (active OR due) AND (never scheduled), so a computed KPI is picked up exactly once: as soon as next_execution_date is set after the first run, the KPI never matches again and is never recomputed.

Fixed to active AND (due OR never scheduled).

Also in this PR:

  • catch compute errors per KPI, so one failing KPI no longer silently skips the rest of the scheduled batch (previously a single try/except around the whole loop aborted the remaining KPIs)
  • build next_execution_date from fields.Datetime.now() instead of naive local datetime.now() formatted with DEFAULT_SERVER_DATETIME_FORMAT
  • fix kpi.history name default: default=fields.Datetime.now() is evaluated once at server boot, so every unnamed history row gets the boot timestamp

Tests: two new scheduler tests (rescheduling a due KPI, and batch isolation when one KPI raises).

The scheduler domain
["&", "|", (active), (due), (never scheduled)] parses as
(active OR due) AND (never scheduled), so a computed KPI is picked up
exactly once: as soon as next_execution_date is set, the KPI is never
computed again. Require active AND (due OR never scheduled).

Also:
- catch compute errors per KPI so one failing KPI no longer silently
  skips the rest of the batch
- build next_execution_date from fields.Datetime.now() instead of naive
  local datetime.now()
- fix kpi.history name default evaluated once at server boot
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @max3903,
some modules you are maintaining are being modified, check this out!

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