Skip to content

[FIX] purchase_deposit: convert deposit amounts to the order currency - #3142

Merged
OCA-git-bot merged 1 commit into
OCA:19.0from
adhoc-dev:19.0-fix-purchase_deposit-guard-multicurrency-mav
Sep 10, 2026
Merged

OCA-git-bot merged 1 commit into
OCA:19.0from
adhoc-dev:19.0-fix-purchase_deposit-guard-multicurrency-mav

Conversation

@mav-adhoc

@mav-adhoc mav-adhoc commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

What

action_post copies the deposit amount from the vendor bill back into the purchase
order line. When the bill is issued in a currency other than the order one the figure
was copied verbatim, so an order in a strong currency ended up with a deposit line
holding the nominal of a weak one — three orders of magnitude off, in the case that
brought us here.

This converts it to the order currency, at the bill date.

Why it matters beyond the wrong figure

The deposit line's price_unit is not only informative: it is the amount deducted from
the final bill (_prepare_account_move_line puts the deposit line in with
quantity = -qty_invoiced), and on 18.0 it is also what the wizard compares against the
order total. So a bill figure landing there unconverted both corrupts the deduction and,
on 18.0, makes any further deposit on that order impossible.

Deposits billed in the order currency are unaffected: the conversion rate is exactly 1.

Test plan

test_deposit_billed_in_another_currency: an order in a currency worth 1000x the
company one, a deposit of 300, and a bill edited to the company currency for 300,000.
Without the fix the order line ends up at 300000.0; with it, at 300.0.

Full suite green (7 tests on 18.0, 6 on 19.0).

@OCA-git-bot OCA-git-bot added series:19.0 mod:purchase_deposit Module purchase_deposit labels Aug 6, 2026
@mav-adhoc
mav-adhoc force-pushed the 19.0-fix-purchase_deposit-guard-multicurrency-mav branch from 7495c36 to 66afe92 Compare August 6, 2026 18:53

@BhaveshHeliconia BhaveshHeliconia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

Just minor comments

from odoo.tests import TransactionCase


class TestPurchaseDepositMultiCurrency(TransactionCase):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
class TestPurchaseDepositMultiCurrency(TransactionCase):
class TestPurchaseDepositMultiCurrency(Basecommon):

Comment on lines +18 to +20
(
0,
0,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
(
0,
0,
Command.create(

Comment on lines +40 to +42
(
0,
0,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
(
0,
0,
Command.create(

@mav-adhoc

Copy link
Copy Markdown
Contributor Author

Hi @HviorForgeFlow! Can you review the fix please? Thanks

@mav-adhoc
mav-adhoc force-pushed the 19.0-fix-purchase_deposit-guard-multicurrency-mav branch from 66afe92 to a68b654 Compare September 8, 2026 18:28
@mav-adhoc mav-adhoc changed the title [FIX] purchase_deposit: convert deposit amounts to the order currency [FIX] purchase_deposit: measure the deposit at the order rate Sep 8, 2026
@mav-adhoc

Copy link
Copy Markdown
Contributor Author

Applied the review suggestions in both branches: the test case now inherits from BaseCommon and builds its data with Command.create. Thanks @BhaveshHeliconia.

Heads-up, since this was already approved: the fix itself changed. It used to convert the deposit at the bill date, it now converts at the order rate (purchase.order.currency_rate), which is the basis the order total already uses. The reasoning is in the updated description — converting at the bill date makes the amount left to bill on an order float with the exchange rate, and a fully advanced order stops adding up. The test was extended so it discriminates between the two. Worth a fresh look rather than carrying the previous approval over.

@mav-adhoc
mav-adhoc force-pushed the 19.0-fix-purchase_deposit-guard-multicurrency-mav branch from a68b654 to e4bedf7 Compare September 8, 2026 18:33
@mav-adhoc mav-adhoc changed the title [FIX] purchase_deposit: measure the deposit at the order rate [FIX] purchase_deposit: convert deposit amounts to the order currency Sep 8, 2026
@mav-adhoc

Copy link
Copy Markdown
Contributor Author

Sorry for the churn: I briefly pushed a version that converted the deposit at the order rate instead of the bill date, and I have reverted it. It looked like the better basis — it is the one purchase.order.currency_rate/amount_total_cc use, and it makes an order advanced in fixed instalments of the company currency add up exactly. But measuring an old order at its own rate is only right while that rate is still meaningful: on a long-lived order in a foreign currency, paid over a year or more in a high-inflation company currency, the order rate is stale and it inflates every later deposit. I checked it against real orders and it would have newly blocked several of them, some by a wide margin. There is no single conversion basis that is right for every order, so this PR stays on the bill date and the deposit stays worth what was actually paid.

The only difference from the version you approved is your two test suggestions, now applied in both branches. Thanks again @BhaveshHeliconia.

@BhaveshHeliconia BhaveshHeliconia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@les-adhoc les-adhoc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@HviorForgeFlow HviorForgeFlow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Code looks good, thanks for the contribution.

Just a minor alignment

Comment thread purchase_deposit/__manifest__.py Outdated
{
"name": "Purchase Deposit",
"version": "19.0.1.0.0",
"version": "19.0.1.0.1",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

don't change version, ocabot will do

@mav-adhoc
mav-adhoc force-pushed the 19.0-fix-purchase_deposit-guard-multicurrency-mav branch 2 times, most recently from 4b274ff to 03be572 Compare September 9, 2026 15:13
@mav-adhoc

Copy link
Copy Markdown
Contributor Author

Thanks @HviorForgeFlow. Version bump dropped, the manifest is untouched now — same in the 18.0 counterpart (#3141) and in #3172, so all three can be merged with the plain /ocabot merge patch.

About the red test with Odoo / test with OCB: it is not this PR. purchase_deposit runs clean (purchase_deposit: 10 tests, no failure); the only failing test is purchase_order_line_description's tour, which is red on every open PR of the 19.0 branch right now — #3152 hits the exact same step.

I tracked it down and it is a core change: since odoo/odoo#285946 the read-only label of product_label_section_and_note_field is only rendered as cell text when the label is actually read-only, which on an open order it is not, so the description now lives in a textarea value and :contains() no longer matches it. Fix in #3174 (test-only, two selectors), verified against core 5587c47a865 and current e809d194b88. Once that one lands the 19.0 branch goes green again and I will rebase this PR on top.

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Sorry @mav-adhoc you are not allowed to merge.

To do so you must either have push permissions on the repository, or be a declared maintainer of all modified addons.

If you wish to adopt an addon and become it's maintainer, open a pull request to add your GitHub login to the maintainers key of its manifest.

}
)

def test_deposit_billed_in_another_currency(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you add this test case to test_purchase_deposit.py instead of creating a separate test file?

Also, if AI was used for this contribution, please add the Assisted-by: trailer according to the OCA AI policy.

https://github.com/OCA/.github/blob/master/AI_POLICY.md

@HviorForgeFlow HviorForgeFlow Sep 10, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Attend comments @mav-adhoc, moving test is enough for now

When the vendor bills a deposit in a currency other than the order one,
action_post copied the bill figure into the order line verbatim, so an
order in a strong currency ended up holding the nominal of a weak one.
Convert it at the bill date instead.

Deposits billed in the order currency are unaffected: the conversion
rate is exactly 1.

Assisted-by: Claude Opus 5
@mav-adhoc
mav-adhoc force-pushed the 19.0-fix-purchase_deposit-guard-multicurrency-mav branch from 03be572 to 1937d19 Compare September 10, 2026 12:46
@mav-adhoc

Copy link
Copy Markdown
Contributor Author

@Saran440 @HviorForgeFlow Done! Thnaks to both of you!

@HviorForgeFlow

Copy link
Copy Markdown
Member

/ocabot merge patch

@OCA-git-bot

Copy link
Copy Markdown
Contributor

On my way to merge this fine PR!
Prepared branch 19.0-ocabot-merge-pr-3142-by-HviorForgeFlow-bump-patch, awaiting test results.

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@OCA-git-bot
OCA-git-bot merged commit 1599f33 into OCA:19.0 Sep 10, 2026
7 checks passed
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at e19c41a. Thanks a lot for contributing to OCA. ❤️

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.

7 participants