From dc8552f6ff048655dd13b5b6786121a8f1a00a27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 27 Mar 2019 00:39:52 +0100 Subject: [PATCH] Test debit and credit when closing period The warning should be raise only if there is credit on receivable and debit on payable. issue8208 review285071002 --- account.py | 10 +- ...scenario_account_tax_cash_period_close.rst | 116 ++++++++++++++++++ tests/test_account_tax_cash.py | 5 + 3 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 tests/scenario_account_tax_cash_period_close.rst diff --git a/account.py b/account.py index 195c6ccca7..bb49fd3a48 100644 --- a/account.py +++ b/account.py @@ -60,9 +60,13 @@ class Period(metaclass=PoolMeta): ('move.period', '=', period.id), ('reconciliation', '=', None), ('invoice_payment', '=', None), - ['OR', - ('account.type.receivable', '=', True), - ('account.type.payable', '=', True), + ['OR', [ + ('account.type.receivable', '=', True), + ('credit', '>', 0), + ], [ + ('account.type.payable', '=', True), + ('debit', '<', 0), + ], ], ]) if move_lines: diff --git a/tests/scenario_account_tax_cash_period_close.rst b/tests/scenario_account_tax_cash_period_close.rst new file mode 100644 index 0000000000..e787eaa87a --- /dev/null +++ b/tests/scenario_account_tax_cash_period_close.rst @@ -0,0 +1,116 @@ +=============================== +Account Tax Cash Closing Period +=============================== + +Imports:: + + >>> from decimal import Decimal + >>> from proteus import Model, Wizard + >>> from trytond.tests.tools import activate_modules + >>> from trytond.modules.company.tests.tools import create_company, \ + ... get_company + >>> from trytond.modules.account.tests.tools import create_fiscalyear, \ + ... create_chart, get_accounts, create_tax, create_tax_code + >>> from trytond.modules.account_invoice.tests.tools import \ + ... set_fiscalyear_invoice_sequences + +Install account_tax_cash:: + + >>> config = activate_modules('account_tax_cash') + +Create company:: + + >>> _ = create_company() + >>> company = get_company() + +Create fiscal year:: + + >>> fiscalyear = set_fiscalyear_invoice_sequences( + ... create_fiscalyear(company)) + >>> fiscalyear.click('create_period') + >>> period = fiscalyear.periods[0] + +Create chart of accounts:: + + >>> _ = create_chart(company) + >>> accounts = get_accounts(company) + >>> receivable = accounts['receivable'] + >>> revenue = accounts['revenue'] + >>> expense = accounts['expense'] + >>> account_cash = accounts['cash'] + +Set tax cash basis:: + + >>> Tax = Model.get('account.tax') + >>> TaxGroup = Model.get('account.tax.group') + >>> TaxCode = Model.get('account.tax.code') + + >>> group_cash_basis = TaxGroup(name="Cash Basis", code="CASH") + >>> group_cash_basis.save() + + >>> fiscalyear.tax_group_on_cash_basis.append(TaxGroup(group_cash_basis.id)) + >>> fiscalyear.save() + +Create party:: + + >>> Party = Model.get('party.party') + >>> party = Party(name='Party') + >>> party.save() + +Create revenue:: + + >>> Move = Model.get('account.move') + >>> Journal = Model.get('account.journal') + >>> journal_revenue, = Journal.find([('type', '=', 'revenue')]) + >>> move = Move() + >>> move.period = period + >>> move.date = period.start_date + >>> move.journal = journal_revenue + >>> line = move.lines.new() + >>> line.account = revenue + >>> line.credit = Decimal('10') + >>> line = move.lines.new() + >>> line.account = receivable + >>> line.party = party + >>> line.debit = Decimal('10') + >>> move.click('post') + +Can close the period:: + + >>> period.click('close') + >>> period.click('reopen') + +Receive cash:: + + >>> journal_cash, = Journal.find([('type', '=', 'cash')]) + >>> move = Move() + >>> move.period = period + >>> move.data = period.start_date + >>> move.journal = journal_cash + >>> line = move.lines.new() + >>> line.account = account_cash + >>> line.debit = Decimal('10') + >>> line = move.lines.new() + >>> line.account = receivable + >>> line.party = party + >>> line.credit = Decimal('10') + >>> move.click('post') + +Can not close the period:: + + >>> period.click('close') # doctest: +IGNORE_EXCEPTION_DETAIL + Traceback (most recent call last): + ... + ClosePeriodWarning: ... + +Reconcile lines:: + + >>> Line = Model.get('account.move.line') + >>> lines = Line.find([('account', '=', receivable.id)]) + >>> reconcile_lines = Wizard('account.move.reconcile_lines', lines) + >>> reconcile_lines.state == 'end' + True + +Can close the period:: + + >>> period.click('close') diff --git a/tests/test_account_tax_cash.py b/tests/test_account_tax_cash.py index bcda91ebfa..900074f275 100644 --- a/tests/test_account_tax_cash.py +++ b/tests/test_account_tax_cash.py @@ -35,4 +35,9 @@ def suite(): tearDown=doctest_teardown, encoding='utf-8', checker=doctest_checker, optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) + suite.addTests(doctest.DocFileSuite( + 'scenario_account_tax_cash_period_close.rst', + tearDown=doctest_teardown, encoding='utf-8', + checker=doctest_checker, + optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) return suite