diff --git a/tests/scenario_invoice.rst b/tests/scenario_invoice.rst index cfe3bae302..e8433fbbf2 100644 --- a/tests/scenario_invoice.rst +++ b/tests/scenario_invoice.rst @@ -8,6 +8,12 @@ Imports:: >>> 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, create_tax, set_tax_code + >>> from.trytond.modules.account_invoice.tests.tools import \ + ... set_fiscalyear_invoice_sequences >>> today = datetime.date.today() Create database:: @@ -20,122 +26,38 @@ Install account_invoice:: >>> Module = Model.get('ir.module.module') >>> account_invoice_module, = Module.find( ... [('name', '=', 'account_invoice')]) - >>> Module.install([account_invoice_module.id], config.context) + >>> account_invoice_module.click('install') >>> Wizard('ir.module.module.install_upgrade').execute('upgrade') Create company:: - >>> Currency = Model.get('currency.currency') - >>> CurrencyRate = Model.get('currency.currency.rate') - >>> 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='.') - ... currency.save() - ... CurrencyRate(date=today + relativedelta(month=1, day=1), - ... rate=Decimal('1.0'), currency=currency).save() - ... else: - ... currency, = currencies - >>> 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 - >>> company.currency = currency - >>> company_config.execute('add') - >>> company, = Company.find([]) - -Reload the context:: - - >>> User = Model.get('res.user') - >>> config._context = User.get_preferences(True, config.context) + >>> _ = create_company() + >>> company = get_company() Create fiscal year:: - >>> FiscalYear = Model.get('account.fiscalyear') - >>> Sequence = Model.get('ir.sequence') - >>> SequenceStrict = Model.get('ir.sequence.strict') - >>> fiscalyear = FiscalYear(name=str(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_seq = Sequence(name=str(today.year), code='account.move', - ... company=company) - >>> post_move_seq.save() - >>> fiscalyear.post_move_sequence = post_move_seq - >>> invoice_seq = SequenceStrict(name=str(today.year), - ... code='account.invoice', company=company) - >>> invoice_seq.save() - >>> fiscalyear.out_invoice_sequence = invoice_seq - >>> fiscalyear.in_invoice_sequence = invoice_seq - >>> fiscalyear.out_credit_note_sequence = invoice_seq - >>> fiscalyear.in_credit_note_sequence = invoice_seq - >>> fiscalyear.save() - >>> FiscalYear.create_period([fiscalyear.id], config.context) + >>> fiscalyear = set_fiscalyear_invoice_sequences( + ... create_fiscalyear(company)) + >>> fiscalyear.click('create_period') + >>> period = fiscalyear.periods[0] Create chart of accounts:: - >>> AccountTemplate = Model.get('account.account.template') - >>> Account = Model.get('account.account') - >>> 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), - ... ]) - >>> expense, = Account.find([ - ... ('kind', '=', 'expense'), - ... ('company', '=', company.id), - ... ]) - >>> account_tax, = Account.find([ - ... ('kind', '=', 'other'), - ... ('company', '=', company.id), - ... ('name', '=', 'Main Tax'), - ... ]) - >>> create_chart.form.account_receivable = receivable - >>> create_chart.form.account_payable = payable - >>> create_chart.execute('create_properties') + >>> _ = create_chart(company) + >>> accounts = get_accounts(company) + >>> receivable = accounts['receivable'] + >>> revenue = accounts['revenue'] + >>> expense = accounts['expense'] + >>> account_tax = accounts['tax'] Create tax:: - >>> TaxCode = Model.get('account.tax.code') - >>> Tax = Model.get('account.tax') - >>> tax = Tax() - >>> tax.name = 'Tax' - >>> tax.description = 'Tax' - >>> tax.type = 'percentage' - >>> tax.rate = Decimal('.10') - >>> tax.invoice_account = account_tax - >>> tax.credit_note_account = account_tax - >>> invoice_base_code = TaxCode(name='invoice base') - >>> invoice_base_code.save() - >>> tax.invoice_base_code = invoice_base_code - >>> invoice_tax_code = TaxCode(name='invoice tax') - >>> invoice_tax_code.save() - >>> tax.invoice_tax_code = invoice_tax_code - >>> credit_note_base_code = TaxCode(name='credit note base') - >>> credit_note_base_code.save() - >>> tax.credit_note_base_code = credit_note_base_code - >>> credit_note_tax_code = TaxCode(name='credit note tax') - >>> credit_note_tax_code.save() - >>> tax.credit_note_tax_code = credit_note_tax_code + >>> tax = set_tax_code(create_tax(Decimal('.10'))) >>> tax.save() + >>> invoice_base_code = tax.invoice_base_code + >>> invoice_tax_code = tax.invoice_tax_code + >>> credit_note_base_code = tax.credit_note_base_code + >>> credit_note_tax_code = tax.credit_note_tax_code Create party:: @@ -198,9 +120,7 @@ Create invoice:: Decimal('20.00') >>> invoice.total_amount Decimal('240.00') - >>> invoice.save() - >>> Invoice.post([invoice.id], config.context) - >>> invoice.reload() + >>> invoice.click('post') >>> invoice.state u'posted' >>> invoice.untaxed_amount @@ -278,8 +198,6 @@ Create empty invoice:: >>> invoice = Invoice() >>> invoice.party = party >>> invoice.payment_term = payment_term - >>> invoice.save() - >>> Invoice.post([invoice.id], config.context) - >>> invoice.reload() + >>> invoice.click('post') >>> invoice.state u'paid' diff --git a/tests/scenario_invoice_alternate_currency.rst b/tests/scenario_invoice_alternate_currency.rst index 20bc91e325..24f7507d7f 100644 --- a/tests/scenario_invoice_alternate_currency.rst +++ b/tests/scenario_invoice_alternate_currency.rst @@ -9,6 +9,13 @@ Imports:: >>> from decimal import Decimal >>> from operator import attrgetter >>> from proteus import config, Model, Wizard + >>> from trytond.modules.currency.tests.tools import get_currency + >>> 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, set_tax_code + >>> from.trytond.modules.account_invoice.tests.tools import \ + ... set_fiscalyear_invoice_sequences >>> today = datetime.date.today() Create database:: @@ -21,133 +28,38 @@ Install account_invoice:: >>> Module = Model.get('ir.module.module') >>> account_invoice_module, = Module.find( ... [('name', '=', 'account_invoice')]) - >>> Module.install([account_invoice_module.id], config.context) + >>> account_invoice_module.click('install') >>> Wizard('ir.module.module.install_upgrade').execute('upgrade') Create company:: - >>> Currency = Model.get('currency.currency') - >>> CurrencyRate = Model.get('currency.currency.rate') - >>> 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='.') - ... currency.save() - ... CurrencyRate(date=today + relativedelta(month=1, day=1), - ... rate=Decimal('1.0'), currency=currency).save() - ... else: - ... currency, = currencies - >>> currencies = Currency.find([('code', '=', 'EUR')]) - >>> if not currencies: - ... eur = Currency(name='Euro', symbol=u'€', code='EUR', - ... rounding=Decimal('0.01'), mon_grouping='[]', - ... mon_decimal_point='.') - ... eur.save() - ... CurrencyRate(date=today + relativedelta(month=1, day=1), - ... rate=Decimal('2.0'), currency=eur).save() - ... else: - ... eur, = currencies - - >>> 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 - >>> company.currency = currency - >>> company_config.execute('add') - >>> company, = Company.find([]) - -Reload the context:: - - >>> User = Model.get('res.user') - >>> config._context = User.get_preferences(True, config.context) + >>> currency = get_currency('USD') + >>> eur = get_currency('EUR') + >>> _ = create_company(currency=currency) + >>> company = get_company() Create fiscal year:: - >>> FiscalYear = Model.get('account.fiscalyear') - >>> Sequence = Model.get('ir.sequence') - >>> SequenceStrict = Model.get('ir.sequence.strict') - >>> fiscalyear = FiscalYear(name=str(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_seq = Sequence(name=str(today.year), code='account.move', - ... company=company) - >>> post_move_seq.save() - >>> fiscalyear.post_move_sequence = post_move_seq - >>> invoice_seq = SequenceStrict(name=str(today.year), - ... code='account.invoice', company=company) - >>> invoice_seq.save() - >>> fiscalyear.out_invoice_sequence = invoice_seq - >>> fiscalyear.in_invoice_sequence = invoice_seq - >>> fiscalyear.out_credit_note_sequence = invoice_seq - >>> fiscalyear.in_credit_note_sequence = invoice_seq - >>> 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') - >>> 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), - ... ]) - >>> expense, = Account.find([ - ... ('kind', '=', 'expense'), - ... ('company', '=', company.id), - ... ]) - >>> account_tax, = Account.find([ - ... ('kind', '=', 'other'), - ... ('company', '=', company.id), - ... ('name', '=', 'Main Tax'), - ... ]) - >>> create_chart.form.account_receivable = receivable - >>> create_chart.form.account_payable = payable - >>> create_chart.execute('create_properties') + >>> _ = create_chart(company) + >>> accounts = get_accounts(company) + >>> revenue = accounts['revenue'] + >>> expense = accounts['expense'] + >>> account_tax = accounts['tax'] Create tax:: - >>> TaxCode = Model.get('account.tax.code') - >>> Tax = Model.get('account.tax') - >>> tax = Tax() - >>> tax.name = 'Tax' - >>> tax.description = 'Tax' - >>> tax.type = 'percentage' - >>> tax.rate = Decimal('.10') - >>> tax.invoice_account = account_tax - >>> tax.credit_note_account = account_tax - >>> invoice_base_code = TaxCode(name='invoice base') - >>> invoice_base_code.save() - >>> tax.invoice_base_code = invoice_base_code - >>> invoice_tax_code = TaxCode(name='invoice tax') - >>> invoice_tax_code.save() - >>> tax.invoice_tax_code = invoice_tax_code - >>> credit_note_base_code = TaxCode(name='credit note base') - >>> credit_note_base_code.save() - >>> tax.credit_note_base_code = credit_note_base_code - >>> credit_note_tax_code = TaxCode(name='credit note tax') - >>> credit_note_tax_code.save() - >>> tax.credit_note_tax_code = credit_note_tax_code + >>> tax = set_tax_code(create_tax(Decimal('.10'))) >>> tax.save() + >>> invoice_base_code = tax.invoice_base_code + >>> invoice_tax_code = tax.invoice_tax_code + >>> credit_note_base_code = tax.credit_note_base_code + >>> credit_note_tax_code = tax.credit_note_tax_code Create party:: @@ -224,17 +136,7 @@ Create invoice with alternate currency:: Create negative tax:: - >>> negative_tax = Tax() - >>> negative_tax.name = 'Negative Tax' - >>> negative_tax.description = 'Negative Tax' - >>> negative_tax.type = 'percentage' - >>> negative_tax.rate = Decimal('-.10') - >>> negative_tax.invoice_account = account_tax - >>> negative_tax.credit_note_account = account_tax - >>> negative_tax.invoice_base_code = invoice_base_code - >>> negative_tax.invoice_tax_code = invoice_tax_code - >>> negative_tax.credit_note_base_code = credit_note_base_code - >>> negative_tax.credit_note_tax_code = credit_note_tax_code + >>> negative_tax = set_tax_code(create_tax(Decimal('-.10'))) >>> negative_tax.save() Create invoice with alternate currency and negative taxes:: diff --git a/tests/scenario_invoice_supplier.rst b/tests/scenario_invoice_supplier.rst index 03c6ec956f..864d960dcf 100644 --- a/tests/scenario_invoice_supplier.rst +++ b/tests/scenario_invoice_supplier.rst @@ -8,6 +8,12 @@ Imports:: >>> 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, create_tax, set_tax_code + >>> from.trytond.modules.account_invoice.tests.tools import \ + ... set_fiscalyear_invoice_sequences >>> today = datetime.date.today() Create database:: @@ -20,122 +26,37 @@ Install account_invoice:: >>> Module = Model.get('ir.module.module') >>> account_invoice_module, = Module.find( ... [('name', '=', 'account_invoice')]) - >>> Module.install([account_invoice_module.id], config.context) + >>> account_invoice_module.click('install') >>> Wizard('ir.module.module.install_upgrade').execute('upgrade') Create company:: - >>> Currency = Model.get('currency.currency') - >>> CurrencyRate = Model.get('currency.currency.rate') - >>> 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='.') - ... currency.save() - ... CurrencyRate(date=today + relativedelta(month=1, day=1), - ... rate=Decimal('1.0'), currency=currency).save() - ... else: - ... currency, = currencies - >>> 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 - >>> company.currency = currency - >>> company_config.execute('add') - >>> company, = Company.find([]) - -Reload the context:: - - >>> User = Model.get('res.user') - >>> config._context = User.get_preferences(True, config.context) + >>> _ = create_company() + >>> company = get_company() Create fiscal year:: - >>> FiscalYear = Model.get('account.fiscalyear') - >>> Sequence = Model.get('ir.sequence') - >>> SequenceStrict = Model.get('ir.sequence.strict') - >>> fiscalyear = FiscalYear(name=str(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_seq = Sequence(name=str(today.year), code='account.move', - ... company=company) - >>> post_move_seq.save() - >>> fiscalyear.post_move_sequence = post_move_seq - >>> invoice_seq = SequenceStrict(name=str(today.year), - ... code='account.invoice', company=company) - >>> invoice_seq.save() - >>> fiscalyear.out_invoice_sequence = invoice_seq - >>> fiscalyear.in_invoice_sequence = invoice_seq - >>> fiscalyear.out_credit_note_sequence = invoice_seq - >>> fiscalyear.in_credit_note_sequence = invoice_seq - >>> 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') - >>> 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), - ... ]) - >>> expense, = Account.find([ - ... ('kind', '=', 'expense'), - ... ('company', '=', company.id), - ... ]) - >>> account_tax, = Account.find([ - ... ('kind', '=', 'other'), - ... ('company', '=', company.id), - ... ('name', '=', 'Main Tax'), - ... ]) - >>> create_chart.form.account_receivable = receivable - >>> create_chart.form.account_payable = payable - >>> create_chart.execute('create_properties') + >>> _ = create_chart(company) + >>> accounts = get_accounts(company) + >>> payable = accounts['payable'] + >>> revenue = accounts['revenue'] + >>> expense = accounts['expense'] + >>> account_tax = accounts['tax'] Create tax:: - >>> TaxCode = Model.get('account.tax.code') - >>> Tax = Model.get('account.tax') - >>> tax = Tax() - >>> tax.name = 'Tax' - >>> tax.description = 'Tax' - >>> tax.type = 'percentage' - >>> tax.rate = Decimal('.10') - >>> tax.invoice_account = account_tax - >>> tax.credit_note_account = account_tax - >>> invoice_base_code = TaxCode(name='invoice base') - >>> invoice_base_code.save() - >>> tax.invoice_base_code = invoice_base_code - >>> invoice_tax_code = TaxCode(name='invoice tax') - >>> invoice_tax_code.save() - >>> tax.invoice_tax_code = invoice_tax_code - >>> credit_note_base_code = TaxCode(name='credit note base') - >>> credit_note_base_code.save() - >>> tax.credit_note_base_code = credit_note_base_code - >>> credit_note_tax_code = TaxCode(name='credit note tax') - >>> credit_note_tax_code.save() - >>> tax.credit_note_tax_code = credit_note_tax_code + >>> tax = set_tax_code(create_tax(Decimal('.10'))) >>> tax.save() + >>> invoice_base_code = tax.invoice_base_code + >>> invoice_tax_code = tax.invoice_tax_code + >>> credit_note_base_code = tax.credit_note_base_code + >>> credit_note_tax_code = tax.credit_note_tax_code Create party:: @@ -197,9 +118,7 @@ Create invoice:: Decimal('10.00') >>> invoice.total_amount Decimal('120.00') - >>> invoice.save() - >>> Invoice.post([invoice.id], config.context) - >>> invoice.reload() + >>> invoice.click('post') >>> invoice.state u'posted' >>> invoice.untaxed_amount @@ -261,9 +180,8 @@ Create a posted and a draft invoice to cancel:: >>> line = invoice.lines.new() >>> line.product = product >>> line.quantity = 1 - >>> invoice.save() >>> invoice.click('post') - >>> invoice_draft = Invoice(Invoice.copy([invoice.id], config.context)[0]) + >>> invoice_draft, = Invoice.duplicate([invoice]) Cancel draft invoice:: diff --git a/tests/tools.py b/tests/tools.py new file mode 100644 index 0000000000..6e14d32044 --- /dev/null +++ b/tests/tools.py @@ -0,0 +1,28 @@ +#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 + +__all__ = ['set_fiscalyear_invoice_sequences'] + + +def set_fiscalyear_invoice_sequences(fiscalyear, config=None): + "Set invoice sequences to fiscalyear" + SequenceStrict = Model.get('ir.sequence.strict', config=config) + + invoice_seq = SequenceStrict(name=fiscalyear.name, code='account.invoice', + company=fiscalyear.company) + invoice_seq.save() + fiscalyear.out_invoice_sequence = invoice_seq + fiscalyear.in_invoice_sequence = invoice_seq + fiscalyear.out_credit_note_sequence = invoice_seq + fiscalyear.in_credit_note_sequence = invoice_seq + return fiscalyear + + +def create_payment_term(config=None): + "Create a direct payment term" + PaymentTerm = Model.get('account.invoice.payment_term') + + payment_term = PaymentTerm(name='Direct') + payment_term.lines.new(type='remainder', days=0) + return payment_term