From 5cc6fffd80d3953092332fd8d210a5d4cc40df71 Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Sun, 15 Feb 2015 13:11:01 +0100 Subject: [PATCH] Add doctest scenario issue4528 review11901002 --- setup.py | 10 +- tests/scenario_invoice.rst | 166 +++++++++++++++++++++++++++++++++ tests/test_analytic_invoice.py | 5 + 3 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 tests/scenario_invoice.rst diff --git a/setup.py b/setup.py index 4a91f60236..5e9323840f 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 to add analytic accounting on invoice', @@ -63,7 +69,7 @@ setup(name=name, ], package_data={ 'trytond.modules.analytic_invoice': (info.get('xml', []) - + ['tryton.cfg', 'view/*.xml', 'locale/*.po']), + + ['tryton.cfg', 'view/*.xml', 'locale/*.po', 'tests/*.rst']), }, classifiers=[ 'Development Status :: 5 - Production/Stable', @@ -89,6 +95,7 @@ setup(name=name, ], license='GPL-3', install_requires=requires, + dependency_links=dependency_links, zip_safe=False, entry_points=""" [trytond.modules] @@ -96,4 +103,5 @@ setup(name=name, """, test_suite='tests', test_loader='trytond.test_loader:Loader', + tests_require=tests_require, ) diff --git a/tests/scenario_invoice.rst b/tests/scenario_invoice.rst new file mode 100644 index 0000000000..d1c33fdb06 --- /dev/null +++ b/tests/scenario_invoice.rst @@ -0,0 +1,166 @@ +========================= +Analytic Invoice Scenario +========================= + +Imports:: + >>> import datetime + >>> from dateutil.relativedelta import relativedelta + >>> from decimal import Decimal + >>> from operator import attrgetter + >>> 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 + >>> from.trytond.modules.account_invoice.tests.tools import \ + ... set_fiscalyear_invoice_sequences, create_payment_term + >>> today = datetime.date.today() + +Create database:: + + >>> config = config.set_trytond() + >>> config.pool.test = True + +Install account_invoice:: + + >>> Module = Model.get('ir.module.module') + >>> analytic_invoice_module, = Module.find( + ... [('name', '=', 'analytic_invoice')]) + >>> analytic_invoice_module.click('install') + >>> Wizard('ir.module.module.install_upgrade').execute('upgrade') + +Create company:: + + >>> _ = create_company() + >>> company = get_company() + +Create fiscal year:: + + >>> fiscalyear = set_fiscalyear_invoice_sequences( + ... create_fiscalyear(company)) + >>> fiscalyear.click('create_period') + +Create chart of accounts:: + + >>> _ = create_chart(company) + >>> accounts = get_accounts(company) + >>> 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() + >>> mandatory_root = AnalyticAccount(type='root', name='Root', + ... mandatory=True) + >>> mandatory_root.save() + >>> mandatory_analytic_account = AnalyticAccount(root=mandatory_root, + ... parent=mandatory_root, name='Mandatory Analytic') + >>> mandatory_analytic_account.save() + +Create party:: + + >>> Party = Model.get('party.party') + >>> party = Party(name='Party') + >>> party.save() + +Create product:: + + >>> ProductUom = Model.get('product.uom') + >>> unit, = ProductUom.find([('name', '=', 'Unit')]) + >>> ProductTemplate = Model.get('product.template') + >>> Product = Model.get('product.product') + >>> product = Product() + >>> template = ProductTemplate() + >>> template.name = 'product' + >>> template.default_uom = unit + >>> template.type = 'service' + >>> template.list_price = Decimal('40') + >>> template.cost_price = Decimal('25') + >>> template.account_expense = expense + >>> template.account_revenue = revenue + >>> template.save() + >>> product.template = template + >>> product.save() + +Create payment term:: + + >>> payment_term = create_payment_term() + >>> payment_term.save() + +Create invoice with analytic accounts:: + + >>> Invoice = Model.get('account.invoice') + >>> invoice = Invoice() + >>> invoice.party = party + >>> invoice.payment_term = payment_term + >>> line = invoice.lines.new() + >>> entry, mandatory_entry = line.analytic_accounts + >>> entry.root == root + True + >>> bool(entry.required) + False + >>> entry.account = analytic_account + >>> mandatory_entry.root == mandatory_root + True + >>> bool(mandatory_entry.required) + True + >>> mandatory_entry.account = mandatory_analytic_account + >>> line.product = product + >>> line.quantity = 5 + >>> invoice.click('post') + >>> invoice.state + u'posted' + >>> analytic_account.reload() + >>> analytic_account.credit + Decimal('200.00') + >>> analytic_account.debit + Decimal('0.00') + >>> mandatory_analytic_account.reload() + >>> mandatory_analytic_account.credit + Decimal('200.00') + >>> mandatory_analytic_account.debit + Decimal('0.00') + + +Create invoice with an empty analytic account:: + + >>> invoice = Invoice() + >>> invoice.party = party + >>> invoice.payment_term = payment_term + >>> line = invoice.lines.new() + >>> entry, mandatory_entry = line.analytic_accounts + >>> mandatory_entry.account = mandatory_analytic_account + >>> line.product = product + >>> line.quantity = 1 + >>> invoice.click('post') + >>> invoice.state + u'posted' + >>> analytic_account.reload() + >>> analytic_account.credit + Decimal('200.00') + >>> analytic_account.debit + Decimal('0.00') + >>> mandatory_analytic_account.reload() + >>> mandatory_analytic_account.credit + Decimal('240.00') + >>> mandatory_analytic_account.debit + Decimal('0.00') + +Credit invoice with refund:: + + >>> credit = Wizard('account.invoice.credit', [invoice]) + >>> credit.form.with_refund = True + >>> credit.execute('credit') + >>> invoice.reload() + >>> invoice.state + u'paid' + >>> mandatory_analytic_account.reload() + >>> mandatory_analytic_account.credit + Decimal('240.00') + >>> mandatory_analytic_account.debit + Decimal('40.00') diff --git a/tests/test_analytic_invoice.py b/tests/test_analytic_invoice.py index 86eeb59764..69bc2e416c 100644 --- a/tests/test_analytic_invoice.py +++ b/tests/test_analytic_invoice.py @@ -1,8 +1,10 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. import unittest +import doctest import trytond.tests.test_tryton from trytond.tests.test_tryton import ModuleTestCase +from trytond.tests.test_tryton import doctest_setup, doctest_teardown class AnalyticInvoiceTestCase(ModuleTestCase): @@ -14,4 +16,7 @@ def suite(): suite = trytond.tests.test_tryton.suite() suite.addTests(unittest.TestLoader().loadTestsFromTestCase( AnalyticInvoiceTestCase)) + suite.addTests(doctest.DocFileSuite('scenario_invoice.rst', + setUp=doctest_setup, tearDown=doctest_teardown, encoding='utf-8', + optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) return suite