From edeff346f66e5b052dc304a7e9207965f26f4311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 24 Oct 2014 10:44:05 +0200 Subject: [PATCH] Add some test tools to ease scenario writing review11331002 --- tests/scenario_account_asset.rst | 125 +++++++------------------------ tests/tools.py | 29 +++++++ 2 files changed, 56 insertions(+), 98 deletions(-) create mode 100644 tests/tools.py diff --git a/tests/scenario_account_asset.rst b/tests/scenario_account_asset.rst index e8f30a8f87..6b3c418811 100644 --- a/tests/scenario_account_asset.rst +++ b/tests/scenario_account_asset.rst @@ -2,16 +2,20 @@ Account Asset Scenario ====================== -============= -General Setup -============= - 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 + >>> from.trytond.modules.account_invoice.tests.tools import \ + ... set_fiscalyear_invoice_sequences, create_payment_term + >>> from trytond.modules.account_asset.tests.tools \ + ... import add_asset_accounts >>> today = datetime.date.today() Create database:: @@ -22,37 +26,16 @@ Create database:: Install account_asset:: >>> Module = Model.get('ir.module.module') - >>> modules = Module.find([ + >>> module, = Module.find([ ... ('name', '=', 'account_asset'), - ... ]) - >>> Module.install([x.id for x in modules], config.context) + ... ]) + >>> module.click('install') >>> Wizard('ir.module.module.install_upgrade').execute('upgrade') Create company:: - >>> Currency = Model.get('currency.currency') - >>> CurrencyRate = Model.get('currency.currency.rate') - >>> Company = Model.get('company.company') - >>> Party = Model.get('party.party') - >>> company_config = Wizard('company.company.config') - >>> company_config.execute('company') - >>> company = company_config.form - >>> party = Party(name='Dunder Mifflin') - >>> party.save() - >>> company.party = party - >>> currencies = Currency.find([('code', '=', 'USD')]) - >>> if not currencies: - ... currency = Currency(name='US Dollar', symbol=u'$', code='USD', - ... rounding=Decimal('0.01'), mon_grouping='[]', - ... mon_decimal_point='.', mon_thousands_sep=',') - ... currency.save() - ... CurrencyRate(date=today + relativedelta(month=1, day=1), - ... rate=Decimal('1.0'), currency=currency).save() - ... else: - ... currency, = currencies - >>> company.currency = currency - >>> company_config.execute('add') - >>> company, = Company.find() + >>> _ = create_company() + >>> company = get_company() Reload the context:: @@ -61,63 +44,18 @@ Reload the context:: Create fiscal year:: - >>> FiscalYear = Model.get('account.fiscalyear') - >>> Sequence = Model.get('ir.sequence') - >>> SequenceStrict = Model.get('ir.sequence.strict') - >>> fiscalyear = FiscalYear(name='%s' % today.year) - >>> fiscalyear.start_date = today + relativedelta(month=1, day=1) - >>> fiscalyear.end_date = today + relativedelta(month=12, day=31) - >>> fiscalyear.company = company - >>> post_move_sequence = Sequence(name='%s' % today.year, - ... code='account.move', - ... company=company) - >>> post_move_sequence.save() - >>> fiscalyear.post_move_sequence = post_move_sequence - >>> invoice_sequence = SequenceStrict(name='%s' % today.year, - ... code='account.invoice', - ... company=company) - >>> invoice_sequence.save() - >>> fiscalyear.out_invoice_sequence = invoice_sequence - >>> fiscalyear.in_invoice_sequence = invoice_sequence - >>> fiscalyear.out_credit_note_sequence = invoice_sequence - >>> fiscalyear.in_credit_note_sequence = invoice_sequence - >>> fiscalyear.save() - >>> FiscalYear.create_period([fiscalyear.id], config.context) + >>> fiscalyear = set_fiscalyear_invoice_sequences( + ... create_fiscalyear(company)) + >>> fiscalyear.click('create_period') Create chart of accounts:: - >>> AccountTemplate = Model.get('account.account.template') - >>> Account = Model.get('account.account') - >>> AccountJournal = Model.get('account.journal') - >>> account_template, = AccountTemplate.find([('parent', '=', None)]) - >>> create_chart = Wizard('account.create_chart') - >>> create_chart.execute('account') - >>> create_chart.form.account_template = account_template - >>> create_chart.form.company = company - >>> create_chart.execute('create_account') - >>> receivable, = Account.find([ - ... ('kind', '=', 'receivable'), - ... ('company', '=', company.id), - ... ]) - >>> payable, = Account.find([ - ... ('kind', '=', 'payable'), - ... ('company', '=', company.id), - ... ]) - >>> revenue, = Account.find([ - ... ('kind', '=', 'revenue'), - ... ('company', '=', company.id), - ... ]) - >>> asset_account, expense = Account.find([ - ... ('kind', '=', 'expense'), - ... ('company', '=', company.id), - ... ], order=[('name', 'DESC')]) - >>> depreciation_account, = Account.find([ - ... ('kind', '=', 'other'), - ... ('name', '=', 'Depreciation'), - ... ]) - >>> create_chart.form.account_receivable = receivable - >>> create_chart.form.account_payable = payable - >>> create_chart.execute('create_properties') + >>> _ = create_chart(company) + >>> accounts = add_asset_accounts(get_accounts(company), company) + >>> revenue = accounts['revenue'] + >>> asset_account = accounts['asset'] + >>> expense = accounts['expense'] + >>> depreciation_account = accounts['depreciation'] Create an asset:: @@ -152,11 +90,7 @@ Create supplier:: Create payment term:: - >>> PaymentTerm = Model.get('account.invoice.payment_term') - >>> PaymentTermLine = Model.get('account.invoice.payment_term.line') - >>> payment_term = PaymentTerm(name='Direct') - >>> payment_term_line = PaymentTermLine(type='remainder', days=0) - >>> payment_term.lines.append(payment_term_line) + >>> payment_term = create_payment_term() >>> payment_term.save() Buy an asset:: @@ -172,8 +106,7 @@ Buy an asset:: >>> invoice_line.account == asset_account True >>> supplier_invoice.invoice_date = today + relativedelta(day=1, month=1) - >>> supplier_invoice.save() - >>> Invoice.post([supplier_invoice.id], config.context) + >>> supplier_invoice.click('post') >>> supplier_invoice.state u'posted' >>> invoice_line, = supplier_invoice.lines @@ -199,9 +132,7 @@ Depreciate the asset:: >>> asset.unit == unit True >>> asset.residual_value = Decimal('100') - >>> asset.save() - >>> Asset.create_lines([asset.id], config.context) - >>> asset.reload() + >>> asset.click('create_lines') >>> len(asset.lines) 24 >>> [l.depreciation for l in asset.lines] == [Decimal('37.5')] * 24 @@ -218,8 +149,7 @@ Depreciate the asset:: Decimal('100.00') >>> asset.lines[-1].accumulated_depreciation Decimal('900.00') - >>> Asset.run([asset.id], config.context) - >>> asset.reload() + >>> asset.click('run') Create Moves for 3 months:: @@ -308,8 +238,7 @@ Sale the asset:: >>> invoice_line.unit_price = Decimal('600') >>> invoice_line.account == revenue True - >>> customer_invoice.save() - >>> Invoice.post([customer_invoice.id], config.context) + >>> customer_invoice.click('post') >>> customer_invoice.state u'posted' >>> asset.reload() diff --git a/tests/tools.py b/tests/tools.py new file mode 100644 index 0000000000..cf03206002 --- /dev/null +++ b/tests/tools.py @@ -0,0 +1,29 @@ +# This file is part of Tryton. The COPYRIGHT file at the top level of +# this repository contains the full copyright notices and license terms. +from proteus import Model + +from trytond.modules.company.tests.tools import get_company + + +def add_asset_accounts(accounts, company=None, config=None): + "Add asset kind to accounts" + Account = Model.get('account.account', config=config) + + if not company: + company = get_company() + + expense_accounts = Account.find([ + ('kind', '=', 'expense'), + ('company', '=', company.id), + ]) + for account in expense_accounts: + if account.name == 'Expense': + accounts['expense'] = account + elif account.name == 'Assets': + accounts['asset'] = account + depreciation, = Account.find([ + ('kind', '=', 'other'), + ('name', '=', 'Depreciation'), + ]) + accounts['depreciation'] = depreciation + return accounts