Skip to content

[16.0][IMP] account_payment_partner:Check first if payment method is sepa_direct_debit#1566

Open
ekainlarrea wants to merge 2 commits intoOCA:16.0from
Digital5-Odoo:16.0.0-fix-account_payment_partner
Open

[16.0][IMP] account_payment_partner:Check first if payment method is sepa_direct_debit#1566
ekainlarrea wants to merge 2 commits intoOCA:16.0from
Digital5-Odoo:16.0.0-fix-account_payment_partner

Conversation

@ekainlarrea
Copy link
Copy Markdown

…irect_debit

When partner_bank_id is set will be printed even if payment mode is sepa_direct_debit not showing clients bank account.
This PR fixes it.

@pedrobaeza pedrobaeza changed the title [IMP] account_payment_partner:Check first if payment method is sepa_d… [16.0][IMP] account_payment_partner:Check first if payment method is sepa_direct_debit Mar 3, 2026
@pedrobaeza pedrobaeza added this to the 16.0 milestone Mar 3, 2026
@pedrobaeza
Copy link
Copy Markdown
Member

If you have set a partner bank in the invoice, that one should have preference. Remove it and configure the system to not fill it (uncheck "Bank account required" in the payment method) for having the desired result.

@TelmoSuarez
Copy link
Copy Markdown

But the partner_bank_id in the invoice specifies the bank account to which the invoice will be paid. This means when using sepa direct debit, the partner_bank_id will be one from the company not the one from the customer.
IMO is confusing to show one or the order depending if the partner_bank_id is set.

@pedrobaeza
Copy link
Copy Markdown
Member

The idea is to overpass all of this with:

def _compute_partner_bank_id(self):
res = super()._compute_partner_bank_id()
for move in self:
payment_mode = move.payment_mode_id
if payment_mode:
if (
move.move_type in ["in_invoice", "in_receipt"]
and payment_mode.payment_type == "outbound"
and not payment_mode.payment_method_id.bank_account_required
):
move.partner_bank_id = False
continue
elif move.move_type in ["out_invoice", "out_receipt"]:
if payment_mode.payment_method_id.bank_account_required:
if (
payment_mode.bank_account_link == "fixed"
and payment_mode.fixed_journal_id.bank_account_id
):
move.partner_bank_id = (
payment_mode.fixed_journal_id.bank_account_id
)
continue
else:
move.partner_bank_id = False
else:
if not move.company_id.keep_partner_bank_without_payment_mode:
move.partner_bank_id = False
return res

and AFAIK, the domain is changed for customer invoices and payment mode.

Am I wrong?

@TelmoSuarez
Copy link
Copy Markdown

I understand that, but isn't it a bit weird to overpass it? Even if you uncheck "Bank account required" in the payment mode, the user may be able to set partner_bank_id and change the bank account returned by the function partner_banks_to_show which is then only used (AFAIK) in the invoice report.
I feel like makes more sense to just use the bank account from the mandate if the payment method is sepa_direct_debit. IMHO if there is the need to be able to print the bank account from the company in this situation it should be a more user-friendly way of doing it.

@pedrobaeza
Copy link
Copy Markdown
Member

OK, right, let's do one thing: please move that code to the account_banking_sepa_direct_debit module, where it should be hosted in first place, and let's move to that direction.

@ekainlarrea ekainlarrea force-pushed the 16.0.0-fix-account_payment_partner branch from 227a2b3 to 9f6f7f8 Compare March 3, 2026 16:55
Copy link
Copy Markdown

@marcos-mendez marcos-mendez left a comment

Choose a reason for hiding this comment

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

Automated Review -- Tests Failed

1. Root Cause of Test Failure

The test failure occurs because the unidecode Python library is missing from the environment. This dependency is required by the account_banking_pain_base module, which is a dependency of account_banking_sepa_direct_debit. The error prevents Odoo from loading the module and initializing the database.


2. Suggested Fix

Install the missing unidecode Python package in the test environment:

pip install unidecode

This should be done before running the tests to avoid the DistributionNotFound error.


3. Additional Code Issues

  • No issue identified in the provided diff. The code change in account_move.py correctly overrides the partner_banks_to_show method to handle SEPA direct debit logic, and the removal of duplicated logic in account_payment_partner is correct.
  • The new account_move.py in account_banking_sepa_direct_debit is a valid extension and follows OCA patterns.

4. Test Improvements

To improve test coverage for the new logic in account_banking_sepa_direct_debit, consider adding the following test cases in a TransactionCase or SavepointCase:

Suggested Test Cases:

  1. Test partner_banks_to_show with SEPA direct debit payment mode:

    • Create a move with payment_mode_id.payment_method_id.code == "sepa_direct_debit"
    • Ensure it returns mandate_id.partner_bank_id or partner_id.valid_mandate_id.partner_bank_id
    • Assert that super().partner_banks_to_show() is called for other payment methods.
  2. Test partner_banks_to_show with no mandate:

    • Create a move with SEPA direct debit but no valid mandate.
    • Ensure it gracefully falls back to super().partner_banks_to_show() or returns empty recordset.
  3. Test partner_banks_to_show with valid mandate:

    • Create a move with a valid mandate and ensure the correct bank is returned.

OCA Testing Pattern:

Use TransactionCase for tests that require database changes (e.g., creating mandates, payment modes, etc.). Tag tests appropriately using @tagged('post_install', 'manual') if they are not part of the automatic test suite.

Example:

from odoo.tests import TransactionCase
from odoo.tests.common import tagged

@tagged('post_install', 'manual')
class TestPartnerBanksToShow(TransactionCase):
    def test_partner_banks_to_show_sepa_direct_debit(self):
        # Test logic here
        pass

This ensures that the new logic is fully tested under realistic conditions.


Reciprocal Review Request

Hi everyone! I found some test failures on this PR and left detailed feedback above. I am happy to discuss or help debug. In the meantime, if any of you get a chance, I would appreciate a look at my open PR(s):

My open PRs across OCA:

Reviewing each other's work helps the whole community move forward. Thank you!


Environment via OCA Neural Reviewer: Minikube + K8s Job + oca-ci/py3.10-odoo16.0 | Odoo 16.0
Automated review by OCA Neural Reviewer + qwen3-coder:30b

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants