first commit
This commit is contained in:
2
modules/stock_quantity_early_planning/tests/__init__.py
Normal file
2
modules/stock_quantity_early_planning/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,156 @@
|
||||
======================================
|
||||
Stock Quantity Early Planning 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.currency.tests.tools import get_currency
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
>>> today = dt.date.today()
|
||||
>>> week1 = today + dt.timedelta(weeks=1)
|
||||
>>> week2 = today + dt.timedelta(weeks=2)
|
||||
>>> week3 = today + dt.timedelta(weeks=3)
|
||||
>>> week4 = today + dt.timedelta(weeks=4)
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('stock_quantity_early_planning', create_company)
|
||||
|
||||
>>> Location = Model.get('stock.location')
|
||||
>>> Move = Model.get('stock.move')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> Product = Model.get('product.product')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> QuantityEarlyPlan = Model.get('stock.quantity.early_plan')
|
||||
>>> ShipmentOut = Model.get('stock.shipment.out')
|
||||
|
||||
Get currency::
|
||||
|
||||
>>> currency = get_currency()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> customer = Party(name="Customer")
|
||||
>>> customer.save()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = "Product"
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.list_price = Decimal('20')
|
||||
>>> product, = template.products
|
||||
>>> product.cost_price = Decimal('5')
|
||||
>>> _ = template.products.new(cost_price=Decimal('5'))
|
||||
>>> template.save()
|
||||
>>> product1, product2 = template.products
|
||||
|
||||
Get stock locations::
|
||||
|
||||
>>> supplier_loc, = Location.find([('code', '=', 'SUP')])
|
||||
>>> customer_loc, = Location.find([('code', '=', 'CUS')])
|
||||
>>> input_loc, = Location.find([('code', '=', 'IN')])
|
||||
>>> output_loc, = Location.find([('code', '=', 'OUT')])
|
||||
|
||||
Plan receiving some products tomorrow and in 2 week::
|
||||
|
||||
>>> def fill(quantity, product, date):
|
||||
... move = Move()
|
||||
... move.product = product
|
||||
... move.quantity = quantity
|
||||
... move.from_location = supplier_loc
|
||||
... move.to_location = input_loc
|
||||
... move.unit_price = product.cost_price
|
||||
... move.currency = currency
|
||||
... move.planned_date = date
|
||||
... move.save()
|
||||
|
||||
>>> fill(5, product1, today)
|
||||
>>> fill(10, product1, week2)
|
||||
>>> fill(5, product1, week4)
|
||||
>>> fill(5, product2, week1)
|
||||
>>> fill(5, product2, week2)
|
||||
|
||||
Plan to ship some products in 3 weeks::
|
||||
|
||||
>>> shipment_out1 = ShipmentOut()
|
||||
>>> shipment_out1.planned_date = week3
|
||||
>>> shipment_out1.customer = customer
|
||||
>>> move = shipment_out1.outgoing_moves.new()
|
||||
>>> move.product = product1
|
||||
>>> move.quantity = 4
|
||||
>>> move.from_location = output_loc
|
||||
>>> move.to_location = customer_loc
|
||||
>>> move.unit_price = product1.list_price_used
|
||||
>>> move.currency = currency
|
||||
>>> move = shipment_out1.outgoing_moves.new()
|
||||
>>> move.product = product2
|
||||
>>> move.quantity = 6
|
||||
>>> move.from_location = output_loc
|
||||
>>> move.to_location = customer_loc
|
||||
>>> move.unit_price = product2.list_price_used
|
||||
>>> move.currency = currency
|
||||
>>> shipment_out1.save()
|
||||
|
||||
>>> shipment_out2 = ShipmentOut()
|
||||
>>> shipment_out2.planned_date = week3
|
||||
>>> shipment_out2.customer = customer
|
||||
>>> move = shipment_out2.outgoing_moves.new()
|
||||
>>> move.product = product1
|
||||
>>> move.quantity = 8
|
||||
>>> move.from_location = output_loc
|
||||
>>> move.to_location = customer_loc
|
||||
>>> move.unit_price = product1.list_price_used
|
||||
>>> move.currency = currency
|
||||
>>> shipment_out2.save()
|
||||
|
||||
>>> shipment_out3 = ShipmentOut()
|
||||
>>> shipment_out3.planned_date = week4
|
||||
>>> shipment_out3.customer = customer
|
||||
>>> move = shipment_out3.outgoing_moves.new()
|
||||
>>> move.product = product1
|
||||
>>> move.quantity = 4
|
||||
>>> move.from_location = output_loc
|
||||
>>> move.to_location = customer_loc
|
||||
>>> move.unit_price = product1.list_price_used
|
||||
>>> move.currency = currency
|
||||
>>> shipment_out3.save()
|
||||
|
||||
>>> ShipmentOut.click([shipment_out1, shipment_out2, shipment_out3], 'wait')
|
||||
|
||||
Generate early planning::
|
||||
|
||||
>>> generate_planning = Wizard('stock.quantity.early_plan.generate')
|
||||
>>> generate_planning.execute('generate')
|
||||
|
||||
Check early planning::
|
||||
|
||||
>>> plan1, = QuantityEarlyPlan.find(
|
||||
... [('origin', '=', str(shipment_out1))])
|
||||
>>> assertEqual(plan1.earlier_date, week2)
|
||||
>>> assertEqual(plan1.earliest_date, today)
|
||||
>>> plan1.earliest_percentage
|
||||
0.4
|
||||
|
||||
>>> plan2, = QuantityEarlyPlan.find(
|
||||
... [('origin', '=', str(shipment_out2))])
|
||||
>>> assertEqual(plan2.earlier_date, week2)
|
||||
>>> assertEqual(plan2.earliest_date, week2)
|
||||
>>> plan2.earliest_percentage
|
||||
1.0
|
||||
|
||||
>>> plan3, = QuantityEarlyPlan.find(
|
||||
... [('origin', '=', str(shipment_out3))])
|
||||
>>> assertEqual(plan3.earlier_date, week4)
|
||||
>>> assertEqual(plan3.earliest_date, today)
|
||||
>>> plan3.earliest_percentage
|
||||
0.75
|
||||
@@ -0,0 +1,143 @@
|
||||
===============================================
|
||||
Stock Quantity Early Planning Incoming 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.currency.tests.tools import get_currency
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
>>> today = dt.date.today()
|
||||
>>> week1 = today + dt.timedelta(weeks=1)
|
||||
>>> week2 = today + dt.timedelta(weeks=2)
|
||||
>>> week3 = today + dt.timedelta(weeks=3)
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('stock_quantity_early_planning', create_company)
|
||||
|
||||
>>> Company = Model.get('company.company')
|
||||
>>> Location = Model.get('stock.location')
|
||||
>>> Move = Model.get('stock.move')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> Product = Model.get('product.product')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> QuantityEarlyPlan = Model.get('stock.quantity.early_plan')
|
||||
>>> ShipmentOut = Model.get('stock.shipment.out')
|
||||
>>> ShipmentInternal = Model.get('stock.shipment.internal')
|
||||
|
||||
Get currency::
|
||||
|
||||
>>> currency = get_currency()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> customer = Party(name="Customer")
|
||||
>>> customer.save()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = "Product"
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.list_price = Decimal('20')
|
||||
>>> product, = template.products
|
||||
>>> product.cost_price = Decimal('5')
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Get stock locations::
|
||||
|
||||
>>> supplier_loc, = Location.find([('code', '=', 'SUP')])
|
||||
>>> customer_loc, = Location.find([('code', '=', 'CUS')])
|
||||
|
||||
Duplicate warehouse::
|
||||
|
||||
>>> warehouse, = Location.find([('type', '=', 'warehouse')])
|
||||
>>> warehouse2, = warehouse.duplicate()
|
||||
|
||||
Plan receiving some products in 1 week in second warehouse::
|
||||
|
||||
>>> def fill(quantity, product, date):
|
||||
... move = Move()
|
||||
... move.product = product
|
||||
... move.quantity = quantity
|
||||
... move.from_location = supplier_loc
|
||||
... move.to_location = warehouse2.input_location
|
||||
... move.unit_price = product.cost_price
|
||||
... move.currency = currency
|
||||
... move.planned_date = date
|
||||
... move.save()
|
||||
|
||||
>>> fill(5, product, today)
|
||||
>>> fill(15, product, week1)
|
||||
|
||||
Request to ship to first warehouse in 2 and 3 weeks::
|
||||
|
||||
>>> shipment_int1 = ShipmentInternal()
|
||||
>>> shipment_int1.planned_date = week2
|
||||
>>> shipment_int1.from_location = warehouse2.storage_location
|
||||
>>> shipment_int1.to_location = warehouse.storage_location
|
||||
>>> move = shipment_int1.moves.new()
|
||||
>>> move.from_location = warehouse2.storage_location
|
||||
>>> move.to_location = warehouse.storage_location
|
||||
>>> move.product = product
|
||||
>>> move.quantity = 10
|
||||
>>> shipment_int1.save()
|
||||
>>> ShipmentInternal.write(
|
||||
... [shipment_int1.id], {'state': 'request'}, shipment_int1._context)
|
||||
|
||||
>>> shipment_int2 = ShipmentInternal()
|
||||
>>> shipment_int2.planned_date = week2
|
||||
>>> shipment_int2.from_location = warehouse2.storage_location
|
||||
>>> shipment_int2.to_location = warehouse.storage_location
|
||||
>>> move = shipment_int2.moves.new()
|
||||
>>> move.from_location = warehouse2.storage_location
|
||||
>>> move.to_location = warehouse.storage_location
|
||||
>>> move.product = product
|
||||
>>> move.quantity = 5
|
||||
>>> shipment_int2.save()
|
||||
>>> ShipmentInternal.write(
|
||||
... [shipment_int2.id], {'state': 'request'}, shipment_int2._context)
|
||||
|
||||
Plan to ship in 3 weeks::
|
||||
|
||||
>>> shipment_out = ShipmentOut(warehouse=warehouse)
|
||||
>>> shipment_out.planned_date = week3
|
||||
>>> shipment_out.customer = customer
|
||||
>>> move = shipment_out.outgoing_moves.new()
|
||||
>>> move.product = product
|
||||
>>> move.quantity = 7
|
||||
>>> move.from_location = warehouse.output_location
|
||||
>>> move.to_location = customer_loc
|
||||
>>> move.unit_price = product.list_price_used
|
||||
>>> move.currency = currency
|
||||
>>> shipment_out.save()
|
||||
>>> shipment_out.click('wait')
|
||||
|
||||
Generate early planning::
|
||||
|
||||
>>> generate_planning = Wizard('stock.quantity.early_plan.generate')
|
||||
>>> generate_planning.execute('generate')
|
||||
|
||||
Check early planning::
|
||||
|
||||
>>> plan, = QuantityEarlyPlan.find(
|
||||
... [('origin', '=', str(shipment_int1))])
|
||||
>>> assertEqual(plan.earlier_date, week1)
|
||||
|
||||
>>> plan, = QuantityEarlyPlan.find(
|
||||
... [('origin', '=', str(shipment_int2))])
|
||||
>>> assertEqual(plan.earlier_date, today)
|
||||
|
||||
>>> plan, = QuantityEarlyPlan.find(
|
||||
... [('origin', '=', str(shipment_out))])
|
||||
>>> assertEqual(plan.earlier_date, week1)
|
||||
14
modules/stock_quantity_early_planning/tests/test_module.py
Normal file
14
modules/stock_quantity_early_planning/tests/test_module.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# 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.modules.company.tests import CompanyTestMixin
|
||||
from trytond.tests.test_tryton import ModuleTestCase
|
||||
|
||||
|
||||
class StockQuantityEarlyPlanningTestCase(CompanyTestMixin, ModuleTestCase):
|
||||
'Test Stock Quantity Early Planning module'
|
||||
module = 'stock_quantity_early_planning'
|
||||
extras = ['production']
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
@@ -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