Commit 1f01f382 authored by Łukasz Nowak's avatar Łukasz Nowak

erp5_item: Factorise quantity update

parent 56b4b95e
...@@ -79,22 +79,7 @@ for line in kw.get('listbox'): ...@@ -79,22 +79,7 @@ for line in kw.get('listbox'):
movement_to_update.setAggregateValueList( movement_to_update.setAggregateValueList(
movement_to_update.getAggregateValueList() + [item]) movement_to_update.getAggregateValueList() + [item])
context.Movement_updateQuantityFromAggregateList(at_date=DateTime())
if context.isMovement():
movement_list = context,
else:
movement_list = context.getCellValueList(base_id='movement')
for movement in movement_list:
quantity = 0
item_list = movement.getAggregateValueList()
for item in item_list:
if item.getQuantityUnit() != movement.getQuantityUnit():
if len(item_list) > 1:
raise NotImplementedError(
'Quantity unit from the movement differs from quantity'
' unit on the item')
quantity += item.getQuantity(at_date=DateTime())
movement.setQuantity(quantity)
return context.Base_redirect(form_id, keep_items=dict( return context.Base_redirect(form_id, keep_items=dict(
portal_status_message=translateString('Items created'))) portal_status_message=translateString('Items created')))
...@@ -92,23 +92,7 @@ for item_uid in uids: ...@@ -92,23 +92,7 @@ for item_uid in uids:
movement_to_update.setAggregateValueSet( movement_to_update.setAggregateValueSet(
movement_to_update.getAggregateValueList() + [item]) movement_to_update.getAggregateValueList() + [item])
if context.isMovement(): context.Movement_updateQuantityFromAggregateList()
movement_list = context,
else:
movement_list = context.getCellValueList(base_id='movement')
for movement in movement_list:
quantity = 0
item_list = movement.getAggregateValueList()
for item in item_list:
if item.getQuantityUnit() != movement.getQuantityUnit():
if len(item_list) > 1:
raise NotImplementedError(
'Quantity unit from the movement differs from quantity'
' unit on the item')
else:
movement.setQuantityUnit(item.getQuantityUnit())
quantity += item.getQuantity()
movement.setQuantity(quantity)
return context.Base_redirect(form_id, keep_items=dict( return context.Base_redirect(form_id, keep_items=dict(
portal_status_message=translateString('Items aggregated'))) portal_status_message=translateString('Items aggregated')))
if context.isMovement():
movement_list = context,
else:
movement_list = context.getCellValueList(base_id='movement')
for movement in movement_list:
quantity = 0
item_list = movement.getAggregateValueList()
for item in item_list:
if item.getQuantityUnit() != movement.getQuantityUnit():
if len(item_list) > 1:
raise NotImplementedError(
'Quantity unit from the movement differs from quantity'
' unit on the item')
else:
movement.setQuantityUnit(item.getQuantityUnit())
quantity += item.getQuantity(at_date=at_date)
movement.setQuantity(quantity)
<?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>_params</string> </key>
<value> <string>at_date=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Movement_updateQuantityFromAggregateList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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