Fix test and scenario

This commit is contained in:
Jes?s Mart?n Jim?nez 2016-06-02 13:02:19 +02:00
parent 8d7ec9d5dc
commit d0e3bd3712
2 changed files with 41 additions and 97 deletions

View file

@ -3,12 +3,17 @@ Account Invoice Tree 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, create_tax, set_tax_code
>>> from trytond.modules.account_invoice.tests.tools import \
... set_fiscalyear_invoice_sequences
>>> today = datetime.date.today()
Create database::
@ -18,36 +23,15 @@ Create database::
Install sale_wbs::
>>> Module = Model.get('ir.module.module')
>>> Module = Model.get('ir.module')
>>> module, = Module.find([('name', '=', 'account_invoice_tree')])
>>> module.click('install')
>>> Wizard('ir.module.module.install_upgrade').execute('upgrade')
>>> Wizard('ir.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='U.S. Dollar', symbol='$', code='USD',
... rounding=Decimal('0.01'), mon_grouping='[3, 3, 0]',
... 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 = 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([])
>>> _ = create_company()
>>> company = get_company()
Reload the context::
@ -57,62 +41,24 @@ 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=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')
>>> _ = create_chart(company)
>>> accounts = get_accounts(company)
>>> receivable = accounts['receivable']
>>> payable = accounts['payable']
>>> revenue = accounts['revenue']
>>> expense = accounts['expense']
>>> cash = accounts['cash']
Set Cash journal::
>>> Journal = 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),
... ])
>>> expense, = Account.find([
... ('kind', '=', 'expense'),
... ('company', '=', company.id),
... ])
>>> create_chart.form.account_receivable = receivable
>>> create_chart.form.account_payable = payable
>>> create_chart.execute('create_properties')
>>> cash, = Account.find([
... ('kind', '=', 'other'),
... ('name', '=', 'Main Cash'),
... ('company', '=', company.id),
... ])
>>> cash_journal, = Journal.find([('type', '=', 'cash')])
>>> cash_journal.credit_account = cash
>>> cash_journal.debit_account = cash
@ -173,10 +119,11 @@ Create product::
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 = PaymentTerm(name='Term')
>>> line = payment_term.lines.new(type='percent', ratio=Decimal('.5'))
>>> delta = line.relativedeltas.new(days=20)
>>> line = payment_term.lines.new(type='remainder')
>>> delta = line.relativedeltas.new(days=40)
>>> payment_term.save()
Create a Invoice::
@ -190,6 +137,7 @@ Create a Invoice::
>>> invoice_line.product = product1
>>> invoice_line.description = 'Product Line 1'
>>> invoice_line.quantity = 10
>>> invoice_line.unit_price = Decimal('40')
>>> invoice_line = invoice.lines.new()
>>> invoice_line.type = 'title'
>>> invoice_line.description = 'Chapter 1'
@ -203,16 +151,19 @@ Create a Invoice::
>>> child_invoice_line.product = service1
>>> child_invoice_line.description = 'Service Line 1'
>>> child_invoice_line.quantity = 5
>>> child_invoice_line.unit_price = Decimal('40')
>>> child_invoice_line = invoice.lines.new()
>>> child_invoice_line.parent = InvoiceLine(chapter1_line.id)
>>> child_invoice_line.product = product2
>>> child_invoice_line.description = 'Product Line 2'
>>> child_invoice_line.quantity = 15
>>> child_invoice_line.unit_price = Decimal('40')
>>> child_invoice_line = invoice.lines.new()
>>> child_invoice_line.parent = InvoiceLine(chapter2_line.id)
>>> child_invoice_line.product = service2
>>> child_invoice_line.description = 'Service Line 2'
>>> child_invoice_line.quantity = 10
>>> child_invoice_line.unit_price = Decimal('40')
>>> invoice.save()
Check invoice structure::

View file

@ -3,29 +3,22 @@
import unittest
import doctest
import trytond.tests.test_tryton
from trytond.tests.test_tryton import test_view, test_depends
from trytond.tests.test_tryton import ModuleTestCase
from trytond.tests.test_tryton import doctest_setup, doctest_teardown
from trytond.tests.test_tryton import doctest_checker
class TestCase(unittest.TestCase):
'Test module'
def setUp(self):
trytond.tests.test_tryton.install_module('account_invoice_tree')
def test0005views(self):
'Test views'
test_view('account_invoice_tree')
def test0006depends(self):
'Test depends'
test_depends()
class AccountInvoiceTreeTestCase(ModuleTestCase):
'Test Account Invoice Tree module'
module = 'account_invoice_tree'
def suite():
suite = trytond.tests.test_tryton.suite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestCase))
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
AccountInvoiceTreeTestCase))
suite.addTests(doctest.DocFileSuite('scenario_account_invoice_tree.rst',
setUp=doctest_setup, tearDown=doctest_teardown, encoding='utf-8',
checker=doctest_checker,
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
return suite