details: https://code.tryton.org/tryton/commit/f41d049a9845
branch: 7.8
user: Cédric Krier <[email protected]>
date: Sat Jan 10 19:40:21 2026 +0100
description:
Update sign of amount line paid according to invoice type and payment
kind
Closes #14070
(grafted from d87267b3346844e209a197c7c216f8f1641bd775)
diffstat:
modules/account_payment/account.py |
8 +-
modules/account_payment/tests/scenario_account_payment_credit_note_in.rst |
77 ++++++++++
2 files changed, 84 insertions(+), 1 deletions(-)
diffs (101 lines):
diff -r 5cd6ed36d4da -r f41d049a9845 modules/account_payment/account.py
--- a/modules/account_payment/account.py Sat Jan 10 18:53:51 2026 +0100
+++ b/modules/account_payment/account.py Sat Jan 10 19:40:21 2026 +0100
@@ -776,9 +776,15 @@
continue
payment_amount = Decimal(0)
for payment in line.payments:
+ amount_line_paid = payment.amount_line_paid
+ if ((invoice.type == 'in'
+ and payment.kind == 'receivable')
+ or (invoice.type == 'out'
+ and payment.kind == 'payable')):
+ amount_line_paid *= -1
with Transaction().set_context(date=payment.date):
payment_amount += Currency.compute(
- payment.currency, payment.amount_line_paid,
+ payment.currency, amount_line_paid,
invoice.currency)
amounts[invoice.id] -= payment_amount
return amounts
diff -r 5cd6ed36d4da -r f41d049a9845
modules/account_payment/tests/scenario_account_payment_credit_note_in.rst
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/account_payment/tests/scenario_account_payment_credit_note_in.rst
Sat Jan 10 19:40:21 2026 +0100
@@ -0,0 +1,77 @@
+=====================================
+Supplier Credit Note Payment Scenario
+=====================================
+
+Imports::
+
+ >>> from decimal import Decimal
+
+ >>> from proteus import Model, Wizard
+ >>> 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
+
+Activate modules::
+
+ >>> config = activate_modules(
+ ... ['account_payment', 'account_invoice'], create_company,
create_chart)
+
+ >>> Invoice = Model.get('account.invoice')
+ >>> Party = Model.get('party.party')
+ >>> Payment = Model.get('account.payment')
+ >>> PaymentJournal = Model.get('account.payment.journal')
+
+Create fiscal year::
+
+ >>> fiscalyear = set_fiscalyear_invoice_sequences(create_fiscalyear())
+ >>> fiscalyear.click('create_period')
+
+Get accounts::
+
+ >>> accounts = get_accounts()
+
+Create payment journal::
+
+ >>> payment_journal = PaymentJournal(name="Manual",
process_method='manual')
+ >>> payment_journal.save()
+
+Create party::
+
+ >>> party = Party(name="Supplier")
+ >>> party.save()
+
+Create invoice::
+
+ >>> invoice = Invoice(type='in')
+ >>> invoice.party = party
+ >>> invoice.invoice_date = fiscalyear.start_date
+ >>> line = invoice.lines.new()
+ >>> line.account = accounts['expense']
+ >>> line.quantity = -1
+ >>> line.unit_price = Decimal('100')
+ >>> invoice.click('post')
+ >>> invoice.state
+ 'posted'
+ >>> invoice.amount_to_pay
+ Decimal('-100.00')
+ >>> line_to_pay, = invoice.lines_to_pay
+
+Partially receive payment::
+
+ >>> pay_line = Wizard('account.move.line.pay', [line_to_pay])
+ >>> pay_line.execute('next_')
+ >>> pay_line.execute('next_')
+ >>> payment, = Payment.find()
+ >>> payment.kind
+ 'receivable'
+ >>> payment.amount = Decimal('20')
+ >>> payment.click('submit')
+
+Check amount to pay::
+
+ >>> invoice.reload()
+ >>> invoice.amount_to_pay
+ Decimal('-80.00')