From 78eba2ada3589f4e3cf682c0af78ebbf214c32c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Tarroja=20Caubet?= Date: Tue, 29 Sep 2026 11:27:32 +0200 Subject: [PATCH] Set supplier direct debit only on supplier invoice lines Closes #15058 --- modules/account_payment/account.py | 11 +++- .../scenario_account_payment_invoice.rst | 24 -------- ..._account_payment_invoice_direct_debit.json | 4 ++ ...o_account_payment_invoice_direct_debit.rst | 56 +++++++++++++++++++ 4 files changed, 69 insertions(+), 26 deletions(-) create mode 100644 modules/account_payment/tests/scenario_account_payment_invoice_direct_debit.json create mode 100644 modules/account_payment/tests/scenario_account_payment_invoice_direct_debit.rst diff --git a/modules/account_payment/account.py b/modules/account_payment/account.py index b5c5b42ccf..dcf9901d20 100644 --- a/modules/account_payment/account.py +++ b/modules/account_payment/account.py @@ -774,6 +774,11 @@ class Invoice(metaclass=PoolMeta): __name__ = 'account.invoice' payment_direct_debit = fields.Boolean("Direct Debit", + domain=[ + If(Eval('type') != 'in', + ('payment_direct_debit', '=', False), + ()), + ], states={ 'invisible': Eval('type') != 'in', 'readonly': Eval('state') != 'draft', @@ -784,11 +789,13 @@ class Invoice(metaclass=PoolMeta): def default_payment_direct_debit(cls): return False - @fields.depends('party') + @fields.depends('party', 'type') def on_change_party(self): super().on_change_party() - if self.party: + if self.type == 'in' and self.party: self.payment_direct_debit = self.party.payment_direct_debit + else: + self.payment_direct_debit = False def _get_move_line(self, date, amount): line = super()._get_move_line(date, amount) diff --git a/modules/account_payment/tests/scenario_account_payment_invoice.rst b/modules/account_payment/tests/scenario_account_payment_invoice.rst index d3a45b194a..659c94c883 100644 --- a/modules/account_payment/tests/scenario_account_payment_invoice.rst +++ b/modules/account_payment/tests/scenario_account_payment_invoice.rst @@ -129,27 +129,3 @@ Check amount to pay:: >>> invoice.reload() >>> invoice.amount_to_pay Decimal('40.00') - -Set party as direct debit:: - - >>> party.payment_direct_debit = True - >>> party.save() - -Create invoice:: - - >>> Invoice = Model.get('account.invoice') - >>> invoice = Invoice(type='out') - >>> invoice.party = party - >>> bool(invoice.payment_direct_debit) - True - >>> line = invoice.lines.new() - >>> line.description = 'Description' - >>> line.account = revenue - >>> line.quantity = 1 - >>> line.unit_price = Decimal('50') - >>> invoice.click('post') - >>> invoice.state - 'posted' - >>> line_to_pay, = invoice.lines_to_pay - >>> bool(line_to_pay.payment_direct_debit) - True diff --git a/modules/account_payment/tests/scenario_account_payment_invoice_direct_debit.json b/modules/account_payment/tests/scenario_account_payment_invoice_direct_debit.json new file mode 100644 index 0000000000..290cfdf8ed --- /dev/null +++ b/modules/account_payment/tests/scenario_account_payment_invoice_direct_debit.json @@ -0,0 +1,4 @@ +[ + {"payment_direct_debit": false} + ,{"payment_direct_debit": true} +] diff --git a/modules/account_payment/tests/scenario_account_payment_invoice_direct_debit.rst b/modules/account_payment/tests/scenario_account_payment_invoice_direct_debit.rst new file mode 100644 index 0000000000..adbf8dea81 --- /dev/null +++ b/modules/account_payment/tests/scenario_account_payment_invoice_direct_debit.rst @@ -0,0 +1,56 @@ +=========================================== +Account Payment Party Direct Debit Scenario +=========================================== + +Imports:: + + >>> import datetime as dt + >>> from decimal import Decimal + + >>> from proteus import Model + >>> from trytond.modules.account.tests.tools import ( + ... create_chart, create_fiscalyear, get_accounts) + >>> from trytond.modules.account_invoice.tests.tools import ( + ... set_fiscalyear_invoice_sequences) + >>> from trytond.modules.company.tests.tools import create_company + >>> from trytond.tests.tools import activate_modules, assertEqual + + >>> payment_direct_debit = globals().get('payment_direct_debit', False) + >>> today = dt.date.today() + +Activate modules:: + + >>> config = activate_modules( + ... ['account_payment', 'account_invoice'], create_company, create_chart) + + >>> Party = Model.get('party.party') + >>> Invoice = Model.get('account.invoice') + +Create fiscal year:: + + >>> fiscalyear = set_fiscalyear_invoice_sequences(create_fiscalyear()) + >>> fiscalyear.click('create_period') + +Get accounts:: + + >>> accounts = get_accounts() + +Create party:: + + >>> party = Party(name='Supplier') + >>> party.payment_direct_debit = payment_direct_debit + >>> party.save() + +Create supplier invoice:: + + >>> invoice = Invoice(type='in') + >>> invoice.party = party + >>> invoice.invoice_date = today + >>> assertEqual(invoice.payment_direct_debit, payment_direct_debit) + >>> line = invoice.lines.new() + >>> line.account = accounts['expense'] + >>> line.quantity = 1 + >>> line.unit_price = Decimal('50.0000') + >>> invoice.click('post') + >>> line_to_pay, = invoice.lines_to_pay + >>> assertEqual(line_to_pay.payment_direct_debit, payment_direct_debit)