Skip to content

[IMP] purchase_deposit: make the deposit over total check optional - #3172

Merged
OCA-git-bot merged 1 commit into
OCA:18.0from
adhoc-dev:18.0-rm-purchase_deposit-deposit-over-total-check-mav
Sep 23, 2026
Merged

OCA-git-bot merged 1 commit into
OCA:18.0from
adhoc-dev:18.0-rm-purchase_deposit-deposit-over-total-check-mav

Conversation

@mav-adhoc

@mav-adhoc mav-adhoc commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

What

Puts the "deposit can't be greater than the PO total" check added in #2788 (18.0
only) behind a new company setting, Limit Deposits to Order Total, disabled by
default. Previous version of this PR removed the check; made it optional instead,
as @Saran440 suggested in the review.

Why

The check refuses legitimate deposits, and there is no way around it from the UI.

1. The two sides of the comparison are not the same base. It sums the deposit
lines' price_unit, which is tax excluded, and compares it against
order.amount_total, which is tax included. The effective ceiling therefore depends on
whether the order carries taxes: the untaxed total on a tax exempt order, the tax
included total on a taxed one. Deposit lines also carry product_qty = 0, so they never
contribute to amount_total themselves.

2. On a multi-currency order the sum it compares has no single right value. When the
order is in a foreign currency and the vendor bills the deposits in the company
currency, each deposit line holds an amount converted from the bill. Whichever rate that
conversion uses, the sum cannot serve as a hard limit:

  • at each bill's own date (what the module does, see [FIX] purchase_deposit: convert deposit amounts to the order currency #3141) the amount left to bill on
    the order floats with the exchange rate. An order advanced in fixed instalments of the
    company currency stops adding up, and the last instalment is refused even though every
    single amount is right.
  • at the order's own rate (purchase.order.currency_rate, the basis of
    amount_total_cc) a fully advanced order does add up — but only while that rate is
    still meaningful. On an order paid over a year or more in a high-inflation company
    currency, the order rate is stale and it inflates every later deposit instead.

I measured both bases against a set of real orders: each one unblocks some and blocks
others, several by a wide margin. That is not a bug in either conversion — an exchange
difference on a prepayment is real and has to be recognised somewhere. But it has to be
recognised in the accounting of the bills, not charged against a commercial control that
then refuses the operation.

Why the setting is disabled by default. 16.0, 17.0 and 19.0 do not have this check,
so a disabled default keeps 18.0 in line with the other branches, and the two points
above mean an enabled default keeps refusing operations that are correct. There is no
migration script: the setting starts disabled everywhere, and a deployment that wants
the ceiling enables it in Purchase > Configuration > Settings. For reference, core
sale handles the same situation with a non-blocking warning in the wizard
(display_invoice_amount_warning) rather than an error.

The error message is now diagnosable. It states the deposit total, the order total
and the currency, and its msgid is static again: it was built with an f-string inside
self.env._(), which made the msgid dynamic and the string untranslatable.

The readme fragment is renamed CONFIGURATION.rst → CONFIGURE.md, the name the readme
generator looks for; the old one never reached README.rst. README.rst itself is left
to the bot, as the CI expects for PRs that touch readme fragments.

Test plan

  • test_not_allow_deposit_greater_than_po_total is restored, with the setting enabled.
  • New test_allow_deposit_greater_than_po_total_by_default covers the default: the same
    deposit that the check refuses is created.
  • Full suite: 0 failed, 0 error(s) of 8 tests.
  • Rendered message, for the record: The deposits of P00045 would add up to $ 5,000.00, more than its total amount of $ 4,830.00.

@OCA-git-bot OCA-git-bot added series:18.0 mod:purchase_deposit Module purchase_deposit labels Sep 8, 2026
@mav-adhoc

Copy link
Copy Markdown
Contributor Author

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

@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

@mav-adhoc

Copy link
Copy Markdown
Contributor Author

Dropped the manifest version bump here too, per @HviorForgeFlow's review on #3142 — ocabot does it on merge, so no nobump needed on any of the three.

@mav-adhoc

Copy link
Copy Markdown
Contributor Author

For whoever merges: the red runboat/build here is not this PR. Every build of the 18.0 branch is failing at init, including the branch build itself (11184a7d7), while 19.0 deploys fine; the failures cluster on the heaviest branches across OCA repos and the platform reports its deployment cap reached. Reported upstream in sbidoul/runboat#158 with the details. Everything else — pre-commit, test with Odoo, test with OCB, codecov — is green.

@HviorForgeFlow

Copy link
Copy Markdown
Member

