diff --git a/tests/scenario_stock_supply_forecast.rst b/tests/scenario_stock_supply_forecast.rst new file mode 100644 index 0000000000..d9d4084fc4 --- /dev/null +++ b/tests/scenario_stock_supply_forecast.rst @@ -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 --git a/tests/test_stock_supply_forecast.py b/tests/test_stock_supply_forecast.py index 45de8a9b8e..7b5c7f3c33 100644 --- a/tests/test_stock_supply_forecast.py +++ b/tests/test_stock_supply_forecast.py @@ -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 @@ def suite(): 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