[16.0][IMP] account_payment_partner: add flag to control partner_bank_id without payment mode#1555
Conversation
|
Added a dedicated test (
This test fails without the code fix and passes with it. |
Temporary dependency on OCA/bank-payment#1555 to fix test_force_out_invoice_create_refund failure. Remove this commit once the PR is merged and released.
Temporary dependency on OCA/bank-payment#1555 to fix test_force_out_invoice_create_refund failure. Remove this commit once the PR is merged and released.
Temporary dependency on OCA/bank-payment#1555 to fix test_force_out_invoice_create_refund failure. Remove this commit once the PR is merged and released.
Temporary dependency on OCA/bank-payment#1555 to fix test_force_out_invoice_create_refund failure. Remove this commit once the PR is merged and released.
Temporary dependency on OCA/bank-payment#1555 to fix test_force_out_invoice_create_refund failure. Remove this commit once the PR is merged and released.
Temporary dependency on OCA/bank-payment#1555 to fix test_force_out_invoice_create_refund failure. Remove this commit once the PR is merged and released.
|
cc @rvalyi |
|
ping @OCA/banking-maintainers |
|
Thanks for the PR, but did you check #1418 before? |
…thout payment mode Add a company-level setting keep_partner_bank_without_payment_mode (default True) that controls whether partner_bank_id is preserved or cleared when no payment mode is set on an invoice. When enabled (default), invoices without a payment mode keep the bank account auto-selected by Odoo core. When disabled, the bank account is cleared (legacy behavior). This resolves the long-standing disagreement in OCA#1418 by letting each company choose the behavior that fits their workflow.
Update test_onchange_payment_mode_id to reflect the new default behavior (flag=True keeps bank account). Add test_no_payment_mode_clears_bank_when_flag_disabled to verify that disabling the flag restores the legacy clearing behavior. Add test_refund_no_payment_mode_preserves_partner_bank to verify that refunds without payment mode preserve the bank account.
02146e4 to
aa8e643
Compare
|
@grindtildeath Thanks for pointing that out — we were not aware of #1418 when we opened this PR. We've now reviewed the full discussion there and understand the concerns from both sides. Update: company-level flag approachBased on the consensus suggested by @pedrobaeza in #1418 (comment), we've updated this PR to add a company-level flag instead of simply removing the New field
What changes in practice
Files modified
Tests
All 20 tests passing, 0 failures. @sbidoul Would you be OK with us addressing this in our PR? We're in urgent need of this fix because the OCA/l10n-brazil CI is completely blocked — all open PRs are failing due to |
pedrobaeza
left a comment
There was a problem hiding this comment.
Thanks for doing the changes to reconcile both behaviors. I accept to switch the default behavior to the new one to preserve the bank account.
Let's merge this one:
/ocabot merge patch
|
On my way to merge this fine PR! |
|
@pedrobaeza ocabot fail? |
|
/ocabot merge patch |
|
On my way to merge this fine PR! |
|
@pedrobaeza your merge command was aborted due to failed check(s), which you can inspect on this commit of 16.0-ocabot-merge-pr-1555-by-pedrobaeza-bump-patch. After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red. |
|
The pre-commit checks are currently failing due to setuptools. I’m going to open a PR updating the repository (via copier update) to switch from setup.py to pyproject.toml, which should fix the issue. |
|
I opened a PR with the pre-commit fix here: #1559 |
|
/ocabot merge patch |
|
Hey, thanks for contributing! Proceeding to merge this for you. |
|
Congratulations, your PR was merged at 5cd82ff. Thanks a lot for contributing to OCA. ❤️ |
|
Thanks @felipemotter for this PR and for the addition of configuration parameter ! |
|
@remi-filament i can do this. |
Summary
After OCB commit 7763099c (backported to OCB 16.0 on Feb 10, 2026), the core
_compute_partner_bank_idmethod now filters bank accounts by theallow_out_paymentfield and the reversal wizard explicitly calls_compute_partner_bank_id()after creating reversed moves.The
account_payment_partneroverride of_compute_partner_bank_idhad anelsebranch that unconditionally setpartner_bank_id = Falsewhen nopayment_mode_idwas present. This discarded the value computed bysuper(), preventing trusted bank accounts (withallow_out_payment=True) from being auto-selected.Why PR #1554 is not sufficient
PR #1554 (already merged) added
allow_out_payment=Trueto test bank accounts, which fixed theaccount_payment_partnerown tests. However, it did not address the root cause in the code logic.The issue is specifically in
_compute_partner_bank_idataccount_payment_partner/models/account_move.py:When no
payment_mode_idis set, theelsebranch overrides whateversuper()computed. After the OCB change,super()correctly auto-selects trusted bank accounts filtered byallow_out_payment=True, but this override discards the result.This is particularly visible in the OCA/l10n-brazil multi-localization tests (
test_force_out_invoice_create_refund), where:partner_bank_id=Falseas default_compute_partner_bank_id()to recomputesuper()correctly finds the partner's bank account (withallow_out_payment=True)account_payment_partner'selsebranch immediately clears it toFalseSince the test uses a US company (no Brazilian fiscal operations, no payment modes),
payment_mode_idis empty, and the bank account is always cleared — causing all open PRs in OCA/l10n-brazil to fail CI.Root cause
The
else: move.partner_bank_id = Falsewas added to prevent auto-filling bank accounts without a payment mode. However, since OCB now usesallow_out_payment(defaultFalse, opt-in) to control which accounts are trusted for auto-selection, this guard is no longer needed — the core already ensures only explicitly trusted accounts are used.Solution
else: move.partner_bank_id = Falsebranch from_compute_partner_bank_id, so the value computed bysuper()is preserved when no payment mode is settest_onchange_payment_mode_idto expect the bank account to remain set after removing the payment mode (since the bank hasallow_out_payment=True, core auto-selects it)How to reproduce
Install
account_payment_partnerwith OCB 16.0 (commit ada7a398f or later, which includes 7763099c). Then run the OCA/l10n-brazil multi-localization test:partner_bank_idisFalse(test fails)partner_bank_idis correctly set to the partner's trusted bank account (test passes)