first commit
This commit is contained in:
2
modules/account_payment/tests/__init__.py
Normal file
2
modules/account_payment/tests/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
192
modules/account_payment/tests/scenario_account_payment.rst
Normal file
192
modules/account_payment/tests/scenario_account_payment.rst
Normal file
@@ -0,0 +1,192 @@
|
||||
================
|
||||
Payment Scenario
|
||||
================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> 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.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
>>> today = dt.date.today()
|
||||
>>> tomorrow = today + dt.timedelta(days=1)
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('account_payment', create_company, create_chart)
|
||||
|
||||
Set employee::
|
||||
|
||||
>>> User = Model.get('res.user')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> Employee = Model.get('company.employee')
|
||||
>>> employee_party = Party(name="Employee")
|
||||
>>> employee_party.save()
|
||||
>>> employee = Employee(party=employee_party)
|
||||
>>> employee.save()
|
||||
>>> user = User(config.user)
|
||||
>>> user.employees.append(employee)
|
||||
>>> user.employee = employee
|
||||
>>> user.save()
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = create_fiscalyear(today=(today, tomorrow))
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
>>> payable = accounts['payable']
|
||||
>>> expense = accounts['expense']
|
||||
|
||||
>>> Journal = Model.get('account.journal')
|
||||
>>> expense_journal, = Journal.find([('code', '=', 'EXP')])
|
||||
|
||||
Create payment journal::
|
||||
|
||||
>>> PaymentJournal = Model.get('account.payment.journal')
|
||||
>>> payment_journal = PaymentJournal(name='Manual',
|
||||
... process_method='manual')
|
||||
>>> payment_journal.save()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> customer = Party(name='Customer')
|
||||
>>> customer.save()
|
||||
>>> supplier = Party(name='Supplier')
|
||||
>>> supplier.save()
|
||||
|
||||
Create payable move::
|
||||
|
||||
>>> Move = Model.get('account.move')
|
||||
>>> move = Move()
|
||||
>>> move.journal = expense_journal
|
||||
>>> line = move.lines.new(
|
||||
... account=payable, party=supplier, maturity_date=tomorrow,
|
||||
... credit=Decimal('50.00'))
|
||||
>>> line = move.lines.new(account=expense, debit=Decimal('50.00'))
|
||||
>>> move.click('post')
|
||||
|
||||
Partially pay line::
|
||||
|
||||
>>> Payment = Model.get('account.payment')
|
||||
>>> line, = [l for l in move.lines if l.account == payable]
|
||||
>>> pay_line = Wizard('account.move.line.pay', [line])
|
||||
>>> pay_line.form.date = tomorrow
|
||||
>>> pay_line.execute('next_')
|
||||
>>> assertEqual(pay_line.form.journal, payment_journal)
|
||||
>>> pay_line.execute('next_')
|
||||
>>> payment, = Payment.find()
|
||||
>>> bool(payment.number)
|
||||
True
|
||||
>>> assertEqual(payment.date, tomorrow)
|
||||
>>> assertEqual(payment.party, supplier)
|
||||
>>> payment.amount
|
||||
Decimal('50.00')
|
||||
>>> payment.amount = Decimal('20.00')
|
||||
>>> payment.reference_type = 'creditor_reference'
|
||||
>>> payment.reference = 'RF18539007547034'
|
||||
>>> payment.reference
|
||||
'RF18 5390 0754 7034'
|
||||
>>> payment.click('submit')
|
||||
>>> assertEqual(payment.submitted_by, employee)
|
||||
>>> payment.click('approve')
|
||||
>>> assertEqual(payment.approved_by, employee)
|
||||
>>> payment.state
|
||||
'approved'
|
||||
>>> process_payment = payment.click('process_wizard')
|
||||
>>> group, = process_payment.actions[0]
|
||||
>>> assertEqual(group.payments, [payment])
|
||||
>>> payment.state
|
||||
'processing'
|
||||
>>> line.reload()
|
||||
>>> line.payment_amount
|
||||
Decimal('30.00')
|
||||
|
||||
Check the properties of the payment group::
|
||||
|
||||
>>> group = payment.group
|
||||
>>> group.payment_count
|
||||
1
|
||||
>>> group.payment_amount
|
||||
Decimal('20.00')
|
||||
>>> group.payment_amount_succeeded
|
||||
>>> group.payment_complete
|
||||
False
|
||||
|
||||
Success the payment and recheck the payment group::
|
||||
|
||||
>>> group.click('succeed')
|
||||
>>> payment.reload()
|
||||
>>> assertEqual(payment.succeeded_by, employee)
|
||||
>>> payment.state
|
||||
'succeeded'
|
||||
>>> group.reload()
|
||||
>>> group.payment_amount_succeeded
|
||||
Decimal('20.00')
|
||||
>>> group.payment_complete
|
||||
True
|
||||
|
||||
Search for the completed payment::
|
||||
|
||||
>>> PaymentGroup = Model.get('account.payment.group')
|
||||
>>> group, = PaymentGroup.find([('payment_complete', '=', 'True')])
|
||||
>>> group.payment_complete
|
||||
True
|
||||
>>> assertEqual(group, payment.group)
|
||||
|
||||
Partially fail to pay the remaining::
|
||||
|
||||
>>> pay_line = Wizard('account.move.line.pay', [line])
|
||||
>>> pay_line.execute('next_')
|
||||
>>> pay_line.execute('next_')
|
||||
>>> payment, = Payment.find([('state', '=', 'draft')])
|
||||
>>> payment.amount
|
||||
Decimal('30.00')
|
||||
>>> payment.click('submit')
|
||||
>>> payment.click('approve')
|
||||
>>> process_payment = payment.click('process_wizard')
|
||||
>>> line.reload()
|
||||
>>> line.payment_amount
|
||||
Decimal('0.00')
|
||||
>>> payment.reload()
|
||||
>>> payment.click('fail')
|
||||
>>> assertEqual(payment.failed_by, employee)
|
||||
>>> payment.state
|
||||
'failed'
|
||||
>>> payment.group.payment_complete
|
||||
True
|
||||
>>> payment.group.payment_amount_succeeded
|
||||
>>> line.reload()
|
||||
>>> line.payment_amount
|
||||
Decimal('30.00')
|
||||
|
||||
Pay line and block it after::
|
||||
|
||||
>>> move, = move.duplicate()
|
||||
>>> move.click('post')
|
||||
>>> line, = [l for l in move.lines if l.account == payable]
|
||||
>>> pay_line = Wizard('account.move.line.pay', [line])
|
||||
>>> pay_line.execute('next_')
|
||||
>>> pay_line.execute('next_')
|
||||
>>> len(line.payments)
|
||||
1
|
||||
|
||||
>>> line.click('payment_block')
|
||||
>>> len(line.payments)
|
||||
0
|
||||
|
||||
Try to pay blocked line::
|
||||
|
||||
>>> pay_line = Wizard('account.move.line.pay', [line])
|
||||
>>> pay_line.execute('next_')
|
||||
>>> pay_line.execute('next_')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
BlockedWarning: ...
|
||||
@@ -0,0 +1,81 @@
|
||||
=====================================
|
||||
Payment Blocked Direct Debit Scenario
|
||||
=====================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> 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.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
|
||||
>>> today = dt.date.today()
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('account_payment', create_company, create_chart)
|
||||
|
||||
>>> Journal = Model.get('account.journal')
|
||||
>>> Line = Model.get('account.move.line')
|
||||
>>> Move = Model.get('account.move')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> Payment = Model.get('account.payment')
|
||||
>>> PaymentJournal = Model.get('account.payment.journal')
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = create_fiscalyear()
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
>>> revnue_journal, = Journal.find([('code', '=', 'REV')])
|
||||
|
||||
Create payment journal::
|
||||
|
||||
>>> payment_journal = PaymentJournal(
|
||||
... name="Manual", process_method='manual')
|
||||
>>> payment_journal.save()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> customer = Party(name="Customer")
|
||||
>>> _ = customer.reception_direct_debits.new(journal=payment_journal)
|
||||
>>> customer.save()
|
||||
|
||||
Create receivable moves::
|
||||
|
||||
>>> move = Move()
|
||||
>>> move.journal = revnue_journal
|
||||
>>> line = move.lines.new(
|
||||
... account=accounts['receivable'], party=customer,
|
||||
... debit=Decimal('100.00'), maturity_date=today)
|
||||
>>> line = move.lines.new(
|
||||
... account=accounts['revenue'],
|
||||
... credit=Decimal('100.00'))
|
||||
>>> move.click('post')
|
||||
|
||||
Direct debit is not created when payment blocked::
|
||||
|
||||
>>> line, = Line.find([('party', '=', customer.id)])
|
||||
>>> line.click('payment_block')
|
||||
>>> create_direct_debit = Wizard('account.move.line.create_direct_debit')
|
||||
>>> create_direct_debit.form.date = today
|
||||
>>> create_direct_debit.execute('create_')
|
||||
>>> len(Payment.find([]))
|
||||
0
|
||||
|
||||
Direct debit is created when payment is unblocked::
|
||||
|
||||
>>> line.click('payment_unblock')
|
||||
>>> create_direct_debit = Wizard('account.move.line.create_direct_debit')
|
||||
>>> create_direct_debit.form.date = today
|
||||
>>> create_direct_debit.execute('create_')
|
||||
>>> len(Payment.find([]))
|
||||
1
|
||||
@@ -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')
|
||||
@@ -0,0 +1,97 @@
|
||||
=============================
|
||||
Payment Direct Debit Scenario
|
||||
=============================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> 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.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual, assertIsNotNone
|
||||
|
||||
>>> today = dt.date.today()
|
||||
>>> tomorrow = today + dt.timedelta(days=1)
|
||||
>>> after_tomorrow = tomorrow + dt.timedelta(days=1)
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('account_payment', create_company, create_chart)
|
||||
|
||||
>>> Journal = Model.get('account.journal')
|
||||
>>> Move = Model.get('account.move')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> Payment = Model.get('account.payment')
|
||||
>>> PaymentJournal = Model.get('account.payment.journal')
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = create_fiscalyear(today=(today, after_tomorrow))
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
>>> revnue_journal, = Journal.find([('code', '=', 'REV')])
|
||||
|
||||
Create payment journal::
|
||||
|
||||
>>> payment_journal = PaymentJournal(
|
||||
... name="Manual", process_method='manual')
|
||||
>>> payment_journal.save()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> customer1 = Party(name="Customer 1")
|
||||
>>> _ = customer1.reception_direct_debits.new(journal=payment_journal)
|
||||
>>> customer1.save()
|
||||
>>> customer2 = Party(name="Customer 2")
|
||||
>>> customer2.save()
|
||||
|
||||
Create receivable moves::
|
||||
|
||||
>>> move = Move()
|
||||
>>> move.journal = revnue_journal
|
||||
>>> line = move.lines.new(
|
||||
... account=accounts['receivable'], party=customer1,
|
||||
... debit=Decimal('100.00'), maturity_date=tomorrow)
|
||||
>>> line = move.lines.new(
|
||||
... account=accounts['revenue'],
|
||||
... credit=Decimal('100.00'))
|
||||
>>> move.click('post')
|
||||
|
||||
>>> move = Move()
|
||||
>>> move.journal = revnue_journal
|
||||
>>> line = move.lines.new(
|
||||
... account=accounts['receivable'], party=customer2,
|
||||
... debit=Decimal('200.00'), maturity_date=tomorrow)
|
||||
>>> line = move.lines.new(
|
||||
... account=accounts['revenue'],
|
||||
... credit=Decimal('200.00'))
|
||||
>>> move.click('post')
|
||||
|
||||
Create direct debit::
|
||||
|
||||
>>> create_direct_debit = Wizard('account.move.line.create_direct_debit')
|
||||
>>> create_direct_debit.form.date = after_tomorrow
|
||||
>>> create_direct_debit.execute('create_')
|
||||
|
||||
>>> payment, = Payment.find([])
|
||||
>>> payment.amount
|
||||
Decimal('100.00')
|
||||
>>> assertEqual(payment.party, customer1)
|
||||
>>> assertEqual(payment.date, tomorrow)
|
||||
>>> assertEqual(payment.journal, payment_journal)
|
||||
>>> assertIsNotNone(payment.line)
|
||||
|
||||
Re-run create direct debit does nothing::
|
||||
|
||||
>>> create_direct_debit = Wizard('account.move.line.create_direct_debit')
|
||||
>>> create_direct_debit.form.date = after_tomorrow
|
||||
>>> create_direct_debit.execute('create_')
|
||||
|
||||
>>> assertEqual(Payment.find([]), [payment])
|
||||
@@ -0,0 +1,92 @@
|
||||
=============================================
|
||||
Account Payment Direct Debit Balance Scenario
|
||||
=============================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> 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.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual, assertIsNone
|
||||
|
||||
>>> today = dt.date.today()
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('account_payment', create_company, create_chart)
|
||||
|
||||
>>> Journal = Model.get('account.journal')
|
||||
>>> Move = Model.get('account.move')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> Payment = Model.get('account.payment')
|
||||
>>> PaymentJournal = Model.get('account.payment.journal')
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = create_fiscalyear()
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
>>> revnue_journal, = Journal.find([('code', '=', 'REV')])
|
||||
|
||||
Create payment journal::
|
||||
|
||||
>>> payment_journal = PaymentJournal(
|
||||
... name="Manual", process_method='manual')
|
||||
>>> payment_journal.save()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> customer = Party(name="Customer")
|
||||
>>> _ = customer.reception_direct_debits.new(
|
||||
... journal=payment_journal, type='balance')
|
||||
>>> customer.save()
|
||||
|
||||
Create receivable moves::
|
||||
|
||||
>>> move = Move()
|
||||
>>> move.journal = revnue_journal
|
||||
>>> line = move.lines.new(
|
||||
... account=accounts['receivable'], party=customer,
|
||||
... debit=Decimal('100.00'), maturity_date=today)
|
||||
>>> line = move.lines.new(
|
||||
... account=accounts['revenue'],
|
||||
... credit=Decimal('100.00'))
|
||||
>>> move.click('post')
|
||||
|
||||
Create direct debit::
|
||||
|
||||
>>> create_direct_debit = Wizard('account.move.line.create_direct_debit')
|
||||
>>> create_direct_debit.execute('create_')
|
||||
|
||||
>>> payment, = Payment.find([])
|
||||
>>> payment.amount
|
||||
Decimal('100.00')
|
||||
>>> assertEqual(payment.party, customer)
|
||||
>>> assertEqual(payment.journal, payment_journal)
|
||||
>>> assertIsNone(payment.line)
|
||||
>>> payment.amount = Decimal('25.00')
|
||||
>>> payment.save()
|
||||
|
||||
Re-run create a second direct debit::
|
||||
|
||||
>>> create_direct_debit = Wizard('account.move.line.create_direct_debit')
|
||||
>>> create_direct_debit.execute('create_')
|
||||
|
||||
>>> payment2, = Payment.find([('id', '!=', payment.id)])
|
||||
>>> payment2.amount
|
||||
Decimal('75.00')
|
||||
|
||||
Re-run create direct debit does nothing::
|
||||
|
||||
>>> create_direct_debit = Wizard('account.move.line.create_direct_debit')
|
||||
>>> create_direct_debit.execute('create_')
|
||||
|
||||
>>> assertEqual(Payment.find([]), [payment, payment2])
|
||||
@@ -0,0 +1,128 @@
|
||||
================================
|
||||
Account Payment Dunning Scenario
|
||||
================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> 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.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
>>> today = dt.date.today()
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(
|
||||
... ['account_payment', 'account_dunning'], create_company, create_chart)
|
||||
|
||||
>>> Dunning = Model.get('account.dunning')
|
||||
>>> Journal = Model.get('account.journal')
|
||||
>>> Move = Model.get('account.move')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> PaymentJournal = Model.get('account.payment.journal')
|
||||
>>> Procedure = Model.get('account.dunning.procedure')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
>>> expense_journal, = Journal.find([('code', '=', 'EXP')])
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = create_fiscalyear(today=today)
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Create dunning procedure::
|
||||
|
||||
>>> procedure = Procedure(name='Procedure')
|
||||
>>> level = procedure.levels.new(overdue=dt.timedelta(0))
|
||||
>>> procedure.save()
|
||||
|
||||
Create payment journal::
|
||||
|
||||
>>> payment_journal = PaymentJournal(
|
||||
... name='Manual',
|
||||
... process_method='manual')
|
||||
>>> payment_journal.save()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> customer = Party(name='Customer')
|
||||
>>> customer.dunning_procedure = procedure
|
||||
>>> customer.save()
|
||||
|
||||
Create payable move::
|
||||
|
||||
>>> move = Move()
|
||||
>>> move.journal = expense_journal
|
||||
>>> line = move.lines.new()
|
||||
>>> line.party = customer
|
||||
>>> line.account = accounts['receivable']
|
||||
>>> line.debit = Decimal('50.00')
|
||||
>>> line.maturity_date = today
|
||||
>>> line = move.lines.new()
|
||||
>>> line.account = accounts['revenue']
|
||||
>>> line.credit = Decimal('50.00')
|
||||
>>> move.click('post')
|
||||
|
||||
Make a payment::
|
||||
|
||||
>>> line, = [l for l in move.lines if l.account == accounts['receivable']]
|
||||
>>> line.payment_amount
|
||||
Decimal('50.00')
|
||||
>>> pay_line = Wizard('account.move.line.pay', [line])
|
||||
>>> pay_line.execute('next_')
|
||||
>>> pay_line.execute('next_')
|
||||
>>> payment, = line.payments
|
||||
>>> line.payment_amount
|
||||
Decimal('0.00')
|
||||
|
||||
Create no dunning::
|
||||
|
||||
>>> create_dunning = Wizard('account.dunning.create')
|
||||
>>> create_dunning.execute('create_')
|
||||
>>> Dunning.find([])
|
||||
[]
|
||||
|
||||
Fail the payment::
|
||||
|
||||
>>> payment.click('submit')
|
||||
>>> process_payment = payment.click('process_wizard')
|
||||
>>> group, = process_payment.actions[0]
|
||||
>>> assertEqual(group.payments, [payment])
|
||||
>>> payment.click('fail')
|
||||
>>> payment.state
|
||||
'failed'
|
||||
>>> line.reload()
|
||||
>>> line.payment_amount
|
||||
Decimal('50.00')
|
||||
|
||||
Create dunning::
|
||||
|
||||
>>> create_dunning = Wizard('account.dunning.create')
|
||||
>>> create_dunning.execute('create_')
|
||||
>>> dunning, = Dunning.find([])
|
||||
>>> assertEqual(dunning.line, line)
|
||||
|
||||
Recreate a payment::
|
||||
|
||||
>>> pay_line = Wizard('account.move.line.pay', [line])
|
||||
>>> pay_line.execute('next_')
|
||||
>>> pay_line.execute('next_')
|
||||
>>> _, payment = line.payments
|
||||
>>> payment.state
|
||||
'draft'
|
||||
|
||||
Dunning is inactive::
|
||||
|
||||
>>> dunning.reload()
|
||||
>>> dunning.active
|
||||
False
|
||||
>>> Dunning.find([])
|
||||
[]
|
||||
@@ -0,0 +1,155 @@
|
||||
========================
|
||||
Invoice 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)
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(create_fiscalyear())
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
>>> payable = accounts['payable']
|
||||
>>> receivable = accounts['receivable']
|
||||
>>> revenue = accounts['revenue']
|
||||
|
||||
>>> Journal = Model.get('account.journal')
|
||||
>>> expense, = Journal.find([('code', '=', 'EXP')])
|
||||
|
||||
Create payment journal::
|
||||
|
||||
>>> PaymentJournal = Model.get('account.payment.journal')
|
||||
>>> payment_journal = PaymentJournal(name='Manual',
|
||||
... process_method='manual')
|
||||
>>> payment_journal.save()
|
||||
|
||||
Create party::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> party = Party(name='Party')
|
||||
>>> party.save()
|
||||
|
||||
Create invoice::
|
||||
|
||||
>>> Invoice = Model.get('account.invoice')
|
||||
>>> invoice = Invoice()
|
||||
>>> invoice.party = party
|
||||
>>> line = invoice.lines.new()
|
||||
>>> line.description = 'Description'
|
||||
>>> line.account = revenue
|
||||
>>> 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
|
||||
>>> bool(line_to_pay.payment_direct_debit)
|
||||
False
|
||||
|
||||
Partially pay line::
|
||||
|
||||
>>> Payment = Model.get('account.payment')
|
||||
>>> pay_line = Wizard('account.move.line.pay', [line_to_pay])
|
||||
>>> pay_line.execute('next_')
|
||||
>>> pay_line.execute('next_')
|
||||
>>> payment, = Payment.find()
|
||||
>>> payment.amount = Decimal('20')
|
||||
>>> payment.click('submit')
|
||||
|
||||
Check amount to pay::
|
||||
|
||||
>>> invoice.reload()
|
||||
>>> invoice.amount_to_pay
|
||||
Decimal('80.00')
|
||||
|
||||
Process the payment::
|
||||
|
||||
>>> process_payment = payment.click('process_wizard')
|
||||
|
||||
Check amount to pay::
|
||||
|
||||
>>> invoice.reload()
|
||||
>>> invoice.amount_to_pay
|
||||
Decimal('80.00')
|
||||
|
||||
Fail the payment::
|
||||
|
||||
>>> payment.click('fail')
|
||||
|
||||
Check amount to pay::
|
||||
|
||||
>>> invoice.reload()
|
||||
>>> invoice.amount_to_pay
|
||||
Decimal('100.00')
|
||||
|
||||
Create multiple valid payments for one line::
|
||||
|
||||
>>> line_to_pay, = invoice.lines_to_pay
|
||||
>>> pay_line = Wizard('account.move.line.pay', [line_to_pay])
|
||||
>>> pay_line.execute('next_')
|
||||
>>> pay_line.execute('next_')
|
||||
>>> payment, = pay_line.actions[0]
|
||||
>>> payment.amount
|
||||
Decimal('100.00')
|
||||
>>> payment.amount = Decimal('30.00')
|
||||
>>> payment.save()
|
||||
>>> pay_line = Wizard('account.move.line.pay', [line_to_pay])
|
||||
>>> pay_line.execute('next_')
|
||||
>>> pay_line.execute('next_')
|
||||
>>> payment, = pay_line.actions[0]
|
||||
>>> payment.amount
|
||||
Decimal('70.00')
|
||||
>>> payment.amount = Decimal('30.00')
|
||||
>>> payment.save()
|
||||
>>> payments = Payment.find([('state', '=', 'draft')])
|
||||
>>> Payment.click(payments, 'submit')
|
||||
|
||||
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()
|
||||
>>> 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
|
||||
@@ -0,0 +1,79 @@
|
||||
=========================
|
||||
Payment Planning Scenario
|
||||
=========================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> 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.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
>>> today = dt.date.today()
|
||||
>>> tomorrow = today + dt.timedelta(days=1)
|
||||
>>> next_week = today + dt.timedelta(weeks=1)
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('account_payment', create_company, create_chart)
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = create_fiscalyear(today=(today, next_week))
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
>>> payable = accounts['payable']
|
||||
>>> expense = accounts['expense']
|
||||
|
||||
>>> Journal = Model.get('account.journal')
|
||||
>>> expense_journal, = Journal.find([('code', '=', 'EXP')])
|
||||
|
||||
Create payment journal::
|
||||
|
||||
>>> PaymentJournal = Model.get('account.payment.journal')
|
||||
>>> payment_journal = PaymentJournal(name='Manual',
|
||||
... process_method='manual')
|
||||
>>> payment_journal.save()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> supplier = Party(name='Supplier')
|
||||
>>> supplier.save()
|
||||
|
||||
Create payable move::
|
||||
|
||||
>>> Move = Model.get('account.move')
|
||||
>>> move = Move()
|
||||
>>> move.journal = expense_journal
|
||||
>>> line = move.lines.new(account=payable, party=supplier,
|
||||
... credit=Decimal('50.00'), maturity_date=next_week)
|
||||
>>> line = move.lines.new(account=expense, debit=Decimal('50.00'))
|
||||
>>> move.click('post')
|
||||
|
||||
Paying the line without date uses the maturity date::
|
||||
|
||||
>>> Payment = Model.get('account.payment')
|
||||
>>> line, = [l for l in move.lines if l.account == payable]
|
||||
>>> pay_line = Wizard('account.move.line.pay', [line])
|
||||
>>> pay_line.execute('next_')
|
||||
>>> pay_line.execute('next_')
|
||||
>>> payment, = Payment.find()
|
||||
>>> assertEqual(payment.date, next_week)
|
||||
|
||||
The date on the payment wizard is used for payment date::
|
||||
|
||||
>>> payment.delete()
|
||||
>>> pay_line = Wizard('account.move.line.pay', [line])
|
||||
>>> pay_line.form.date = tomorrow
|
||||
>>> pay_line.execute('next_')
|
||||
>>> pay_line.execute('next_')
|
||||
>>> payment, = Payment.find()
|
||||
>>> assertEqual(payment.date, tomorrow)
|
||||
@@ -0,0 +1,104 @@
|
||||
============================================
|
||||
Account Payment with Statement Rule 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
|
||||
|
||||
>>> today = dt.date.today()
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(
|
||||
... ['account_payment', 'account_statement', 'account_statement_rule'],
|
||||
... create_company, create_chart)
|
||||
|
||||
>>> AccountJournal = Model.get('account.journal')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> Payment = Model.get('account.payment')
|
||||
>>> PaymentJournal = Model.get('account.payment.journal')
|
||||
>>> Statement = Model.get('account.statement')
|
||||
>>> StatementJournal = Model.get('account.statement.journal')
|
||||
>>> StatementRule = Model.get('account.statement.rule')
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
||||
... create_fiscalyear())
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
Create journals::
|
||||
|
||||
>>> payment_journal = PaymentJournal(
|
||||
... name="Check", process_method='manual')
|
||||
>>> payment_journal.save()
|
||||
|
||||
>>> account_journal, = AccountJournal.find([('code', '=', 'STA')], limit=1)
|
||||
|
||||
>>> statement_journal = StatementJournal(
|
||||
... name="Statement",
|
||||
... journal=account_journal,
|
||||
... validation='amount',
|
||||
... account=accounts['cash'])
|
||||
>>> statement_journal.save()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> customer = Party(name="Customer")
|
||||
>>> customer.save()
|
||||
|
||||
Create statement rules for payment::
|
||||
|
||||
>>> statement_rule = StatementRule(name="Rule Payment")
|
||||
>>> statement_rule.description = r"Payment: *(?P<payment>.*)"
|
||||
>>> statement_line = statement_rule.lines.new()
|
||||
>>> statement_line.amount = "pending"
|
||||
>>> statement_rule.save()
|
||||
|
||||
Receive a payments::
|
||||
|
||||
>>> payment = Payment(kind='receivable')
|
||||
>>> payment.journal = payment_journal
|
||||
>>> payment.party = customer
|
||||
>>> payment.amount = Decimal('100.00')
|
||||
>>> payment.click('submit')
|
||||
>>> process_payment = payment.click('process_wizard')
|
||||
>>> payment.state
|
||||
'processing'
|
||||
|
||||
Create a statement with payment and group as origins::
|
||||
|
||||
>>> statement = Statement(
|
||||
... name="001",
|
||||
... journal=statement_journal,
|
||||
... total_amount=Decimal('100.00'))
|
||||
>>> origin = statement.origins.new()
|
||||
>>> origin.date = today
|
||||
>>> origin.amount = Decimal('100.00')
|
||||
>>> origin.description = "Payment: %s" % payment.rec_name
|
||||
>>> statement.click('apply_rules')
|
||||
>>> line, = statement.lines
|
||||
>>> assertEqual(line.related_to, payment)
|
||||
|
||||
Check payments are succeeded after validation::
|
||||
|
||||
>>> statement.click('validate_statement')
|
||||
>>> statement.state
|
||||
'validated'
|
||||
>>> payment.reload()
|
||||
>>> payment.state
|
||||
'succeeded'
|
||||
@@ -0,0 +1,139 @@
|
||||
=================================
|
||||
Account Payment Warnings Scenario
|
||||
=================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> 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.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
|
||||
>>> today = dt.date.today()
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('account_payment', create_company, create_chart)
|
||||
|
||||
>>> Journal = Model.get('account.journal')
|
||||
>>> Move = Model.get('account.move')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> Payment = Model.get('account.payment')
|
||||
>>> PaymentJournal = Model.get('account.payment.journal')
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = create_fiscalyear()
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
>>> expense_journal, = Journal.find([('code', '=', 'EXP')])
|
||||
>>> cash_journal, = Journal.find([('code', '=', 'CASH')])
|
||||
|
||||
Create payment journal::
|
||||
|
||||
>>> payment_journal = PaymentJournal(
|
||||
... name="Manual", process_method='manual')
|
||||
>>> payment_journal.save()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> supplier = Party(name="Supplier")
|
||||
>>> supplier.save()
|
||||
>>> supplier2 = Party(name="Supplier 2")
|
||||
>>> supplier2.save()
|
||||
|
||||
Create receivable moves::
|
||||
|
||||
>>> move = Move()
|
||||
>>> move.journal = expense_journal
|
||||
>>> line = move.lines.new(
|
||||
... account=accounts['payable'], party=supplier, maturity_date=today,
|
||||
... credit=Decimal('100.00'))
|
||||
>>> line = move.lines.new(
|
||||
... account=accounts['expense'],
|
||||
... debit=Decimal('100.00'))
|
||||
>>> move.click('post')
|
||||
>>> move.state
|
||||
'posted'
|
||||
>>> move2, = move.duplicate()
|
||||
>>> move2.click('post')
|
||||
|
||||
Pay line::
|
||||
|
||||
>>> line, = [l for l in move.lines if l.account == accounts['payable']]
|
||||
>>> pay_line = Wizard('account.move.line.pay', [line])
|
||||
>>> pay_line.form.date = today
|
||||
>>> pay_line.execute('next_')
|
||||
>>> pay_line.execute('next_')
|
||||
>>> payment, = Payment.find()
|
||||
|
||||
Try to cancel move::
|
||||
|
||||
>>> cancel_move = Wizard('account.move.cancel', [move])
|
||||
>>> cancel_move.execute('cancel')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
CancelWarning: ...
|
||||
|
||||
Try to group lines::
|
||||
|
||||
>>> line2, = [l for l in move2.lines if l.account == accounts['payable']]
|
||||
>>> group_line = Wizard('account.move.line.group', [line, line2])
|
||||
>>> group_line.execute('group')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
GroupLineWarning: ...
|
||||
|
||||
Try to reschedule line::
|
||||
|
||||
>>> reschedule_line = Wizard('account.move.line.reschedule', [line])
|
||||
>>> reschedule_line.form.start_date = today
|
||||
>>> reschedule_line.form.frequency = 'monthly'
|
||||
>>> reschedule_line.form.interval = 1
|
||||
>>> reschedule_line.form.amount = Decimal('50.00')
|
||||
>>> reschedule_line.execute('preview')
|
||||
>>> reschedule_line.execute('reschedule')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
RescheduleLineWarning: ...
|
||||
|
||||
Try to delegate line::
|
||||
|
||||
>>> delegate_line = Wizard('account.move.line.delegate', [line])
|
||||
>>> delegate_line.form.party = supplier2
|
||||
>>> delegate_line.execute('delegate')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
DelegateLineWarning: ...
|
||||
|
||||
Reconcile line and try to submit::
|
||||
|
||||
>>> move = Move()
|
||||
>>> move.journal = cash_journal
|
||||
>>> _ = move.lines.new(
|
||||
... account=accounts['payable'], party=supplier,
|
||||
... debit=Decimal('100.00'))
|
||||
>>> _ = move.lines.new(
|
||||
... account=accounts['cash'],
|
||||
... credit=Decimal('100.00'))
|
||||
>>> move.click('post')
|
||||
>>> move.state
|
||||
'posted'
|
||||
|
||||
>>> cash_line, = [l for l in move.lines if l.account == accounts['payable']]
|
||||
>>> reconcile = Wizard('account.move.reconcile_lines', [payment.line, cash_line])
|
||||
>>> reconcile.state
|
||||
'end'
|
||||
|
||||
>>> payment.click('submit')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ReconciledWarning: ...
|
||||
18
modules/account_payment/tests/test_module.py
Normal file
18
modules/account_payment/tests/test_module.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from trytond.modules.company.tests import (
|
||||
CompanyTestMixin, PartyCompanyCheckEraseMixin)
|
||||
from trytond.modules.party.tests import PartyCheckReplaceMixin
|
||||
from trytond.tests.test_tryton import ModuleTestCase
|
||||
|
||||
|
||||
class AccountPaymentTestCase(
|
||||
PartyCompanyCheckEraseMixin, PartyCheckReplaceMixin, CompanyTestMixin,
|
||||
ModuleTestCase):
|
||||
'Test Account Payment module'
|
||||
module = 'account_payment'
|
||||
extras = ['account_invoice', 'account_statement', 'account_statement_rule']
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
8
modules/account_payment/tests/test_scenario.py
Normal file
8
modules/account_payment/tests/test_scenario.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from trytond.tests.test_tryton import load_doc_tests
|
||||
|
||||
|
||||
def load_tests(*args, **kwargs):
|
||||
return load_doc_tests(__name__, __file__, *args, **kwargs)
|
||||
Reference in New Issue
Block a user