Commit b9782cda authored by Sebastien Robin's avatar Sebastien Robin

Order Builders: make the test testOrderBuilder.test_01_simpleOrderBuilder passing again

So it's no longer a newSimulation expected failure. Review method
generateMovementListForStockOptimisation of builders to nicely
generated temporary movements depending on future negative stocks.
parent ac994956
...@@ -166,7 +166,6 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -166,7 +166,6 @@ class BuilderMixin(XMLObject, Amount, Predicate):
getattr(delivery_module, delivery_module_before_building_script_id)() getattr(delivery_module, delivery_module_before_building_script_id)()
def generateMovementListForStockOptimisation(self, **kw): def generateMovementListForStockOptimisation(self, **kw):
# XXX: unused
from Products.ERP5Type.Document import newTempMovement from Products.ERP5Type.Document import newTempMovement
movement_list = [] movement_list = []
for attribute, method in [('node_uid', 'getDestinationUid'), for attribute, method in [('node_uid', 'getDestinationUid'),
...@@ -185,42 +184,39 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -185,42 +184,39 @@ class BuilderMixin(XMLObject, Amount, Predicate):
**kw) **kw)
id_count = 0 id_count = 0
for inventory_item in sql_list: for inventory_item in sql_list:
# XXX FIXME SQL return None inventory...
# It may be better to return always good values
if (inventory_item.inventory is not None): if (inventory_item.inventory is not None):
dumb_movement = inventory_item.getObject() dumb_movement = inventory_item.getObject()
# Create temporary movement # Create temporary movement
movement = newTempMovement(self.getPortalObject(), movement = newTempMovement(self.getPortalObject(),
str(id_count)) str(id_count))
id_count += 1 id_count += 1
resource_portal_type = self.getResourcePortalType()
movement.edit( movement.edit(
resource=inventory_item.resource_relative_url, resource=inventory_item.resource_relative_url,
variation_category_list=dumb_movement.getVariationCategoryList(), variation_category_list=dumb_movement.getVariationCategoryList(),
destination_value=self.getDestinationValue(), destination_value=self.getDestinationValue(),
resource_portal_type=resource_portal_type,
destination_section_value=self.getDestinationSectionValue()) destination_section_value=self.getDestinationSectionValue())
# We can do other test on inventory here # We can do other test on inventory here
# XXX It is better if it can be sql parameters # XXX It is better if it can be sql parameters
resource_portal_type = self.getResourcePortalType() #resource_portal_type = self.getResourcePortalType()
resource = movement.getResourceValue() resource = movement.getResourceValue()
# FIXME: XXX Those properties are defined on a supply line !! # FIXME: XXX Those properties are defined on a supply line !!
# min_flow, max_delay # min_flow, max_delay
min_flow = resource.getMinFlow(0) min_flow = resource.getMinFlow(0)
if (resource.getPortalType() == resource_portal_type) and\ assert resource.getPortalType() == resource_portal_type
(round(inventory_item.inventory, 5) < min_flow): if round(inventory_item.inventory, 5) < min_flow:
# FIXME XXX getNextNegativeInventoryDate must work stop_date = resource.getNextNegativeInventoryDate(
stop_date = DateTime()+10 variation_text=movement.getVariationText(),
# stop_date = resource.getNextNegativeInventoryDate( from_date=DateTime(),
# variation_text=movement.getVariationText(), **kw)
# from_date=DateTime(), if stop_date is None:
# # node_category=node_category, stop_date = DateTime()
# # section_category=section_category)
# node_uid=self.getDestinationUid(),
# section_uid=self.getDestinationSectionUid())
max_delay = resource.getMaxDelay(0) max_delay = resource.getMaxDelay(0)
movement.edit( movement.edit(
start_date=DateTime(((stop_date-max_delay).Date())), start_date=DateTime(((stop_date-max_delay).Date())),
stop_date=DateTime(stop_date.Date()), stop_date=DateTime(stop_date.Date()),
quantity=min_flow-inventory_item.inventory, quantity=max(min_flow, -inventory_item.inventory),
quantity_unit=resource.getQuantityUnit() quantity_unit=resource.getQuantityUnit()
# XXX FIXME define on a supply line # XXX FIXME define on a supply line
# quantity_unit # quantity_unit
...@@ -234,7 +230,7 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -234,7 +230,7 @@ class BuilderMixin(XMLObject, Amount, Predicate):
simulation movements) to construct a new delivery. simulation movements) to construct a new delivery.
""" """
method_id = self.getSimulationSelectMethodId() or 'portal_catalog' method_id = self.getSimulationSelectMethodId() or 'portal_catalog'
select_method = getattr(self.getPortalObject(), method_id) select_method = getattr(self, method_id)
movement_list = [] # use list to preserve order movement_list = [] # use list to preserve order
movement_set = set() movement_set = set()
......
...@@ -55,8 +55,14 @@ class TestOrderBuilderMixin(TestOrderMixin): ...@@ -55,8 +55,14 @@ class TestOrderBuilderMixin(TestOrderMixin):
# defaults # defaults
decrease_quantity = 1.0 decrease_quantity = 1.0
max_delay = 0.0 max_delay = 4.0
min_flow = 0.0 min_flow = 7.0
def afterSetUp(self):
"""
Make sure to not use special apparel setting from TestOrderMixin
"""
self.createCategories()
def stepSetMaxDelayOnResource(self, sequence): def stepSetMaxDelayOnResource(self, sequence):
""" """
...@@ -78,6 +84,7 @@ class TestOrderBuilderMixin(TestOrderMixin): ...@@ -78,6 +84,7 @@ class TestOrderBuilderMixin(TestOrderMixin):
""" """
order_builder = sequence.get('order_builder') order_builder = sequence.get('order_builder')
organisation = sequence.get('organisation') organisation = sequence.get('organisation')
resource = sequence.get('resource')
order_builder.edit( order_builder.edit(
delivery_module = self.order_module, delivery_module = self.order_module,
...@@ -86,8 +93,8 @@ class TestOrderBuilderMixin(TestOrderMixin): ...@@ -86,8 +93,8 @@ class TestOrderBuilderMixin(TestOrderMixin):
delivery_cell_portal_type = self.order_cell_portal_type, delivery_cell_portal_type = self.order_cell_portal_type,
destination_value = organisation, destination_value = organisation,
resource_portal_type = self.resource_portal_type, resource_portal_type = self.resource_portal_type,
simulation_select_method_id='generateMovementListForStockOptimisation',
) )
order_builder.newContent( order_builder.newContent(
portal_type = 'Category Movement Group', portal_type = 'Category Movement Group',
collect_order_group='delivery', collect_order_group='delivery',
...@@ -162,7 +169,7 @@ class TestOrderBuilderMixin(TestOrderMixin): ...@@ -162,7 +169,7 @@ class TestOrderBuilderMixin(TestOrderMixin):
# XXX: ... and for more lines/cells too # XXX: ... and for more lines/cells too
order_line, = order.contentValues(portal_type=self.order_line_portal_type) order_line, = order.contentValues(portal_type=self.order_line_portal_type)
self.assertEqual(order_line.getResourceValue(), resource) self.assertEqual(order_line.getResourceValue(), resource)
self.assertEqual(order_line.getTotalQuantity(), self.wanted_quantity) self.assertEqual(order_line.getTotalQuantity(), self.min_flow)
def stepBuildOrderBuilder(self, sequence): def stepBuildOrderBuilder(self, sequence):
""" """
...@@ -197,7 +204,8 @@ class TestOrderBuilderMixin(TestOrderMixin): ...@@ -197,7 +204,8 @@ class TestOrderBuilderMixin(TestOrderMixin):
packing_list = packing_list_module.newContent( packing_list = packing_list_module.newContent(
portal_type = self.packing_list_portal_type, portal_type = self.packing_list_portal_type,
source_value = organisation, source_value = organisation,
start_date = self.datetime start_date = self.datetime,
specialise = self.business_process,
) )
packing_list_line = packing_list.newContent( packing_list_line = packing_list.newContent(
...@@ -243,7 +251,8 @@ class TestOrderBuilderMixin(TestOrderMixin): ...@@ -243,7 +251,8 @@ class TestOrderBuilderMixin(TestOrderMixin):
packing_list = packing_list_module.newContent( packing_list = packing_list_module.newContent(
portal_type = self.packing_list_portal_type, portal_type = self.packing_list_portal_type,
source_value = organisation, source_value = organisation,
start_date = self.datetime start_date = self.datetime+14,
specialise = self.business_process,
) )
packing_list.newContent( packing_list.newContent(
...@@ -260,6 +269,8 @@ class TestOrderBuilder(TestOrderBuilderMixin, ERP5TypeTestCase): ...@@ -260,6 +269,8 @@ class TestOrderBuilder(TestOrderBuilderMixin, ERP5TypeTestCase):
""" """
run_all_test = 1 run_all_test = 1
resource_portal_type = "Product"
common_sequence_string = """ common_sequence_string = """
CreateOrganisation CreateOrganisation
CreateNotVariatedResource CreateNotVariatedResource
...@@ -279,7 +290,6 @@ class TestOrderBuilder(TestOrderBuilderMixin, ERP5TypeTestCase): ...@@ -279,7 +290,6 @@ class TestOrderBuilder(TestOrderBuilderMixin, ERP5TypeTestCase):
def getTitle(self): def getTitle(self):
return "Order Builder" return "Order Builder"
@newSimulationExpectedFailure
def test_01_simpleOrderBuilder(self, quiet=0, run=run_all_test): def test_01_simpleOrderBuilder(self, quiet=0, run=run_all_test):
""" """
Test simple Order Builder Test simple Order Builder
...@@ -291,7 +301,8 @@ class TestOrderBuilder(TestOrderBuilderMixin, ERP5TypeTestCase): ...@@ -291,7 +301,8 @@ class TestOrderBuilder(TestOrderBuilderMixin, ERP5TypeTestCase):
str(self.datetime.earliestTime() str(self.datetime.earliestTime()
+ self.order_builder_hardcoded_time_diff)) + self.order_builder_hardcoded_time_diff))
self.wanted_stop_date = self.wanted_start_date # We add 4 days to start date to reflect delays
self.wanted_stop_date = self.wanted_start_date + 4
sequence_list = SequenceList() sequence_list = SequenceList()
sequence_list.addSequenceString(self.common_sequence_string) sequence_list.addSequenceString(self.common_sequence_string)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment