Skip to content

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

Merged
OCA-git-bot merged 1 commit into
OCA:19.0from
adhoc-dev:19.0-imp-purchase_deposit-deposit-over-total-check-mav
Sep 25, 2026
Merged

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

Conversation

@mav-adhoc

Copy link
Copy Markdown
Contributor

What

Forward port of #3172, as asked for there.

The "deposit can't be greater than the PO total" check added in #2788 never
reached this branch, so it arrives here already behind the company setting
Limit Deposits to Order Total, disabled by default. Nothing changes for an
existing deployment: a deposit over the order total is still accepted, and the
ceiling is opt-in from Purchase > Configuration > Settings.

Why it is disabled by default

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 #3142) 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) 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.

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. For
reference, core sale handles the same situation with a non-blocking warning in the
wizard (display_invoice_amount_warning) rather than an error.

There is no migration script: the setting starts disabled everywhere.

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

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 and
    test_not_allow_deposit_over_total_with_deposit_already_invoiced cover the check with
    the setting enabled. Both fail if the guarded block is removed.
  • 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 9 tests.

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

Copy link
Copy Markdown
Contributor Author

@HviorForgeFlow Can you review it please? Thanks!

@UsmanGhias UsmanGhias left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Clean patch for OCA/purchase-workflow.

Observations:

  • Code structure follows standard OCA guidelines and cleanly isolates the extension logic.

Ready for testing on standard environments.

Best,
Usman

@HviorForgeFlow

Copy link
Copy Markdown
Member

/ocabot merge minor

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 19.0-ocabot-merge-pr-3182-by-HviorForgeFlow-bump-minor, awaiting test results.

@OCA-git-bot
OCA-git-bot merged commit de52341 into OCA:19.0 Sep 25, 2026
7 checks passed
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at c3edd5c. 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.

4 participants