first commit
This commit is contained in:
2
modules/stock_supply_production/tests/__init__.py
Normal file
2
modules/stock_supply_production/tests/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,149 @@
|
||||
===========================
|
||||
Production Request Scenario
|
||||
===========================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> from trytond.modules.company.tests.tools import create_company
|
||||
>>> from trytond.modules.stock.exceptions import MoveFutureWarning
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
>>> today = dt.date.today()
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('stock_supply_production', create_company)
|
||||
|
||||
>>> Warning = Model.get('res.user.warning')
|
||||
|
||||
Create product::
|
||||
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'product'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.producible = True
|
||||
>>> template.list_price = Decimal(30)
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Define a supply period for production::
|
||||
|
||||
>>> ProductionConfiguration = Model.get('production.configuration')
|
||||
>>> production_configuration = ProductionConfiguration(1)
|
||||
>>> production_configuration.supply_period = dt.timedelta(days=30)
|
||||
>>> production_configuration.save()
|
||||
|
||||
Get stock locations::
|
||||
|
||||
>>> Location = Model.get('stock.location')
|
||||
>>> warehouse_loc, = Location.find([('code', '=', 'WH')])
|
||||
>>> storage_loc, = Location.find([('code', '=', 'STO')])
|
||||
>>> lost_loc, = Location.find([('type', '=', 'lost_found')])
|
||||
|
||||
Create needs for product::
|
||||
|
||||
>>> Move = Model.get('stock.move')
|
||||
>>> move = Move()
|
||||
>>> move.product = product
|
||||
>>> move.quantity = 1
|
||||
>>> move.from_location = storage_loc
|
||||
>>> move.to_location = lost_loc
|
||||
>>> move.click('do')
|
||||
>>> move.state
|
||||
'done'
|
||||
|
||||
>>> move, = move.duplicate(
|
||||
... default={'effective_date': today + dt.timedelta(days=10)})
|
||||
>>> try:
|
||||
... move.click('do')
|
||||
... except MoveFutureWarning as warning:
|
||||
... Warning(user=config.user, name=warning.name).save()
|
||||
>>> move.click('do')
|
||||
|
||||
There is no production request::
|
||||
|
||||
>>> Production = Model.get('production')
|
||||
>>> Production.find([])
|
||||
[]
|
||||
|
||||
Create production request::
|
||||
|
||||
>>> create_pr = Wizard('stock.supply')
|
||||
>>> create_pr.execute('create_')
|
||||
|
||||
There is now a production request::
|
||||
|
||||
>>> productions = Production.find([])
|
||||
>>> len(productions)
|
||||
2
|
||||
>>> {p.state for p in productions}
|
||||
{'request'}
|
||||
>>> for production in productions:
|
||||
... assertEqual(production.product, product)
|
||||
>>> sum(p.quantity for p in productions)
|
||||
2.0
|
||||
>>> assertEqual(sorted(p.planned_date for p in productions),
|
||||
... [today, today + dt.timedelta(days=9)])
|
||||
|
||||
Create an order point negative minimal quantity::
|
||||
|
||||
>>> OrderPoint = Model.get('stock.order_point')
|
||||
>>> order_point = OrderPoint()
|
||||
>>> order_point.type = 'production'
|
||||
>>> order_point.product = product
|
||||
>>> order_point.location = warehouse_loc
|
||||
>>> order_point.min_quantity = -2
|
||||
>>> order_point.target_quantity = 10
|
||||
>>> order_point.save()
|
||||
|
||||
Create production request::
|
||||
|
||||
>>> create_pr = Wizard('stock.supply')
|
||||
>>> create_pr.execute('create_')
|
||||
|
||||
There is no more production request::
|
||||
|
||||
>>> Production = Model.get('production')
|
||||
>>> Production.find([])
|
||||
[]
|
||||
|
||||
Set a minimal quantity on order point::
|
||||
|
||||
>>> order_point.min_quantity = 5
|
||||
>>> order_point.save()
|
||||
|
||||
Create production request::
|
||||
|
||||
>>> create_pr = Wizard('stock.supply')
|
||||
>>> create_pr.execute('create_')
|
||||
|
||||
There is now a production request::
|
||||
|
||||
>>> production, = Production.find([])
|
||||
>>> production.state
|
||||
'request'
|
||||
>>> assertEqual(production.product, product)
|
||||
>>> production.quantity
|
||||
11.0
|
||||
|
||||
Using zero as minimal quantity also creates a production request::
|
||||
|
||||
>>> order_point.min_quantity = 0
|
||||
>>> order_point.save()
|
||||
>>> create_pr = Wizard('stock.supply')
|
||||
>>> create_pr.execute('create_')
|
||||
>>> production, = Production.find([])
|
||||
>>> production.state
|
||||
'request'
|
||||
>>> assertEqual(production.product, product)
|
||||
>>> production.quantity
|
||||
11.0
|
||||
@@ -0,0 +1,76 @@
|
||||
====================================
|
||||
Production Request with BoM Scenario
|
||||
====================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> from trytond.modules.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('stock_supply_production', create_company)
|
||||
|
||||
>>> BoM = Model.get('production.bom')
|
||||
>>> Location = Model.get('stock.location')
|
||||
>>> Move = Model.get('stock.move')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> Production = Model.get('production')
|
||||
|
||||
Create product with a BoM::
|
||||
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
>>> box = ProductUom(name="Box", symbol="b", category=unit.category)
|
||||
>>> box.factor = 10
|
||||
>>> box.rounding = 1
|
||||
>>> box.digits = 0
|
||||
>>> box.save()
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = "product"
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.producible = True
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
>>> bom = BoM(name="Product")
|
||||
>>> output = bom.outputs.new()
|
||||
>>> output.product = product
|
||||
>>> output.quantity = 1
|
||||
>>> output.unit = box
|
||||
>>> bom.save()
|
||||
|
||||
>>> _ = product.boms.new(bom=bom)
|
||||
>>> product.save()
|
||||
|
||||
Get stock locations::
|
||||
|
||||
>>> warehouse_loc, = Location.find([('code', '=', 'WH')])
|
||||
>>> storage_loc, = Location.find([('code', '=', 'STO')])
|
||||
>>> lost_loc, = Location.find([('type', '=', 'lost_found')])
|
||||
|
||||
Create needs for product::
|
||||
|
||||
>>> move = Move()
|
||||
>>> move.product = product
|
||||
>>> move.quantity = 2
|
||||
>>> move.from_location = storage_loc
|
||||
>>> move.to_location = lost_loc
|
||||
>>> move.click('do')
|
||||
>>> move.state
|
||||
'done'
|
||||
|
||||
Create production request::
|
||||
|
||||
>>> create_pr = Wizard('stock.supply')
|
||||
>>> create_pr.execute('create_')
|
||||
|
||||
>>> production, = Production.find([])
|
||||
>>> assertEqual(production.product, product)
|
||||
>>> production.quantity
|
||||
1.0
|
||||
>>> assertEqual(production.unit, box)
|
||||
12
modules/stock_supply_production/tests/test_module.py
Normal file
12
modules/stock_supply_production/tests/test_module.py
Normal file
@@ -0,0 +1,12 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from trytond.tests.test_tryton import ModuleTestCase
|
||||
|
||||
|
||||
class StockSupplyProductionTestCase(ModuleTestCase):
|
||||
'Test Stock Supply Production module'
|
||||
module = 'stock_supply_production'
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
8
modules/stock_supply_production/tests/test_scenario.py
Normal file
8
modules/stock_supply_production/tests/test_scenario.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from trytond.tests.test_tryton import load_doc_tests
|
||||
|
||||
|
||||
def load_tests(*args, **kwargs):
|
||||
return load_doc_tests(__name__, __file__, *args, **kwargs)
|
||||
Reference in New Issue
Block a user