Files
tryton/modules/account_payment/tests/scenario_account_payment.rst
T

193 lines
5.3 KiB
ReStructuredText
Raw Normal View History

2014-03-10 23:06:29 +01:00
================
Payment Scenario
================
Imports::
>>> import datetime as dt
2014-03-10 23:06:29 +01:00
>>> from decimal import Decimal
2024-01-14 19:21:56 +01:00
2016-08-26 09:58:22 +02:00
>>> from proteus import Model, Wizard
2024-01-14 19:21:56 +01:00
>>> from trytond.modules.account.tests.tools import (
... create_chart, create_fiscalyear, get_accounts)
>>> from trytond.modules.company.tests.tools import create_company, get_company
2023-12-29 19:02:08 +01:00
>>> from trytond.tests.tools import activate_modules, assertEqual
>>> today = dt.date.today()
>>> tomorrow = today + dt.timedelta(days=1)
2014-03-10 23:06:29 +01:00
Activate modules::
2014-03-10 23:06:29 +01:00
>>> config = activate_modules('account_payment')
2014-03-10 23:06:29 +01:00
Create company::
>>> _ = create_company()
>>> company = get_company()
2014-03-10 23:06:29 +01:00
2021-04-11 10:48:26 +02:00
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()
2014-03-10 23:06:29 +01:00
Create fiscal year::
>>> fiscalyear = create_fiscalyear(company, (today, tomorrow))
>>> fiscalyear.click('create_period')
2014-03-10 23:06:29 +01:00
Create chart of accounts::
>>> _ = create_chart(company)
>>> accounts = get_accounts(company)
>>> payable = accounts['payable']
>>> expense = accounts['expense']
2014-03-10 23:06:29 +01:00
>>> Journal = Model.get('account.journal')
>>> expense_journal, = Journal.find([('code', '=', 'EXP')])
2014-03-10 23:06:29 +01:00
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'))
2014-03-10 23:06:29 +01: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])
2019-01-17 17:19:24 +01:00
>>> pay_line.form.date = tomorrow
>>> pay_line.execute('next_')
2023-12-29 19:02:08 +01:00
>>> assertEqual(pay_line.form.journal, payment_journal)
2019-01-17 17:19:24 +01:00
>>> pay_line.execute('next_')
2014-03-10 23:06:29 +01:00
>>> payment, = Payment.find()
2023-12-29 19:02:08 +01:00
>>> assertEqual(payment.date, tomorrow)
>>> assertEqual(payment.party, supplier)
>>> payment.amount
Decimal('50.00')
>>> payment.amount = Decimal('20.00')
2022-04-11 20:41:56 +02:00
>>> payment.click('submit')
2023-12-29 19:02:08 +01:00
>>> assertEqual(payment.submitted_by, employee)
2014-03-10 23:06:29 +01:00
>>> payment.click('approve')
2023-12-29 19:02:08 +01:00
>>> assertEqual(payment.approved_by, employee)
2014-03-10 23:06:29 +01:00
>>> payment.state
2018-06-26 19:11:42 +02:00
'approved'
>>> process_payment = payment.click('process_wizard')
>>> group, = process_payment.actions[0]
2023-12-29 19:02:08 +01:00
>>> assertEqual(group.payments, [payment])
2014-03-10 23:06:29 +01:00
>>> payment.state
2018-06-26 19:11:42 +02:00
'processing'
2014-03-10 23:06:29 +01:00
>>> line.reload()
>>> line.payment_amount
Decimal('30.00')
2014-03-10 23:06:29 +01: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::
2021-10-11 18:22:19 +02:00
>>> group.click('succeed')
>>> payment.reload()
2023-12-29 19:02:08 +01:00
>>> 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
2023-12-29 19:02:08 +01:00
>>> assertEqual(group, payment.group)
2014-03-10 23:06:29 +01:00
Partially fail to pay the remaining::
>>> pay_line = Wizard('account.move.line.pay', [line])
2019-01-17 17:19:24 +01:00
>>> pay_line.execute('next_')
>>> pay_line.execute('next_')
2014-03-10 23:06:29 +01:00
>>> payment, = Payment.find([('state', '=', 'draft')])
>>> payment.amount
Decimal('30.00')
2022-04-11 20:41:56 +02:00
>>> payment.click('submit')
2014-03-10 23:06:29 +01:00
>>> payment.click('approve')
>>> process_payment = payment.click('process_wizard')
2014-03-10 23:06:29 +01:00
>>> line.reload()
>>> line.payment_amount
Decimal('0.00')
2014-03-10 23:06:29 +01:00
>>> payment.reload()
>>> payment.click('fail')
2023-12-29 19:02:08 +01:00
>>> assertEqual(payment.failed_by, employee)
2014-03-10 23:06:29 +01:00
>>> payment.state
2018-06-26 19:11:42 +02:00
'failed'
>>> payment.group.payment_complete
True
>>> payment.group.payment_amount_succeeded
2014-03-10 23:06:29 +01:00
>>> line.reload()
>>> line.payment_amount
Decimal('30.00')
2016-10-01 19:25:02 +02: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])
2019-01-17 17:19:24 +01:00
>>> pay_line.execute('next_')
>>> pay_line.execute('next_')
2016-10-01 19:25:02 +02:00
>>> 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])
2019-01-17 17:19:24 +01:00
>>> pay_line.execute('next_')
>>> pay_line.execute('next_')
2016-10-01 19:25:02 +02:00
Traceback (most recent call last):
...
2018-12-29 14:20:28 +01:00
BlockedWarning: ...