Add doctests
This commit is contained in:
1 parent
334824453a
commit
1f61c6b665
2 files changed
+234
No files matched your search
@@ -0,0 +1,218 @@
|
||||
=========================================
|
||||
Purchase Invoice Line Standalone Scenario
|
||||
=========================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime
|
||||
>>> from dateutil.relativedelta import relativedelta
|
||||
>>> from decimal import Decimal
|
||||
>>> from operator import attrgetter
|
||||
>>> from proteus import config, Model, Wizard
|
||||
>>> today = datetime.date.today()
|
||||
|
||||
Create database::
|
||||
|
||||
>>> current_config = config.set_trytond()
|
||||
>>> current_config.pool.test = True
|
||||
|
||||
Install purchase_invoice_line_standalone::
|
||||
|
||||
>>> Module = Model.get('ir.module.module')
|
||||
>>> purchase_module, = Module.find([('name', '=',
|
||||
... 'purchase_invoice_line_standalone')])
|
||||
>>> Module.install([purchase_module.id], current_config.context)
|
||||
>>> 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', '=', 'EUR')])
|
||||
>>> if not currencies:
|
||||
... currency = Currency(name='Euro', symbol=u'€', code='EUR',
|
||||
... rounding=Decimal('0.01'), mon_grouping='[3, 3, 0]',
|
||||
... 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')
|
||||
>>> company_config = Wizard('company.company.config')
|
||||
>>> company_config.execute('company')
|
||||
>>> company = company_config.form
|
||||
>>> company.name = 'Dunder Mifflin'
|
||||
>>> company.currency = currency
|
||||
>>> company_config.execute('add')
|
||||
>>> company, = Company.find([])
|
||||
|
||||
Reload the context::
|
||||
|
||||
>>> User = Model.get('res.user')
|
||||
>>> current_config._context = User.get_preferences(True,
|
||||
... current_config.context)
|
||||
|
||||
Create an accountant user::
|
||||
|
||||
>>> Group = Model.get('res.group')
|
||||
>>> accountant = User()
|
||||
>>> accountant.name = 'Accountant'
|
||||
>>> accountant.login = 'accountant'
|
||||
>>> accountant.password = 'accountant'
|
||||
>>> account_group, = Group.find([('name', '=', 'Account')])
|
||||
>>> accountant.groups.append(account_group)
|
||||
>>> accountant.save()
|
||||
|
||||
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], current_config.context)
|
||||
|
||||
Create chart of accounts::
|
||||
|
||||
>>> AccountTemplate = Model.get('account.account.template')
|
||||
>>> Account = Model.get('account.account')
|
||||
>>> account_template, = AccountTemplate.find([('parent', '=', False)])
|
||||
>>> 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')
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> supplier = Party(name='Supplier')
|
||||
>>> supplier.save()
|
||||
>>> customer = Party(name='Customer')
|
||||
>>> customer.save()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
>>> Product = Model.get('product.product')
|
||||
>>> product = Product()
|
||||
>>> product.name = 'product'
|
||||
>>> product.default_uom = unit
|
||||
>>> product.type = 'goods'
|
||||
>>> product.purchasable = True
|
||||
>>> product.salable = True
|
||||
>>> product.list_price = Decimal('10')
|
||||
>>> product.cost_price = Decimal('5')
|
||||
>>> product.cost_price_method = 'fixed'
|
||||
>>> product.account_expense = expense
|
||||
>>> product.account_revenue = revenue
|
||||
>>> product.save()
|
||||
|
||||
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.save()
|
||||
|
||||
Purchase 5 products::
|
||||
|
||||
>>> Purchase = Model.get('purchase.purchase')
|
||||
>>> PurchaseLine = Model.get('purchase.line')
|
||||
>>> purchase = Purchase()
|
||||
>>> purchase.party = supplier
|
||||
>>> purchase.payment_term = payment_term
|
||||
>>> purchase.invoice_method = 'order'
|
||||
>>> purchase_line = PurchaseLine()
|
||||
>>> purchase.lines.append(purchase_line)
|
||||
>>> purchase_line.product = product
|
||||
>>> purchase_line.quantity = 2.0
|
||||
>>> purchase_line = PurchaseLine()
|
||||
>>> purchase.lines.append(purchase_line)
|
||||
>>> purchase_line.product = product
|
||||
>>> purchase_line.quantity = 3.0
|
||||
>>> purchase_line = PurchaseLine()
|
||||
>>> purchase.lines.append(purchase_line)
|
||||
>>> purchase_line.product = product
|
||||
>>> purchase_line.quantity = 4.0
|
||||
>>> purchase.save()
|
||||
>>> Purchase.quote([purchase.id], current_config.context)
|
||||
>>> Purchase.confirm([purchase.id], current_config.context)
|
||||
>>> purchase.state
|
||||
u'confirmed'
|
||||
>>> purchase.reload()
|
||||
>>> len(purchase.moves)
|
||||
3
|
||||
>>> len(purchase.shipment_returns)
|
||||
0
|
||||
>>> len(purchase.invoices)
|
||||
0
|
||||
|
||||
|
||||
Create a supplier invoice::
|
||||
|
||||
>>> Invoice = Model.get('account.invoice')
|
||||
>>> invoice = Invoice()
|
||||
>>> invoice.type = 'in_invoice'
|
||||
>>> invoice.party = supplier
|
||||
>>> len(invoice.lines.find())
|
||||
3
|
||||
>>> line1 = invoice.lines.find()[0]
|
||||
>>> invoice.lines.append(line1)
|
||||
>>> invoice.save()
|
||||
|
||||
Create a supplier invoice with an accountant::
|
||||
|
||||
>>> current_config = config.set_trytond(user='accountant',
|
||||
... password='accountant', database_name=current_config.database_name)
|
||||
>>> Invoice = Model.get('account.invoice')
|
||||
>>> Partner = Model.get('party.party')
|
||||
>>> supplier, = Partner.find([('name', '=', 'Supplier')])
|
||||
|
||||
>>> invoice = Invoice()
|
||||
>>> invoice.type = 'in_invoice'
|
||||
>>> invoice.party = supplier
|
||||
>>> len(invoice.lines.find())
|
||||
2
|
||||
>>> _ = [invoice.lines.append(l) for l in invoice.lines.find()]
|
||||
>>> invoice.save()
|
||||
|
||||
>>> _ = invoice.lines.pop()
|
||||
>>> invoice.save()
|
||||
@@ -10,8 +10,10 @@ if os.path.isdir(DIR):
|
||||
sys.path.insert(0, os.path.dirname(DIR))
|
||||
|
||||
import unittest
|
||||
import doctest
|
||||
import trytond.tests.test_tryton
|
||||
from trytond.tests.test_tryton import test_view, test_depends
|
||||
from trytond.backend.sqlite.database import Database as SQLiteDatabase
|
||||
|
||||
|
||||
class PurchaseInvoiceLineStandaloneTestCase(unittest.TestCase):
|
||||
@@ -36,10 +38,24 @@ class PurchaseInvoiceLineStandaloneTestCase(unittest.TestCase):
|
||||
test_depends()
|
||||
|
||||
|
||||
def doctest_dropdb(test):
|
||||
database = SQLiteDatabase().connect()
|
||||
cursor = database.cursor(autocommit=True)
|
||||
try:
|
||||
database.drop(cursor, ':memory:')
|
||||
cursor.commit()
|
||||
finally:
|
||||
cursor.close()
|
||||
|
||||
|
||||
def suite():
|
||||
suite = trytond.tests.test_tryton.suite()
|
||||
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
|
||||
PurchaseInvoiceLineStandaloneTestCase))
|
||||
suite.addTests(doctest.DocFileSuite(
|
||||
'scenario_purchase_invoice_line_standalone.rst',
|
||||
setUp=doctest_dropdb, tearDown=doctest_dropdb, encoding='UTF-8',
|
||||
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
|
||||
return suite
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in new issue
Block a user