Skip to content

[18.0] FIX sponsorship_compassion: ZeroDivisionError in origin conversion rate - #2212

Merged
Danielgergely merged 1 commit into
18.0from
fix-origin-conversion-rate-zero-division
Nov 13, 2026
Merged

Danielgergely merged 1 commit into
18.0from
fix-origin-conversion-rate-zero-division

Conversation

@davidwul

Copy link
Copy Markdown
Contributor

Problem

Assigning a SUB sponsorship (via sds.subsponsorship.wizard) crashed with:

File "sponsorship_compassion/models/contract_origin.py", line 110, in _compute_won_sponsorships
    len(contract_ids.filtered("activation_date"))
ZeroDivisionError: float division by zero

The conversion rate only counts contracts without a parent_id. When the origin of the SUB only has sub sponsorships, the denominator is 0.

Fix

  • conversion_rate falls back to 0.0 when the origin has no contract without a parent.
  • The stats are computed for every origin (not only those with contracts), so an origin that loses its last contract is reset instead of keeping stale values.
  • @api.depends also covers contract_ids.parent_id and contract_ids.state, which the compute already reads.

Notes

  • Python-only change: a server restart is enough to fix the crash. Running -u sponsorship_compassion also recomputes the stored values that are already wrong.
  • Not tested in an Odoo instance yet; ruff and pylint-odoo pass.

🤖 Generated with Claude Code

…as sub sponsorships

Assigning a SUB sponsorship to an origin whose contracts all have a parent
raised ZeroDivisionError in _compute_won_sponsorships. Compute the stats for
every origin (reset when no contract left), default the rate to 0 and also
depend on contract parent_id/state.

Assisted-by: claude-opus-5-5, medium, claude-code
@Danielgergely
Danielgergely merged commit e28a161 into 18.0 Nov 13, 2026
1 check passed
@Danielgergely
Danielgergely deleted the fix-origin-conversion-rate-zero-division branch November 13, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants