Update sign of amount line paid according to invoice type and payment kind
Closes #14070
This commit is contained in:
@@ -776,9 +776,15 @@ class Invoice(metaclass=PoolMeta):
|
||||
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
|
||||
|
||||
@@ -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')
|
||||
Reference in New Issue
Block a user