Commit 19a1ca78 authored by Yusei Tahara's avatar Yusei Tahara

Fix bug on production order material consumption tab.

parent be4e2d62
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>"""Returns list of resources\' inventories used in consumption for production\n
\n
Args:\n
- omit_order_resources [default: 1]\n
Do not show resources, which are on order lines.\n
"""\n
if omit_order_resources:\n
from Products.ZSQLCatalog.SQLCatalog import Query\n
from Products.ZSQLCatalog.SQLCatalog import NegatedQuery\n
\n
ignored_resource_uid_list = [q.getResourceUid() for q in context.getMovementList() if q.getResourceUid() is not None]\n
kwargs[\'query\'] = NegatedQuery(Query(operator=\'IN\',**{\'stock.resource_uid\': ignored_resource_uid_list}))\n
\n
kwargs[\'group_by_date\'] = 1\n
kwargs[\'group_by_node\'] = 1\n
kwargs[\'group_by_variation\'] = 1\n
kwargs[\'group_by_resource\'] = 1\n
kwargs[\'section_uid\'] = context.getDestinationSectionUid()\n
\n
inventory_dict = {}\n
for inventory in context.portal_simulation.getFutureInventoryList(*args,**kwargs):\n
inventory_dict[inventory.getResourceUid(), \\\n
tuple(sorted(inventory.getVariationCategoryList())), \\\n
inventory.getDestination()] = inventory\n
\n
result_list = inventory_dict.values()\n
consumption_dict = {}\n
for movement in context.getMovementList():\n
movement_quantity = movement.getQuantity()\n
movement_destination = movement.getDestination()\n
\n
transformation = movement.getSpecialiseValue()\n
if transformation is not None:\n
transformation_line_list = transformation.objectValues()\n
else:\n
transformation_line_list = ()\n
\n
for material in transformation_line_list:\n
material_resource_uid = material.getResourceUid()\n
if not material_resource_uid:\n
continue\n
\n
inventory_dict_key = material_resource_uid, \\\n
tuple(sorted(material.getVariationCategoryList())), \\\n
movement_destination\n
\n
quantity = material.getQuantity()\n
\n
try:\n
obj = inventory_dict[inventory_dict_key]\n
except KeyError:\n
obj = material\n
result_list.append(obj)\n
else:\n
inventory_quantity_unit = obj.getQuantityUnit()\n
quantity_unit = material.getQuantityUnit()\n
if quantity_unit != inventory_quantity_unit:\n
quantity = material.getResourceValue().convertQuantity(quantity,\n
quantity_unit,\n
inventory_quantity_unit)\n
\n
if quantity:\n
consumption_dict[obj.getUid()] = quantity * movement_quantity\n
\n
context.REQUEST.set(\'consumption_dict\', consumption_dict)\n
return result_list\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>omit_order_resources=1,*args,**kwargs</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ProductionOrder_getConsumptionMovementList</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -50,9 +50,71 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>"""Returns list of materials\' inventories used in consumption for production"""\n
kwargs[\'resource_portal_type\'] = context.getPortalObject().getPortalProductTypeList()\n
return context.ProductionOrder_getConsumptionMovementList(*args,**kwargs)\n
<value> <string>"""Returns list of resources\' inventories used in consumption for production\n
Show only resources which are defined in transformation.\n
"""\n
movement_list = context.getMovementList()\n
transformation_line_list_dict = {}\n
consumed_resource_list = []\n
for movement in movement_list:\n
transformation = movement.getSpecialiseValue()\n
if transformation is not None:\n
transformation_line_list = transformation.objectValues()\n
transformation_line_list_dict[movement] = transformation_line_list\n
for transformation_line in transformation_line_list:\n
transformation_resource = transformation_line.getResourceValue()\n
if transformation_resource is not None:\n
consumed_resource_list.append(transformation_resource)\n
else:\n
transformation_line_list_dict[movement] = ()\n
\n
if not consumed_resource_list:\n
return ()\n
\n
kwargs[\'resource\'] = [resource.getRelativeUrl() for resource in consumed_resource_list]\n
kwargs[\'group_by_section\'] = 0\n
kwargs[\'group_by_node\'] = 1\n
kwargs[\'group_by_variation\'] = 1\n
kwargs[\'section_uid\'] = context.getSourceSectionUid()\n
\n
inventory_dict = {}\n
for inventory in context.portal_simulation.getFutureInventoryList(*args,**kwargs):\n
inventory_dict[inventory.resource_relative_url,\n
inventory.variation_text,\n
inventory.node_relative_url] = inventory\n
\n
result_list = inventory_dict.values()\n
consumption_dict = {}\n
for movement in movement_list:\n
for material in transformation_line_list_dict[movement]:\n
material_resource = material.getResource()\n
if material_resource is None:\n
continue\n
\n
inventory_dict_key = (material_resource,\n
\'\\n\'.join(sorted(material.getVariationCategoryList())),\n
movement.getSource())\n
\n
quantity = material.getQuantity()\n
\n
try:\n
obj = inventory_dict[inventory_dict_key]\n
except KeyError:\n
obj = material\n
result_list.append(obj)\n
else:\n
inventory_quantity_unit = obj.getQuantityUnit()\n
quantity_unit = material.getQuantityUnit()\n
if quantity_unit != inventory_quantity_unit:\n
quantity = material.getResourceValue().convertQuantity(quantity,\n
quantity_unit,\n
inventory_quantity_unit)\n
\n
if quantity:\n
consumption_dict[obj.getUid()] = quantity * (movement.getQuantity() or 0)\n
\n
context.REQUEST.set(\'consumption_dict\', consumption_dict)\n
return result_list\n
</string> </value>
</item>
<item>
......
......@@ -11,7 +11,7 @@
<value>
<list>
<string>columns</string>
<string>editable_columns</string>
<string>default_params</string>
<string>list_action</string>
<string>list_method</string>
<string>selection_name</string>
......@@ -96,10 +96,6 @@
<string>consumption_item</string>
<string>Consumption</string>
</tuple>
<tuple>
<string>quantity_unit_item</string>
<string>Unit</string>
</tuple>
<tuple>
<string>getCurrentInventory</string>
<string>Current</string>
......@@ -112,18 +108,17 @@
<string>getFutureInventory</string>
<string>Future</string>
</tuple>
<tuple>
<string>quantity_unit_item</string>
<string>Unit</string>
</tuple>
</list>
</value>
</item>
<item>
<key> <string>editable_columns</string> </key>
<key> <string>default_params</string> </key>
<value>
<list>
<tuple>
<string>movement.start_date</string>
<string>movement.start_date</string>
</tuple>
</list>
<list/>
</value>
</item>
<item>
......
2011-06-22 yusei
* Fix bug on production order material consumption tab.
2011-06-15 yusei
* production order movement may not have specialise category value.
......
463
\ No newline at end of file
464
\ No newline at end of file
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