Commit e0f2a5a8 authored by Sebastien Robin's avatar Sebastien Robin

mrp: consumption view on production orders, use getAggregatedAmountList and...

mrp: consumption view on production orders, use getAggregatedAmountList and avoid displaying unused variation

Previous code was looking to transformation and checking object inside, but now we have
getAggregatedAmountList which is able to greatly do this job.

Also, do not show stock of variations we are not consuming, it could be very disturbing.
parent a1b9d412
......@@ -4,7 +4,6 @@
movement_list = context.getMovementList()
portal = context.getPortalObject()
transformation_line_list_dict = {}
consumed_resource_list = []
resource_portal_type_list = kwargs.get("resource_portal_type")
if resource_portal_type_list is None:
......@@ -13,24 +12,21 @@ if isinstance(resource_portal_type_list, str):
resource_portal_type_list = [resource_portal_type_list]
resource_portal_type_set = set(resource_portal_type_list)
consumed_resource_set = set()
consumed_resource_and_varation_set = set()
for movement in movement_list:
transformation = movement.getSpecialiseValue()
if transformation is not None:
transformation_line_list = transformation.objectValues()
filtered_transformation_line_list = []
for transformation_line in transformation_line_list:
transformation_resource = transformation_line.getResourceValue()
if transformation_resource is not None and transformation_resource.getPortalType() in resource_portal_type_set:
filtered_transformation_line_list.append(transformation_line)
consumed_resource_list.append(transformation_resource)
transformation_line_list_dict[movement] = filtered_transformation_line_list
else:
transformation_line_list_dict[movement] = ()
amount_list = [x for x in movement.asComposedDocument().getAggregatedAmountList() \
if x.getResourceValue().getPortalType() in resource_portal_type_set]
for amount in amount_list:
consumed_resource_set.add(amount.getResourceValue())
consumed_resource_and_varation_set.add(
(amount.getResourceRelativeUrl(), amount.getVariationText()))
transformation_line_list_dict[movement] = amount_list
if not consumed_resource_list:
if not consumed_resource_set:
return ()
kwargs['resource_uid'] = [resource.getUid() for resource in consumed_resource_list]
kwargs['resource_uid'] = [resource.getUid() for resource in consumed_resource_set]
kwargs['group_by_section'] = 0
kwargs['group_by_node'] = 1
kwargs['group_by_variation'] = 1
......@@ -38,7 +34,8 @@ kwargs['section_uid'] = context.getDestinationSectionUid()
inventory_dict = {}
for inventory in portal.portal_simulation.getFutureInventoryList(*args,**kwargs):
inventory_dict[inventory.resource_relative_url,
if (inventory.resource_relative_url, inventory.variation_text) in consumed_resource_and_varation_set:
inventory_dict[inventory.resource_relative_url,
inventory.variation_text,
inventory.node_relative_url] = inventory
......@@ -73,13 +70,7 @@ for movement in movement_list:
consumption_dict[obj.getUid()] = consumption_dict.get(obj.getUid(), 0) + \
quantity * (movement.getQuantity() or 0)
# sort result_list
transformation_allowed_content_type_list = context.portal_types['Transformation'].getTypeAllowedContentTypeList()
def compare(a, b):
return cmp((consumption_dict.has_key(a.getUid()), a.portal_type in transformation_allowed_content_type_list),
(consumption_dict.has_key(b.getUid()), b.portal_type in transformation_allowed_content_type_list),
)
result_list.sort(cmp=compare, reverse=True)
result_list.sort(key=lambda x: (x.getProperty("resource_title"), "".join([y[0] for y in x.getVariationCategoryItemList()])))
context.REQUEST.set('consumption_dict', consumption_dict)
return result_list
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