Created
June 13, 2013 08:34
-
-
Save shalabhaggarwal/5772141 to your computer and use it in GitHub Desktop.
Issue with tryton tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
test_invoice | |
""" | |
import sys | |
import os | |
from dateutil.relativedelta import relativedelta | |
from decimal import Decimal | |
from datetime import datetime | |
DIR = os.path.abspath(os.path.normpath(os.path.join(__file__, | |
'..', '..', '..', '..', '..', 'trytond'))) | |
if os.path.isdir(DIR): | |
sys.path.insert(0, os.path.dirname(DIR)) | |
import unittest | |
import trytond | |
import trytond.tests.test_tryton | |
from trytond.tests.test_tryton import POOL, DB_NAME, USER, CONTEXT, \ | |
test_view, test_depends | |
from trytond.transaction import Transaction | |
from trytond.config import CONFIG | |
CONFIG['data_path'] = '.' | |
class TestInvoice(unittest.TestCase): | |
"Test Invoice" | |
def setUp(self): | |
"Setup" | |
trytond.tests.test_tryton.install_module('account_invoice') | |
self.Party = POOL.get('party.party') | |
self.Address = POOL.get('party.address') | |
self.Company = POOL.get('company.company') | |
self.Currency = POOL.get('currency.currency') | |
self.CurrencyRate = POOL.get('currency.currency.rate') | |
self.Country = POOL.get('country.country') | |
self.Subdivision = POOL.get('country.subdivision') | |
self.FiscalYear = POOL.get('account.fiscalyear') | |
self.Sequence = POOL.get('ir.sequence') | |
self.SequenceStrict = POOL.get('ir.sequence.strict') | |
self.AccountTemplate = POOL.get('account.account.template') | |
self.Account = POOL.get('account.account') | |
self.Invoice = POOL.get('account.invoice') | |
self.CreateChartAccount = POOL.get( | |
'account.create_chart', type="wizard" | |
) | |
self.PaymentTerm = POOL.get('account.invoice.payment_term') | |
self.User = POOL.get('res.user') | |
def test0005views(self): | |
''' | |
Test views. | |
''' | |
test_view('account_invoice') | |
def test0006depends(self): | |
''' | |
Test depends. | |
''' | |
test_depends() | |
def setup_defaults(self): | |
"Setup defaults" | |
self.usd, = self.Currency.create([{ | |
'name': 'United Stated Dollar', | |
'code': 'USD', | |
'symbol': 'USD', | |
}]) | |
self.CurrencyRate.create([{ | |
'rate': Decimal("1.0"), | |
'currency': self.usd.id, | |
}]) | |
self.Country.create([ | |
{ | |
'name': 'France', | |
'code': 'FR', | |
}, { | |
'name': 'United States', | |
'code': 'US' | |
} | |
]) | |
self.company_party, = self.Party.create([{ | |
'name': 'Openlabs', | |
}]) | |
self.company, = self.Company.create([{ | |
'party': self.company_party.id, | |
'currency': self.usd.id, | |
}]) | |
self.User.write([self.User(USER)], { | |
'main_company': self.company.id, | |
'company': self.company.id, | |
}) | |
CONTEXT.update(self.User.get_preferences(context_only=True)) | |
date = datetime.utcnow().date() | |
invoice_sequence, = self.SequenceStrict.create([{ | |
'name': '%s' % date.year, | |
'code': 'account.invoice', | |
'company': self.company.id, | |
}]) | |
fiscal_year, = self.FiscalYear.create([{ | |
'name': '%s' % date.year, | |
'start_date': date + relativedelta(month=1, day=1), | |
'end_date': date + relativedelta(month=12, day=31), | |
'company': self.company.id, | |
'post_move_sequence': self.Sequence.create([{ | |
'name': '%s' % date.year, | |
'code': 'account.move', | |
'company': self.company.id, | |
}])[0].id, | |
'out_invoice_sequence': invoice_sequence.id, | |
'in_invoice_sequence': invoice_sequence.id, | |
'out_credit_note_sequence': invoice_sequence.id, | |
'in_credit_note_sequence': invoice_sequence.id, | |
}]) | |
self.FiscalYear.create_period([fiscal_year]) | |
account_template, = self.AccountTemplate.search( | |
[('parent', '=', None)] | |
) | |
session_id, _, _ = self.CreateChartAccount.create() | |
create_chart = self.CreateChartAccount(session_id) | |
create_chart.account.account_template = account_template | |
create_chart.account.company = self.company | |
create_chart.transition_create_account() | |
revenue, = self.Account.search([ | |
('kind', '=', 'revenue'), | |
('company', '=', self.company.id), | |
]) | |
receivable, = self.Account.search([ | |
('kind', '=', 'receivable'), | |
('company', '=', self.company.id), | |
]) | |
payable, = self.Account.search([ | |
('kind', '=', 'payable'), | |
('company', '=', self.company.id), | |
]) | |
expense, = self.Account.search([ | |
('kind', '=', 'expense'), | |
('company', '=', self.company.id), | |
]) | |
create_chart.properties.company = self.company | |
create_chart.properties.account_receivable = receivable | |
create_chart.properties.account_payable = payable | |
create_chart.transition_create_properties() | |
self.Party.write( | |
[self.Party(self.company_party)], { | |
'account_payable': payable.id, | |
'account_receivable': receivable.id, | |
} | |
) | |
self.PaymentTerm.create([{ | |
'name': 'Direct', | |
'lines': [('create', [{'type': 'remainder'}])] | |
}]) | |
def get_account_by_kind(self, kind, company=None, silent=True): | |
"""Returns an account with given spec | |
:param kind: receivable/payable/expense/revenue | |
:param silent: dont raise error if account is not found | |
""" | |
Account = POOL.get('account.account') | |
Company = POOL.get('company.company') | |
if company is None: | |
company, = Company.search([], limit=1) | |
accounts = Account.search([ | |
('kind', '=', kind), | |
('company', '=', company.id) | |
], limit=1) | |
if not accounts and not silent: | |
raise Exception("Account not found") | |
return accounts[0] if accounts else False | |
def test_0010_test_invoice(self): | |
"""Test invoice | |
""" | |
with Transaction().start(DB_NAME, USER, context=CONTEXT) as txn: | |
# Call method to setup defaults | |
self.setup_defaults() | |
self.assertEqual(len(self.Invoice.search([])), 0) | |
txn.cursor.rollback() | |
def test_0020_test_invoice(self): | |
"""Test invoice | |
""" | |
with Transaction().start(DB_NAME, USER, context=CONTEXT) as txn: | |
# Call method to setup defaults | |
self.setup_defaults() | |
self.assertEqual(len(self.Invoice.search([])), 0) | |
txn.cursor.rollback() | |
def test_0030_test_invoice(self): | |
"""Test invoice | |
""" | |
with Transaction().start(DB_NAME, USER, context=CONTEXT) as txn: | |
# Call method to setup defaults | |
self.setup_defaults() | |
self.assertEqual(len(self.Invoice.search([])), 0) | |
txn.cursor.rollback() | |
def suite(): | |
"Invoice test suite" | |
suite = trytond.tests.test_tryton.suite() | |
suite.addTests( | |
unittest.TestLoader().loadTestsFromTestCase(TestInvoice) | |
) | |
return suite | |
if __name__ == '__main__': | |
unittest.TextTestRunner(verbosity=2).run(suite()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment