diff --git a/setup.py b/setup.py index 043d32be9a..6d3acc3df8 100644 --- a/setup.py +++ b/setup.py @@ -125,5 +125,6 @@ setup(name=name, convert_2to3_doctests=[ 'tests/scenario_stock_supply_purchase_request.rst', 'tests/scenario_stock_internal_supply.rst', + 'tests/scenario_stock_internal_supply_lead_time.rst', ], ) diff --git a/tests/scenario_stock_internal_supply_lead_time.rst b/tests/scenario_stock_internal_supply_lead_time.rst new file mode 100644 index 0000000000..21756d233b --- /dev/null +++ b/tests/scenario_stock_internal_supply_lead_time.rst @@ -0,0 +1,145 @@ +======================================== +Stock Internal Supply Lead Time 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 + >>> today = datetime.date.today() + >>> tomorrow = today + relativedelta(days=1) + +Install stock_supply Module:: + + >>> config = activate_modules('stock_supply') + +Create customer:: + + >>> Party = Model.get('party.party') + >>> customer = Party(name='Customer') + >>> customer.save() + +Create company:: + + >>> _ = create_company() + >>> company = get_company() + +Create product:: + + >>> ProductUom = Model.get('product.uom') + >>> ProductTemplate = Model.get('product.template') + >>> Product = Model.get('product.product') + >>> unit, = ProductUom.find([('name', '=', 'Unit')]) + >>> product = Product() + >>> template = ProductTemplate() + >>> template.name = 'Product' + >>> template.default_uom = unit + >>> template.type = 'goods' + >>> template.list_price = Decimal('20') + >>> template.cost_price = Decimal('8') + >>> template.save() + >>> product.template = template + >>> product.save() + +Get stock locations:: + + >>> Location = Model.get('stock.location') + >>> warehouse_loc, = Location.find([('code', '=', 'WH')]) + >>> supplier_loc, = Location.find([('code', '=', 'SUP')]) + >>> customer_loc, = Location.find([('code', '=', 'CUS')]) + >>> lost_loc, = Location.find([('type', '=', 'lost_found')]) + +Create second warehouse:: + + >>> sec_warehouse_loc, = warehouse_loc.duplicate() + +Add lead time between warehouses:: + + >>> LeadTime = Model.get('stock.location.lead_time') + >>> lead_time = LeadTime() + >>> lead_time.warehouse_from = warehouse_loc + >>> lead_time.warehouse_to = sec_warehouse_loc + >>> lead_time.lead_time = datetime.timedelta(1) + >>> lead_time.save() + +Create internal order point:: + + >>> OrderPoint = Model.get('stock.order_point') + >>> order_point = OrderPoint() + >>> order_point.product = product + >>> order_point.storage_location = sec_warehouse_loc.storage_location + >>> order_point.provisioning_location = warehouse_loc.storage_location + >>> order_point.type = 'internal' + >>> order_point.min_quantity = 10 + >>> order_point.max_quantity = 15 + >>> order_point.save() + +Create inventory to add enough quantity in first warehouse:: + + >>> Inventory = Model.get('stock.inventory') + >>> inventory = Inventory() + >>> inventory.location = warehouse_loc.storage_location + >>> inventory_line = inventory.lines.new(product=product) + >>> inventory_line.quantity = 100.0 + >>> inventory_line.expected_quantity = 0.0 + >>> inventory.click('confirm') + >>> inventory.state + u'done' + +Create needs for tomorrow in second warehouse:: + + >>> ShipmentOut = Model.get('stock.shipment.out') + >>> shipment = ShipmentOut() + >>> shipment.planned_date = tomorrow + >>> shipment.customer = customer + >>> shipment.warehouse = sec_warehouse_loc + >>> move = shipment.outgoing_moves.new() + >>> move.product = product + >>> move.quantity = 10 + >>> move.from_location = sec_warehouse_loc.output_location + >>> move.to_location = customer_loc + >>> shipment.click('wait') + >>> shipment.state + u'waiting' + +Execute internal supply:: + + >>> ShipmentInternal = Model.get('stock.shipment.internal') + >>> Wizard('stock.supply').execute('create_') + >>> shipments = ShipmentInternal.find([], order=[('planned_date', 'ASC')]) + >>> len(shipments) + 2 + >>> first, second = shipments + + >>> first.planned_date == today + True + >>> first.state + u'request' + >>> len(first.moves) + 1 + >>> move, = first.moves + >>> move.from_location == warehouse_loc.storage_location + True + >>> move.to_location == sec_warehouse_loc.storage_location + True + >>> move.quantity + 15.0 + + >>> second.planned_date == tomorrow + True + >>> second.state + u'request' + >>> len(second.moves) + 1 + >>> move, = second.moves + >>> move.from_location == warehouse_loc.storage_location + True + >>> move.to_location == sec_warehouse_loc.storage_location + True + >>> move.quantity + 10.0 diff --git a/tests/test_stock_supply.py b/tests/test_stock_supply.py index 211a8ed998..491ba4dd6b 100644 --- a/tests/test_stock_supply.py +++ b/tests/test_stock_supply.py @@ -128,6 +128,11 @@ def suite(): tearDown=doctest_teardown, encoding='utf-8', checker=doctest_checker, optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) + suite.addTests(doctest.DocFileSuite( + 'scenario_stock_internal_supply_lead_time.rst', + tearDown=doctest_teardown, encoding='utf-8', + checker=doctest_checker, + optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) suite.addTests(doctest.DocFileSuite( 'scenario_stock_supply_purchase_request.rst', tearDown=doctest_teardown, encoding='utf-8',