Commit 3b239e0f authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_trade: show inventory calculation steps

parent 3b8c1195
...@@ -84,6 +84,9 @@ ...@@ -84,6 +84,9 @@
<portal_type id="Inventory Report"> <portal_type id="Inventory Report">
<item>Inventory Report Line</item> <item>Inventory Report Line</item>
</portal_type> </portal_type>
<portal_type id="Inventory Report Line">
<item>Inventory Report Cell</item>
</portal_type>
<portal_type id="Inventory Report Module"> <portal_type id="Inventory Report Module">
<item>Inventory Report</item> <item>Inventory Report</item>
</portal_type> </portal_type>
......
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
<portal_type id="Inventory Line"> <portal_type id="Inventory Line">
<item>Inventory Cell</item> <item>Inventory Cell</item>
</portal_type> </portal_type>
<portal_type id="Inventory Report Line">
<item>Inventory Report Cell</item>
</portal_type>
<portal_type id="Preference"> <portal_type id="Preference">
<item>Purchase Order</item> <item>Purchase Order</item>
<item>Sale Order</item> <item>Sale Order</item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Base Type" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_property_domain_dict</string> </key>
<value>
<dictionary>
<item>
<key> <string>short_title</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>acquire_local_roles</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>allowed_action_list</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>content_icon</string> </key>
<value> <string>inventory_line_icon.gif</string> </value>
</item>
<item>
<key> <string>content_meta_type</string> </key>
<value> <string>ERP5 Inventory Line</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>An inventory line can be found in inventory documents, and bears the available stock of a certain product reference. There will be one inventory line for each product reference of the inventory.</string> </value>
</item>
<item>
<key> <string>factory</string> </key>
<value> <string>addInventoryLine</string> </value>
</item>
<item>
<key> <string>filter_actions</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>filter_content_types</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Inventory Report Cell</string> </value>
</item>
<item>
<key> <string>init_script</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>permission</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>searchable_text_property_id</string> </key>
<value>
<tuple>
<string>title</string>
<string>description</string>
<string>short_title</string>
</tuple>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>type_class</string> </key>
<value> <string>Item</string> </value>
</item>
<item>
<key> <string>type_interface</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>type_mixin</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="TranslationInformation" module="Products.ERP5Type.TranslationProviderBase"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>domain_name</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>property_name</string> </key>
<value> <string>short_title</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="TranslationInformation" module="Products.ERP5Type.TranslationProviderBase"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>domain_name</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>property_name</string> </key>
<value> <string>title</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
if url_dict:
jio_key = '/'.join(context.movement_url.split('/')[-2:])
return {
'command': 'push_history',
'options': {
'jio_key': jio_key
},
}
else:
return context.movement_url
<?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>url_dict=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>InventoryReportCell_getRelatedMovementUrl</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, NegatedQuery
from collections import OrderedDict
newContent = context.newContent
portal = context.getPortalObject()
getCurrentInventoryAssetPrice =portal.portal_simulation.getCurrentInventoryAssetPrice
getMovementHistoryList = portal.portal_simulation.getMovementHistoryList
current_date_kw = kw.copy()
kw.pop('valuation_method', None)
kw['sort_on'] =(('date','ascending'),)
movement_dict = OrderedDict()
current_id = 1
for movement in getMovementHistoryList(**kw):
if movement.date not in movement_dict:
movement_dict[movement.date] = []
movement_dict[movement.date].append(movement)
for date, value_list in movement_dict.iteritems():
current_date_kw['at_date'] = date
same_date_length = len(value_list)
for index in range(same_date_length):
if index < same_date_length - 1:
current_date_kw['uid'] = NegatedQuery(SimpleQuery(uid=[x.getUid() for x in value_list[index+1:]]))
else:
current_date_kw.pop('uid', None)
total_asset_price = getCurrentInventoryAssetPrice(**current_date_kw)
movement = value_list[index]
if not getattr(movement, 'isDelivery', 0):
explanation = movement.getExplanationValue()
else:
explanation = movement
newContent(
id = format(current_id, '07d'),
portal_type='Inventory Report Cell',
date = movement.date,
movement_url = explanation.absolute_url(),
explanation_text = movement.getExplanationText(),
node_title = movement.node_title,
section_title = movement.section_title,
total_quantity = movement.total_quantity,
running_total_quantity = movement.running_total_quantity,
total_asset_price = total_asset_price)
current_id += 1
<?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>**kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>InventoryReportLine_createMovementHistoryCellList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
cell_list = context.objectValues(portal_type='Inventory Report Cell')
return sorted(cell_list, key=lambda x:x.date)
<?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>**kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>InventoryReportLine_getCellList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -63,6 +63,7 @@ ...@@ -63,6 +63,7 @@
<string>right</string> <string>right</string>
<string>center</string> <string>center</string>
<string>bottom</string> <string>bottom</string>
<string>hidden</string>
</list> </list>
</value> </value>
</item> </item>
...@@ -73,7 +74,9 @@ ...@@ -73,7 +74,9 @@
<item> <item>
<key> <string>bottom</string> </key> <key> <string>bottom</string> </key>
<value> <value>
<list/> <list>
<string>listbox</string>
</list>
</value> </value>
</item> </item>
<item> <item>
...@@ -84,6 +87,15 @@ ...@@ -84,6 +87,15 @@
</list> </list>
</value> </value>
</item> </item>
<item>
<key> <string>hidden</string> </key>
<value>
<list>
<string>listbox_date</string>
<string>listbox_total_quantity</string>
</list>
</value>
</item>
<item> <item>
<key> <string>left</string> </key> <key> <string>left</string> </key>
<value> <value>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>editable</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>listbox_date</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>editable</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_date</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>editable</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>listbox_total_quantity</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>editable</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_quantity</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
for content in context.contentValues(portal_type='Inventory Report Line'):
context.deleteContent(content.getId())
context.setTotalAssetPrice(0)
<?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>**kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>InventoryReport_afterClone</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -6,5 +6,5 @@ context.calculate() ...@@ -6,5 +6,5 @@ context.calculate()
context.activate().InventoryReport_recordProductStock() context.activate().InventoryReport_recordProductStock()
if not batch_mode: if not batch_mode:
message = context.Base_translateString("Product Stock is creating") message = context.Base_translateString("Calculating Inventory Report")
return context.Base_redirect('view',keep_items={'portal_status_message': message}) return context.Base_redirect('view',keep_items={'portal_status_message': message})
...@@ -37,6 +37,17 @@ for inventory in inventory_list: ...@@ -37,6 +37,17 @@ for inventory in inventory_list:
at_date = at_date, at_date = at_date,
is_accountable = 1 is_accountable = 1
) )
inventory_report_line.activate(
tag = line_tag
).InventoryReportLine_createMovementHistoryCellList(
section_uid = section_uid,
node_uid = node_uid,
valuation_method = valuation_method,
variation_text = inventory.variation_text,
resource_uid = inventory.resource_uid,
at_date = at_date,
is_accountable = 1
)
tag = '%s:updateTotalAssetPrice' % relative_url tag = '%s:updateTotalAssetPrice' % relative_url
context.activate(after_tag=line_tag, tag=tag).InventoryReport_updateTotalAssetPrice() context.activate(after_tag=line_tag, tag=tag).InventoryReport_updateTotalAssetPrice()
......
...@@ -39,6 +39,7 @@ Internal Trade Condition | Payment Condition ...@@ -39,6 +39,7 @@ Internal Trade Condition | Payment Condition
Internal Trade Condition | Trade Model Line Internal Trade Condition | Trade Model Line
Inventory Line | Inventory Cell Inventory Line | Inventory Cell
Inventory Module | Inventory Inventory Module | Inventory
Inventory Report Line | Inventory Report Cell
Inventory Report Module | Inventory Report Inventory Report Module | Inventory Report
Inventory Report | Inventory Report Line Inventory Report | Inventory Report Line
Inventory | Inventory Line Inventory | Inventory Line
......
...@@ -2,6 +2,7 @@ Container Line | Container Cell ...@@ -2,6 +2,7 @@ Container Line | Container Cell
Internal Order Line | Internal Order Cell Internal Order Line | Internal Order Cell
Internal Packing List Line | Internal Packing List Cell Internal Packing List Line | Internal Packing List Cell
Inventory Line | Inventory Cell Inventory Line | Inventory Cell
Inventory Report Line | Inventory Report Cell
Preference | Purchase Order Preference | Purchase Order
Preference | Sale Order Preference | Sale Order
Purchase Order Line | Purchase Order Cell Purchase Order Line | Purchase Order Cell
......
...@@ -26,6 +26,7 @@ Inventory Cell ...@@ -26,6 +26,7 @@ Inventory Cell
Inventory Line Inventory Line
Inventory Module Inventory Module
Inventory Report Inventory Report
Inventory Report Cell
Inventory Report Line Inventory Report Line
Inventory Report Module Inventory Report Module
Order Order
......
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