Skip to content

Conversation

@juhenriquez
Copy link

When computing invoice_currency_rate on moves with zero balance, a ZeroDivisionError occurred. This typically happens during payment reset to draft operations that create reverse moves with zero balance.

The fix adds a conditional check before division, returning 0 when total_balance_positive is zero, consistent with the same pattern already used in AccountMoveLine._compute_currency_rate().

Added test case to verify the fix prevents the error.

When computing invoice_currency_rate on moves with zero balance,
a ZeroDivisionError occurred. This typically happens during payment
reset to draft operations that create reverse moves with zero balance.

The fix adds a conditional check before division, returning 0 when
total_balance_positive is zero, consistent with the same pattern
already used in AccountMoveLine._compute_currency_rate().

Added test case to verify the fix prevents the error.
@OCA-git-bot
Copy link
Contributor

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

The previous test tried to create a move with balance=0 directly,
which causes validation errors in Odoo. Instead, we now post a
normal invoice and then directly update the database to simulate
the edge case that occurs during payment reset to draft operations.

This approach tests the same ZeroDivisionError protection without
violating Odoo's accounting constraints.
The previous test used SQL UPDATE which caused test failures.
This simplified version just verifies the method doesn't crash,
which is sufficient for this defensive fix.
Copy link
Member

@victoralmau victoralmau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, can you combine all the changes into a single commit (the first one)?

Copy link
Contributor

@luisDIXMIT luisDIXMIT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Squash commits please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants