diff --git a/setup.py b/setup.py index 48fb65756c..4672e2c057 100644 --- a/setup.py +++ b/setup.py @@ -47,6 +47,12 @@ for dep in info.get('depends', []): requires.append(get_require_version('trytond_%s' % dep)) requires.append(get_require_version('trytond')) +tests_require = [get_require_version('proteus')] +dependency_links = [] +if minor_version % 2: + # Add development index for testing with proteus + dependency_links.append('https://trydevpi.tryton.org/') + setup(name=name, version=version, description='Tryton module for analytic accounting', @@ -63,7 +69,7 @@ setup(name=name, ], package_data={ 'trytond.modules.analytic_account': (info.get('xml', []) - + ['tryton.cfg', 'view/*.xml', 'locale/*.po']), + + ['tryton.cfg', 'view/*.xml', 'locale/*.po', 'tests/*.rst']), }, classifiers=[ 'Development Status :: 5 - Production/Stable', @@ -90,6 +96,7 @@ setup(name=name, ], license='GPL-3', install_requires=requires, + dependency_links=dependency_links, zip_safe=False, entry_points=""" [trytond.modules] @@ -97,4 +104,5 @@ setup(name=name, """, test_suite='tests', test_loader='trytond.test_loader:Loader', + tests_require=tests_require, ) diff --git a/tests/scenario_analytic_account.rst b/tests/scenario_analytic_account.rst new file mode 100644 index 0000000000..becdbc7f41 --- /dev/null +++ b/tests/scenario_analytic_account.rst @@ -0,0 +1,115 @@ +========================= +Analytic Account Scenario +========================= + +Imports:: + + >>> import datetime + >>> from dateutil.relativedelta import relativedelta + >>> from decimal import Decimal + >>> from proteus import config, Model, Wizard + >>> from trytond.modules.company.tests.tools import create_company, \ + ... get_company + >>> from trytond.modules.account.tests.tools import create_fiscalyear, \ + ... create_chart, get_accounts + >>> today = datetime.date.today() + +Create database:: + + >>> config = config.set_trytond() + >>> config.pool.test = True + +Install analytic_account:: + + >>> Module = Model.get('ir.module.module') + >>> analytic_account_module, = Module.find([ + ... ('name', '=', 'analytic_account'), + ... ]) + >>> analytic_account_module.click('install') + >>> Wizard('ir.module.module.install_upgrade').execute('upgrade') + +Create company:: + + >>> _ = create_company() + >>> company = get_company() + +Create fiscal year:: + + >>> fiscalyear = 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'] + +Create analytic accounts:: + + >>> AnalyticAccount = Model.get('analytic_account.account') + >>> root = AnalyticAccount(type='root', name='Root') + >>> root.save() + >>> analytic_account = AnalyticAccount(root=root, parent=root, + ... name='Analytic') + >>> analytic_account.save() + +Create parties:: + + >>> Party = Model.get('party.party') + >>> customer = Party(name='Customer') + >>> customer.save() + +Create Move analytic accounts:: + + >>> 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) + >>> analytic_line = line.analytic_lines.new() + >>> analytic_line.journal = journal_revenue + >>> analytic_line.name = 'Analytic Line' + >>> analytic_line.credit = line.credit + >>> analytic_line.account = analytic_account + >>> line = move.lines.new() + >>> line.account = receivable + >>> line.debit = Decimal(42) + >>> line.party = customer + >>> move.click('post') + >>> analytic_account.reload() + >>> analytic_account.credit + Decimal('42.00') + >>> analytic_account.debit + Decimal('0.00') + +Cancel Move:: + + >>> cancel_move = Wizard('account.move.cancel', [move]) + >>> cancel_move.form.description = 'Cancel' + >>> cancel_move.execute('cancel') + >>> move.reload() + >>> line, = [l for l in move.lines if l.account == receivable] + >>> bool(line.reconciliation) + True + >>> cancel_move, = [l.move for l in line.reconciliation.lines + ... if l.move != move] + >>> cancel_move.origin == move + True + >>> analytic_account.reload() + >>> analytic_account.credit + Decimal('42.00') + >>> analytic_account.debit + Decimal('42.00') diff --git a/tests/test_analytic_account.py b/tests/test_analytic_account.py index a689ff8cfa..7806b4f325 100644 --- a/tests/test_analytic_account.py +++ b/tests/test_analytic_account.py @@ -6,6 +6,7 @@ from decimal import Decimal import trytond.tests.test_tryton from trytond.tests.test_tryton import ModuleTestCase from trytond.tests.test_tryton import POOL, DB_NAME, USER, CONTEXT +from trytond.tests.test_tryton import doctest_setup, doctest_teardown from trytond.transaction import Transaction @@ -139,4 +140,7 @@ def suite(): suite.addTest(test) suite.addTests(unittest.TestLoader().loadTestsFromTestCase( AnalyticAccountTestCase)) + suite.addTests(doctest.DocFileSuite('scenario_analytic_account.rst', + setUp=doctest_setup, tearDown=doctest_teardown, encoding='utf-8', + optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) return suite