changeset d7602b8f3ce5 in modules/stock_supply_forecast:default details: https://hg.tryton.org/modules/stock_supply_forecast?cmd=changeset;node=d7602b8f3ce5 description: Add test scenario
issue8404 review277401005 diffstat: tests/scenario_stock_supply_forecast.rst | 101 +++++++++++++++++++++++++++++++ tests/test_stock_supply_forecast.py | 7 ++ 2 files changed, 108 insertions(+), 0 deletions(-) diffs (129 lines): diff -r f2782f6e0ec9 -r d7602b8f3ce5 tests/scenario_stock_supply_forecast.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/scenario_stock_supply_forecast.rst Thu Jun 06 19:19:03 2019 +0200 @@ -0,0 +1,101 @@ +============================== +Stock Supply Forecast Scenario +============================== + +Imports:: + + >>> import datetime + >>> from dateutil.relativedelta import relativedelta + >>> from decimal import Decimal + >>> from proteus import Model, Wizard + >>> from trytond.tests.tools import activate_modules + >>> from trytond.modules.company.tests.tools import create_company, \ + ... get_company + >>> from trytond.modules.account.tests.tools import (create_chart, + ... get_accounts) + >>> today = datetime.date.today() + >>> yesterday = today - relativedelta(days=1) + >>> tomorrow = today + relativedelta(days=1) + +Install stock_supply Module:: + + >>> config = activate_modules('stock_supply_forecast') + +Create company:: + + >>> _ = create_company() + >>> company = get_company() + +Create chart of accounts:: + + >>> _ = create_chart(company) + >>> accounts = get_accounts(company) + >>> expense = accounts['expense'] + +Create parties:: + + >>> Party = Model.get('party.party') + >>> customer = Party(name='Customer') + >>> customer.save() + >>> supplier = Party(name='Supplier') + >>> supplier.save() + +Create account category:: + + >>> ProductCategory = Model.get('product.category') + >>> account_category = ProductCategory(name="Account Category") + >>> account_category.accounting = True + >>> account_category.account_expense = expense + >>> account_category.save() + +Create product:: + + >>> ProductUom = Model.get('product.uom') + >>> ProductTemplate = Model.get('product.template') + >>> unit, = ProductUom.find([('name', '=', 'Unit')]) + + >>> template = ProductTemplate() + >>> template.name = 'Product' + >>> template.default_uom = unit + >>> template.type = 'goods' + >>> template.list_price = Decimal('20') + >>> template.purchasable = True + >>> template.account_category = account_category + >>> template.save() + >>> product, = template.products + +Get warehouse location:: + + >>> Location = Model.get('stock.location') + >>> warehouse_loc, = Location.find([('code', '=', 'WH')]) + +Create a forecast:: + + >>> Forecast = Model.get('stock.forecast') + >>> forecast = Forecast() + >>> forecast.warehouse = warehouse_loc + >>> forecast.from_date = yesterday + >>> forecast.to_date = tomorrow + >>> forecast_line = forecast.lines.new() + >>> forecast_line.product = product + >>> forecast_line.quantity = 10 + >>> forecast.save() + +There is no purchase request:: + + >>> create_pr = Wizard('stock.supply') + >>> create_pr.execute('create_') + >>> PurchaseRequest = Model.get('purchase.request') + >>> PurchaseRequest.find([]) + [] + +There is a draft purchase request after confirming the forecast:: + + >>> forecast.click('confirm') + >>> create_pr = Wizard('stock.supply') + >>> create_pr.execute('create_') + >>> pr, = PurchaseRequest.find([('state', '=', 'draft')]) + >>> pr.product == product + True + >>> pr.quantity + 5.0 diff -r f2782f6e0ec9 -r d7602b8f3ce5 tests/test_stock_supply_forecast.py --- a/tests/test_stock_supply_forecast.py Mon May 06 15:17:59 2019 +0200 +++ b/tests/test_stock_supply_forecast.py Thu Jun 06 19:19:03 2019 +0200 @@ -1,8 +1,11 @@ # 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_teardown +from trytond.tests.test_tryton import doctest_checker class StockSupplyForecastTestCase(ModuleTestCase): @@ -14,4 +17,8 @@ suite = trytond.tests.test_tryton.suite() suite.addTests(unittest.TestLoader().loadTestsFromTestCase( StockSupplyForecastTestCase)) + suite.addTests(doctest.DocFileSuite('scenario_stock_supply_forecast.rst', + tearDown=doctest_teardown, encoding='utf-8', + checker=doctest_checker, + optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) return suite