Add test scenario
issue4748 review16291002
This commit is contained in:
1 parent
c33d23d697
commit
1850cdbd8a
3 files changed
+162
No files matched your search
@@ -46,6 +46,11 @@ for dep in info.get('depends', []):
|
||||
if not re.match(r'(ir|res|webdav)(\W|$)', dep):
|
||||
requires.append(get_require_version('trytond_%s' % dep))
|
||||
requires.append(get_require_version('trytond'))
|
||||
tests_require = [get_require_version('proteus')]
|
||||
dependency_links = []
|
||||
if minor_version % 2:
|
||||
# Add development index for testing with proteus
|
||||
dependency_links.append('https://trydevpi.tryton.org/')
|
||||
|
||||
setup(name=name,
|
||||
version=version,
|
||||
@@ -91,6 +96,7 @@ setup(name=name,
|
||||
],
|
||||
license='GPL-3',
|
||||
install_requires=requires,
|
||||
dependency_links=dependency_links,
|
||||
zip_safe=False,
|
||||
entry_points="""
|
||||
[trytond.modules]
|
||||
@@ -98,4 +104,5 @@ setup(name=name,
|
||||
""",
|
||||
test_suite='tests',
|
||||
test_loader='trytond.test_loader:Loader',
|
||||
tests_require=tests_require,
|
||||
)
|
||||
@@ -0,0 +1,150 @@
|
||||
========================
|
||||
Sale Price List Scenario
|
||||
========================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime
|
||||
>>> 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
|
||||
|
||||
Create database::
|
||||
|
||||
>>> config = config.set_trytond()
|
||||
>>> config.pool.test = True
|
||||
|
||||
Install sale::
|
||||
|
||||
>>> Module = Model.get('ir.module.module')
|
||||
>>> module, = Module.find([('name', '=', 'sale_price_list')])
|
||||
>>> module.click('install')
|
||||
>>> Wizard('ir.module.module.install_upgrade').execute('upgrade')
|
||||
|
||||
Create company::
|
||||
|
||||
>>> _ = create_company()
|
||||
>>> company = get_company()
|
||||
|
||||
Reload the context::
|
||||
|
||||
>>> User = Model.get('res.user')
|
||||
>>> Group = Model.get('res.group')
|
||||
>>> config._context = User.get_preferences(True, config.context)
|
||||
|
||||
Create sale user::
|
||||
|
||||
>>> sale_user = User()
|
||||
>>> sale_user.name = 'Sale'
|
||||
>>> sale_user.login = 'sale'
|
||||
>>> sale_user.main_company = company
|
||||
>>> sale_group, = Group.find([('name', '=', 'Sales')])
|
||||
>>> sale_user.groups.append(sale_group)
|
||||
>>> sale_user.save()
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
||||
... create_fiscalyear(company))
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Create chart of accounts::
|
||||
|
||||
>>> _ = create_chart(company)
|
||||
>>> accounts = get_accounts(company)
|
||||
>>> revenue = accounts['revenue']
|
||||
>>> expense = accounts['expense']
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> customer = Party(name='Customer')
|
||||
>>> customer.save()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> Product = Model.get('product.product')
|
||||
>>> product = Product()
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'product'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.purchasable = True
|
||||
>>> template.salable = True
|
||||
>>> template.list_price = Decimal('10')
|
||||
>>> template.cost_price = Decimal('5')
|
||||
>>> template.cost_price_method = 'fixed'
|
||||
>>> template.account_expense = expense
|
||||
>>> template.account_revenue = revenue
|
||||
>>> template.save()
|
||||
>>> product.template = template
|
||||
>>> product.save()
|
||||
|
||||
>>> service = Product()
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'service'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'service'
|
||||
>>> template.salable = True
|
||||
>>> template.list_price = Decimal('30')
|
||||
>>> template.cost_price = Decimal('10')
|
||||
>>> template.cost_price_method = 'fixed'
|
||||
>>> template.account_expense = expense
|
||||
>>> template.account_revenue = revenue
|
||||
>>> template.save()
|
||||
>>> service.template = template
|
||||
>>> service.save()
|
||||
|
||||
Create payment term::
|
||||
|
||||
>>> payment_term = create_payment_term()
|
||||
>>> payment_term.save()
|
||||
|
||||
Create a price List and assign it to customer::
|
||||
|
||||
>>> PriceList = Model.get('product.price_list')
|
||||
>>> price_list = PriceList(name='Retail')
|
||||
>>> price_list_line = price_list.lines.new()
|
||||
>>> price_list_line.quantity = 10.0
|
||||
>>> price_list_line.product = product
|
||||
>>> price_list_line.formula = 'unit_price * 0.7'
|
||||
>>> price_list_line = price_list.lines.new()
|
||||
>>> price_list_line.product = product
|
||||
>>> price_list_line.formula = 'unit_price * 0.8'
|
||||
>>> price_list_line = price_list.lines.new()
|
||||
>>> price_list_line.formula = 'unit_price * 0.5'
|
||||
>>> price_list.save()
|
||||
>>> customer.sale_price_list = price_list
|
||||
>>> customer.save()
|
||||
|
||||
Use the price list on sale::
|
||||
|
||||
>>> config.user = sale_user.id
|
||||
>>> Sale = Model.get('sale.sale')
|
||||
>>> sale = Sale()
|
||||
>>> sale.party = customer
|
||||
>>> sale.price_list == price_list
|
||||
True
|
||||
>>> sale.payment_term = payment_term
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product
|
||||
>>> sale_line.unit_price
|
||||
Decimal('8.0000')
|
||||
>>> sale_line.quantity = 12.0
|
||||
>>> sale_line.unit_price
|
||||
Decimal('7.0000')
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = service
|
||||
>>> sale_line.unit_price
|
||||
Decimal('15.0000')
|
||||
>>> sale_line.quantity = 2.0
|
||||
>>> sale_line.unit_price
|
||||
Decimal('15.0000')
|
||||
@@ -1,8 +1,10 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
import unittest
|
||||
import doctest
|
||||
import trytond.tests.test_tryton
|
||||
from trytond.tests.test_tryton import ModuleTestCase
|
||||
from trytond.tests.test_tryton import doctest_setup, doctest_teardown
|
||||
|
||||
|
||||
class SalePriceListTestCase(ModuleTestCase):
|
||||
@@ -14,4 +16,7 @@ def suite():
|
||||
suite = trytond.tests.test_tryton.suite()
|
||||
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
|
||||
SalePriceListTestCase))
|
||||
suite.addTests(doctest.DocFileSuite('scenario_sale_price_list.rst',
|
||||
setUp=doctest_setup, tearDown=doctest_teardown, encoding='utf-8',
|
||||
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
|
||||
return suite
|
||||
Reference in new issue
Block a user