Files
tryton/modules/account/tests/scenario_account_reconciliation.rst
T

198 lines
6.2 KiB
ReStructuredText
Raw Normal View History

2013-01-26 15:12:02 +01:00
===============================
Account Reconciliation Scenario
===============================
Imports::
>>> from decimal import Decimal
2024-01-14 19:21:56 +01:00
2016-08-26 09:57:45 +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
>>> from trytond.tests.tools import activate_modules, assertEqual, assertTrue
2013-01-26 15:12:02 +01:00
Activate modules::
2013-01-26 15:12:02 +01:00
>>> config = activate_modules('account')
2013-01-26 15:12:02 +01:00
>>> GLLine = Model.get('account.general_ledger.line')
2013-01-26 15:12:02 +01:00
Create company::
>>> _ = create_company()
>>> company = get_company()
2013-01-26 15:12:02 +01:00
Create fiscal year::
>>> fiscalyear = create_fiscalyear(company)
>>> fiscalyear.click('create_period')
2013-01-26 15:12:02 +01:00
>>> period = fiscalyear.periods[0]
Create chart of accounts::
>>> _ = create_chart(company)
>>> accounts = get_accounts(company)
>>> receivable = accounts['receivable']
>>> revenue = accounts['revenue']
>>> expense = accounts['expense']
>>> cash = accounts['cash']
2013-01-26 15:12:02 +01:00
Create parties::
>>> Party = Model.get('party.party')
>>> customer = Party(name='Customer')
>>> customer.save()
Create Moves for direct reconciliation::
>>> Journal = Model.get('account.journal')
>>> Move = Model.get('account.move')
>>> journal_revenue, = Journal.find([
... ('code', '=', 'REV'),
... ])
>>> journal_cash, = Journal.find([
... ('code', '=', 'CASH'),
... ])
>>> move = Move()
>>> move.period = period
>>> move.journal = journal_revenue
>>> move.date = period.start_date
>>> line = move.lines.new()
>>> line.account = revenue
>>> line.credit = Decimal(42)
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.debit = Decimal(42)
>>> line.party = customer
>>> move.save()
>>> reconcile1, = [l for l in move.lines if l.account == receivable]
>>> move = Move()
>>> move.period = period
>>> move.journal = journal_cash
>>> move.date = period.start_date
>>> line = move.lines.new()
>>> line.account = cash
>>> line.debit = Decimal(42)
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.credit = Decimal(42)
>>> line.party = customer
>>> move.save()
>>> reconcile2, = [l for l in move.lines if l.account == receivable]
Reconcile Lines without writeoff::
>>> reconcile_lines = Wizard('account.move.reconcile_lines',
... [reconcile1, reconcile2])
>>> reconcile_lines.state
'end'
2013-01-26 15:12:02 +01:00
>>> reconcile1.reload()
>>> reconcile2.reload()
2023-12-29 19:02:08 +01:00
>>> assertEqual(reconcile1.reconciliation, reconcile2.reconciliation)
>>> assertTrue(reconcile1.reconciliation)
2013-01-26 15:12:02 +01:00
>>> len(reconcile1.reconciliation.lines)
2
Unreconcile lines::
>>> unreconcile_lines = Wizard(
... 'account.move.unreconcile_lines', [reconcile1])
>>> unreconcile_lines.state
'end'
>>> reconcile1.reload()
>>> reconcile1.reconciliation
>>> reconcile2.reload()
>>> reconcile2.reconciliation
Reconcile general ledger lines::
>>> gl_reconcile1 = GLLine(reconcile1.id)
>>> gl_reconcile2 = GLLine(reconcile2.id)
>>> reconcile_lines = Wizard('account.move.reconcile_lines',
... [gl_reconcile1, gl_reconcile2])
>>> reconcile_lines.state
'end'
>>> gl_reconcile1.reload()
>>> gl_reconcile2.reload()
2023-12-29 19:02:08 +01:00
>>> assertEqual(gl_reconcile1.reconciliation, gl_reconcile2.reconciliation)
>>> assertTrue(gl_reconcile1.reconciliation)
Unreconcile general ledger, lines::
>>> unreconcile_lines = Wizard(
... 'account.move.unreconcile_lines', [gl_reconcile1])
>>> unreconcile_lines.state
'end'
>>> gl_reconcile1.reload()
>>> gl_reconcile1.reconciliation
>>> gl_reconcile2.reload()
>>> gl_reconcile2.reconciliation
2013-01-26 15:12:02 +01:00
Create Moves for writeoff reconciliation::
>>> move = Move()
>>> move.period = period
>>> move.journal = journal_revenue
>>> move.date = period.start_date
>>> line = move.lines.new()
>>> line.account = revenue
>>> line.credit = Decimal(68)
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.debit = Decimal(68)
>>> line.party = customer
>>> move.save()
>>> reconcile1, = [l for l in move.lines if l.account == receivable]
>>> move = Move()
>>> move.period = period
>>> move.journal = journal_cash
>>> move.date = period.start_date
>>> line = move.lines.new()
>>> line.account = cash
>>> line.debit = Decimal(65)
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.credit = Decimal(65)
>>> line.party = customer
>>> move.save()
>>> reconcile2, = [l for l in move.lines if l.account == receivable]
2021-03-11 23:00:09 +01:00
Create a write-off payment method::
2018-09-01 11:20:13 +02:00
>>> Sequence = Model.get('ir.sequence')
2021-03-11 23:00:09 +01:00
>>> sequence_journal, = Sequence.find(
... [('sequence_type.name', '=', "Account Journal")], limit=1)
2013-12-22 00:27:56 +01:00
>>> journal_writeoff = Journal(name='Write-Off', type='write-off',
2018-09-01 11:20:13 +02:00
... sequence=sequence_journal)
2013-12-22 00:27:56 +01:00
>>> journal_writeoff.save()
2018-09-01 11:20:13 +02:00
>>> WriteOff = Model.get('account.move.reconcile.write_off')
>>> writeoff_method = WriteOff()
>>> writeoff_method.name = 'Write Off'
>>> writeoff_method.journal = journal_writeoff
>>> writeoff_method.debit_account = expense
>>> writeoff_method.credit_account = expense
>>> writeoff_method.save()
2021-03-11 23:00:09 +01:00
Reconcile Lines with write-off::
2023-03-13 23:52:02 +01:00
2013-01-26 15:12:02 +01:00
>>> reconcile_lines = Wizard('account.move.reconcile_lines',
... [reconcile1, reconcile2])
>>> reconcile_lines.form_state
'writeoff'
2018-09-01 11:20:13 +02:00
>>> reconcile_lines.form.writeoff = writeoff_method
2013-01-26 15:12:02 +01:00
>>> reconcile_lines.execute('reconcile')
>>> reconcile1.reload()
>>> reconcile2.reload()
2023-12-29 19:02:08 +01:00
>>> assertEqual(reconcile1.reconciliation, reconcile2.reconciliation)
>>> assertTrue(reconcile1.reconciliation)
2013-01-26 15:12:02 +01:00
>>> len(reconcile1.reconciliation.lines)
3
>>> writeoff_line1, = [l for l in reconcile1.reconciliation.lines
... if l.credit == Decimal(3)]
>>> writeoff_line2, = [l for l in writeoff_line1.move.lines
... if l != writeoff_line1]
2023-12-29 19:02:08 +01:00
>>> assertEqual(writeoff_line2.account, expense)
2014-01-31 00:02:55 +01:00
>>> writeoff_line2.debit
Decimal('3.0')