details: https://code.tryton.org/tryton/commit/fd8f302b1650
branch: default
user: Adrià Tarroja Caubet <[email protected]>
date: Tue Sep 29 11:27:32 2026 +0200
description:
Set supplier direct debit only on supplier invoice lines
Closes #15058
diffstat:
modules/account_payment/account.py
| 11 +-
modules/account_payment/tests/scenario_account_payment_invoice.rst
| 24 ----
modules/account_payment/tests/scenario_account_payment_invoice_direct_debit.json
| 4 +
modules/account_payment/tests/scenario_account_payment_invoice_direct_debit.rst
| 56 ++++++++++
4 files changed, 69 insertions(+), 26 deletions(-)
diffs (130 lines):
diff -r a8d3b2e893cd -r fd8f302b1650 modules/account_payment/account.py
--- a/modules/account_payment/account.py Tue Sep 15 09:31:57 2026 +0200
+++ b/modules/account_payment/account.py Tue Sep 29 11:27:32 2026 +0200
@@ -774,6 +774,11 @@
__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 @@
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 -r a8d3b2e893cd -r fd8f302b1650
modules/account_payment/tests/scenario_account_payment_invoice.rst
--- a/modules/account_payment/tests/scenario_account_payment_invoice.rst
Tue Sep 15 09:31:57 2026 +0200
+++ b/modules/account_payment/tests/scenario_account_payment_invoice.rst
Tue Sep 29 11:27:32 2026 +0200
@@ -129,27 +129,3 @@
>>> 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 -r a8d3b2e893cd -r fd8f302b1650
modules/account_payment/tests/scenario_account_payment_invoice_direct_debit.json
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++
b/modules/account_payment/tests/scenario_account_payment_invoice_direct_debit.json
Tue Sep 29 11:27:32 2026 +0200
@@ -0,0 +1,4 @@
+[
+ {"payment_direct_debit": false}
+ ,{"payment_direct_debit": true}
+]
diff -r a8d3b2e893cd -r fd8f302b1650
modules/account_payment/tests/scenario_account_payment_invoice_direct_debit.rst
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++
b/modules/account_payment/tests/scenario_account_payment_invoice_direct_debit.rst
Tue Sep 29 11:27:32 2026 +0200
@@ -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)