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):
getattr(delivery_module, delivery_module_before_building_script_id)()
def generateMovementListForStockOptimisation(self, **kw):
# XXX: unused
from Products.ERP5Type.Document import newTempMovement
movement_list = []
for attribute, method in [('node_uid', 'getDestinationUid'),
......@@ -185,42 +184,39 @@ class BuilderMixin(XMLObject, Amount, Predicate):
**kw)
id_count = 0
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):
dumb_movement = inventory_item.getObject()
# Create temporary movement
movement = newTempMovement(self.getPortalObject(),
str(id_count))
id_count += 1
resource_portal_type = self.getResourcePortalType()
movement.edit(
resource=inventory_item.resource_relative_url,
variation_category_list=dumb_movement.getVariationCategoryList(),
destination_value=self.getDestinationValue(),
resource_portal_type=resource_portal_type,
destination_section_value=self.getDestinationSectionValue())
# We can do other test on inventory here
# XXX It is better if it can be sql parameters
resource_portal_type = self.getResourcePortalType()
#resource_portal_type = self.getResourcePortalType()
resource = movement.getResourceValue()
# FIXME: XXX Those properties are defined on a supply line !!
# min_flow, max_delay
min_flow = resource.getMinFlow(0)
if (resource.getPortalType() == resource_portal_type) and\
(round(inventory_item.inventory, 5) < min_flow):
# FIXME XXX getNextNegativeInventoryDate must work
stop_date = DateTime()+10
# stop_date = resource.getNextNegativeInventoryDate(
# variation_text=movement.getVariationText(),
# from_date=DateTime(),
# # node_category=node_category,
# # section_category=section_category)
# node_uid=self.getDestinationUid(),
# section_uid=self.getDestinationSectionUid())
assert resource.getPortalType() == resource_portal_type
if round(inventory_item.inventory, 5) < min_flow:
stop_date = resource.getNextNegativeInventoryDate(
variation_text=movement.getVariationText(),
from_date=DateTime(),
**kw)
if stop_date is None:
stop_date = DateTime()
max_delay = resource.getMaxDelay(0)
movement.edit(
start_date=DateTime(((stop_date-max_delay).Date())),
stop_date=DateTime(stop_date.Date()),
quantity=min_flow-inventory_item.inventory,
quantity=max(min_flow, -inventory_item.inventory),
quantity_unit=resource.getQuantityUnit()
# XXX FIXME define on a supply line
# quantity_unit
......@@ -234,7 +230,7 @@ class BuilderMixin(XMLObject, Amount, Predicate):
simulation movements) to construct a new delivery.
"""
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_set = set()
......
......@@ -55,8 +55,14 @@ class TestOrderBuilderMixin(TestOrderMixin):
# defaults
decrease_quantity = 1.0
max_delay = 0.0
min_flow = 0.0
max_delay = 4.0
min_flow = 7.0
def afterSetUp(self):
"""
Make sure to not use special apparel setting from TestOrderMixin
"""
self.createCategories()
def stepSetMaxDelayOnResource(self, sequence):
"""
......@@ -78,6 +84,7 @@ class TestOrderBuilderMixin(TestOrderMixin):
"""
order_builder = sequence.get('order_builder')
organisation = sequence.get('organisation')
resource = sequence.get('resource')
order_builder.edit(
delivery_module = self.order_module,
......@@ -86,8 +93,8 @@ class TestOrderBuilderMixin(TestOrderMixin):
delivery_cell_portal_type = self.order_cell_portal_type,
destination_value = organisation,
resource_portal_type = self.resource_portal_type,
simulation_select_method_id='generateMovementListForStockOptimisation',
)
order_builder.newContent(
portal_type = 'Category Movement Group',
collect_order_group='delivery',
......@@ -162,7 +169,7 @@ class TestOrderBuilderMixin(TestOrderMixin):
# XXX: ... and for more lines/cells too
order_line, = order.contentValues(portal_type=self.order_line_portal_type)
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):
"""
......@@ -197,7 +204,8 @@ class TestOrderBuilderMixin(TestOrderMixin):
packing_list = packing_list_module.newContent(
portal_type = self.packing_list_portal_type,
source_value = organisation,
start_date = self.datetime
start_date = self.datetime,
specialise = self.business_process,
)
packing_list_line = packing_list.newContent(
......@@ -243,7 +251,8 @@ class TestOrderBuilderMixin(TestOrderMixin):
packing_list = packing_list_module.newContent(
portal_type = self.packing_list_portal_type,
source_value = organisation,
start_date = self.datetime
start_date = self.datetime+14,
specialise = self.business_process,
)
packing_list.newContent(
......@@ -260,6 +269,8 @@ class TestOrderBuilder(TestOrderBuilderMixin, ERP5TypeTestCase):
"""
run_all_test = 1
resource_portal_type = "Product"
common_sequence_string = """
CreateOrganisation
CreateNotVariatedResource
......@@ -279,7 +290,6 @@ class TestOrderBuilder(TestOrderBuilderMixin, ERP5TypeTestCase):
def getTitle(self):
return "Order Builder"
@newSimulationExpectedFailure
def test_01_simpleOrderBuilder(self, quiet=0, run=run_all_test):
"""
Test simple Order Builder
......@@ -291,7 +301,8 @@ class TestOrderBuilder(TestOrderBuilderMixin, ERP5TypeTestCase):
str(self.datetime.earliestTime()
+ 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.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