@Saran440 @TheerayutEncoder could you take a look as you worked on the feature to be removed here in #2788

@Saran440 Saran440 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 reviewed 👍

Sorry, I missed this use case before. I think this check should be configurable rather than hard-coded.

@mav-adhoc
mav-adhoc force-pushed the 18.0-rm-purchase_deposit-deposit-over-total-check-mav branch 2 times, most recently from 246c15a to b630ab1 Compare September 22, 2026 14:21
@mav-adhoc mav-adhoc changed the title [FIX] purchase_deposit: remove the deposit over total check [IMP] purchase_deposit: make the deposit over total check optional Sep 22, 2026
@mav-adhoc

Copy link
Copy Markdown
Contributor Author

@Saran440 good point — done: the check is back, behind a company setting (Limit Deposits to Order Total), disabled by default so that 18.0 matches the other branches. Your test is restored with the setting enabled. The scope of the PR changed, so a new look is welcome, @HviorForgeFlow @BhaveshHeliconia.

@mav-adhoc
mav-adhoc force-pushed the 18.0-rm-purchase_deposit-deposit-over-total-check-mav branch from b630ab1 to 20bde28 Compare September 22, 2026 14:32

@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.

That looks much better, I was affraid of removing the feature without asking their contributors.

Just a small nitpick...

Comment thread purchase_deposit/models/res_company.py Outdated
domain=[("type", "=", "service")],
help="Default product used for payment advances.",
)
purchase_deposit_limit_to_total = fields.Boolean(

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.

What about renaming to purchase_deposit_limit_order_total?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks!

@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). 🤖

The check added in OCA#2788 refuses legitimate deposits and offers no way
out from the UI, so it now depends on a company setting, "Limit Deposits
to Order Total", disabled by default:

- it compares the deposit lines' price_unit (tax excluded) against
  order.amount_total (tax included), so the effective ceiling depends on
  whether the order has taxes. Deposit lines also carry product_qty = 0
  and never contribute to amount_total.
- when the order is in a foreign currency and the vendor invoices the
  deposits in the company currency, each deposit line holds an amount
  converted at the rate of its own bill date, so the sum it adds up has
  no single right value to compare against.
- 16.0, 17.0 and 19.0 do not have the check, so a disabled default keeps
  18.0 in line with the other branches.

The error message now states the amounts and the currency, and its msgid
is static again: it was built with an f-string and never translated.

The configuration fragment is renamed to CONFIGURE.md, the name the
readme generator looks for, so that it reaches README.rst at last.
@mav-adhoc
mav-adhoc force-pushed the 18.0-rm-purchase_deposit-deposit-over-total-check-mav branch from 20bde28 to d133011 Compare September 22, 2026 19:13

@TheerayutEncoder TheerayutEncoder 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.

Looking good 💯

@HviorForgeFlow

Copy link
Copy Markdown
Member

/ocabot merge minor

@OCA-git-bot

Copy link
Copy Markdown
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 18.0-ocabot-merge-pr-3172-by-HviorForgeFlow-bump-minor, awaiting test results.

@HviorForgeFlow

Copy link
Copy Markdown
Member

@mav-adhoc mind you to forward the change to 19.0, thanks

@OCA-git-bot
OCA-git-bot merged commit da77bad into OCA:18.0 Sep 23, 2026
9 checks passed
@OCA-git-bot

Copy link
Copy Markdown
Contributor

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

@mav-adhoc

Copy link
Copy Markdown
Contributor Author

@HviorForgeFlow Done! #3182

bt-admin pushed a commit to brain-tec/purchase-workflow that referenced this pull request Sep 26, 2026
Forward port of OCA#3172. The check added in OCA#2788 never reached this
branch, so it arrives here already behind the company setting "Limit
Deposits to Order Total", disabled by default: the module keeps the
behaviour it has today, and a deployment that wants the ceiling enables
it in Purchase > Configuration > Settings.

It is not enforced by default because:

- it compares the deposit lines' price_unit (tax excluded) against
  order.amount_total (tax included), so the effective ceiling depends on
  whether the order has taxes. Deposit lines also carry product_qty = 0
  and never contribute to amount_total.
- when the order is in a foreign currency and the vendor invoices the
  deposits in the company currency, each deposit line holds an amount
  converted at the rate of its own bill date, so the sum it adds up has
  no single right value to compare against.

The error message states the amounts and the currency, so that a refusal
can be read without opening the order.

The configuration fragment is renamed to CONFIGURE.md, the name the
readme generator looks for, so that it reaches README.rst at last.
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.

8 participants