Commit dcf1eb85 authored by Klaus Wölfel's avatar Klaus Wölfel Committed by Xiaowu Zhang

erp5_trade: Order Report improvements

- Optionally group by function
- Give higher priority to Order Report compared to Workflow Report
- Optionally filter by Quantity Unit and enable Stat Columns for Quantity

TODO: Quantity also for Thirs Party if filtered by quantity Unit
parent f56528d6
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>8.0</float> </value>
<value> <float>12.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
......
from Products.ERP5Type.DateUtils import getIntervalListBetweenDates
from DateTime import DateTime
request = container.REQUEST
# list only if user has a login defined
aggregation_level = request.get('aggregation_level')
from_date = request.get('from_date')
to_date = request.get('at_date')
group_by = request.get('group_by')
quantity_unit = request.get('quantity_unit')
simulation_state = request.get('simulation_state', ())
# define some parameter dependings on module
if "Sale" in context.getPortalType():
report_type = "sale"
......@@ -30,7 +29,6 @@ elif request.get('order_report_document_portal_type'):
raise ValueError("unknown document portal type for report %s" % doc_portal_type)
else:
raise ValueError("unknown type for report")
selection_columns = [('group_by', "Group by")]
if from_date is None:
# get the minimum start date in catalog
......@@ -46,7 +44,6 @@ if from_date is None:
limit=1)
if result_list:
from_date = DateTime(result_list[0].start_date)
# get period list between given date
interval_list_dict = getIntervalListBetweenDates(from_date=from_date, to_date=to_date,
......@@ -55,7 +52,6 @@ interval_list_dict = getIntervalListBetweenDates(from_date=from_date, to_date=to
'week' : aggregation_level=="week",
'day':aggregation_level=="day"})
interval_list = interval_list_dict[aggregation_level]
# FIXME: translate column names
# list columns of the listbox
interval_column_list = []
......@@ -69,18 +65,21 @@ else:
if group_by == "product":
selection_columns = [('product', "Product")]
stat_columns = [('product', "product")]
elif group_by == "function":
function_title = context.AccountingTransactionLine_getFunctionBaseCategoryTitle()
selection_columns = [('product', function_title)]
stat_columns = [('product', "product")]
else:
selection_columns = [('client', "Client"), ('product', "Product")]
stat_columns = [('client', "client"), ('product', "product")]
for x in interval_list:
interval_column_list.extend([("Amount %s" %x,"Amount %s" %x), ("Quantity %s" %x,"Quantity %s" %x),
("Quantity Unit %s" %x,"Quantity Unit %s" %x)])
interval_column_list.extend([("Amount %s" %x,"Amount %s" %x), ("Quantity %s" %x,"Quantity %s" %x)])
if not quantity_unit:
interval_column_list.extend([("Quantity Unit %s" %x,"Quantity Unit %s" %x)])
total_column_list = [('total amount', 'Total Amount'),('total quantity', 'Total Quantity')]
total_stat_list = [('total amount', 'total amount'),('total quantity', 'total quantity')]
selection_columns.extend(interval_column_list)
selection_columns.extend(total_column_list)
params=dict(period_list=interval_list, report_type=report_type,
doc_portal_type=doc_portal_type, line_portal_type=line_portal_type,
simulation_state=simulation_state)
......
from Products.ERP5Form.Report import ReportSection
from DateTime import DateTime
params, stat_columns, selection_columns = context.OrderModule_getOrderReportParameterDict()
context.REQUEST.set('stat_columns', stat_columns)
result=[]
result.append(ReportSection(
......@@ -11,6 +9,4 @@ result.append(ReportSection(
listbox_display_mode='FlatListMode',
selection_params=params,
form_id='OrderModule_viewOrderStatList'))
return result
from Products.PythonScripts.standard import Object
from json import loads
portal = context.getPortalObject()
request = container.REQUEST
report_group_by = request.get('group_by', None)
quantity_unit = request.get('quantity_unit', None)
active_process_path = request.get('active_process')
# We have to sum product_dict and client_dict from the results of active process
def _addDict(global_dict, local_dict, only_amount=False):
if report_group_by == "both" and not only_amount:
......@@ -30,7 +28,6 @@ def _addDict(global_dict, local_dict, only_amount=False):
if not only_amount:
amount_dict['quantity'] = amount_dict['quantity'] + local_amount_dict['quantity']
amount_dict['quantity_unit'] = local_amount_dict['quantity_unit']
product_dict = {}
client_dict = {}
if active_process_path:
......@@ -55,10 +52,8 @@ if active_process_path:
_addDict(product_dict, result_product_dict)
else:
raise ValueError("No active process found to process report")
def sortProduct(a, b):
return cmp(a['product'], b['product'])
period_counter_dict = {}
line_list = []
append = line_list.append
......@@ -89,7 +84,6 @@ if len(client_dict):
period_counter_dict['total amount'] = period_counter_dict['total amount'] + line_total_amount
else:
period_counter_dict['total amount'] = line_total_amount
append(obj)
if report_group_by == "both":
product_lines_list = []
......@@ -115,12 +109,18 @@ if len(client_dict):
line_product_dict[product_title][period]['amount']
else:
period_counter_dict['Amount %s' %(period)] = line_product_dict[product_title][period]['amount']
if quantity_unit:
if period_counter_dict.has_key('Quantity %s' %(period)):
period_counter_dict['Quantity %s' %(period)] = period_counter_dict['Quantity %s' %(period)] + \
line_product_dict[product_title][period]['quantity']
else:
period_counter_dict['Quantity %s' %(period)] = line_product_dict[product_title][period]['quantity']
else:
obj['Amount %s' %(period)] = 0
obj['Quantity %s' %(period)] = 0
obj['Quantity Unit %s' %(period)] = ""
obj['total quantity'] = line_total_quantity
obj['total amount'] = round(line_total_amount, 2)
# total for stat line
......@@ -128,6 +128,11 @@ if len(client_dict):
period_counter_dict['total amount'] = period_counter_dict['total amount'] + line_total_amount
else:
period_counter_dict['total amount'] = line_total_amount
if quantity_unit:
if period_counter_dict.has_key('total quantity'):
period_counter_dict['total quantity'] = period_counter_dict['total quantity'] + line_total_quantity
else:
period_counter_dict['total quantity'] = line_total_quantity
product_lines_list.append(obj)
# sort product list
......@@ -135,7 +140,7 @@ if len(client_dict):
extend(product_lines_list)
else:
# products
if report_group_by == "product":
if report_group_by in ("product", "function"):
for product_title in product_dict.keys():
obj = Object(uid="new_")
obj['product'] = product_title
......@@ -154,11 +159,15 @@ else:
period_counter_dict['Amount %s' %(period)] = period_counter_dict['Amount %s' %(period)] + product_dict[product_title][period]['amount']
else:
period_counter_dict['Amount %s' %(period)] = product_dict[product_title][period]['amount']
if quantity_unit:
if period_counter_dict.has_key('Quantity %s' %(period)):
period_counter_dict['Quantity %s' %(period)] = period_counter_dict['Quantity %s' %(period)] + product_dict[product_title][period]['quantity']
else:
period_counter_dict['Quantity %s' %(period)] = product_dict[product_title][period]['quantity']
else:
obj['Amount %s' %(period)] = 0
obj['Quantity %s' %(period)] = 0
obj['Quantity Unit %s' %(period)] = ""
obj['total quantity'] = line_total_quantity
obj['total amount'] = round(line_total_amount,2)
# total for stat line
......@@ -166,17 +175,18 @@ else:
period_counter_dict['total amount'] = period_counter_dict['total amount'] + line_total_amount
else:
period_counter_dict['total amount'] = line_total_amount
if quantity_unit:
if period_counter_dict.has_key('total quantity'):
period_counter_dict['total quantity'] = period_counter_dict['total quantity'] + line_total_quantity
else:
period_counter_dict['total quantity'] = line_total_quantity
append(obj)
line_list.sort(sortProduct)
obj = Object(uid="new_")
obj["client"] = 'Total'
for k,v in period_counter_dict.items():
if "mount" in k:
v = round(v, 2)
obj[k] = v
request.set('stat_line', [obj,])
return line_list
......@@ -94,6 +94,7 @@
<string>your_delivery_mode</string>
<string>your_from_date</string>
<string>your_group_by</string>
<string>your_quantity_unit</string>
<string>your_incoterm</string>
<string>your_order</string>
<string>your_section_category</string>
......
<?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>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_quantity_unit</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>field_id</string> </key>
<value> <string>my_dialog_mode_category</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>
<item>
<key> <string>title</string> </key>
<value> <string>Quantity Unit</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -112,6 +112,7 @@
<list>
<string>your_aggregation_level</string>
<string>your_group_by</string>
<string>your_quantity_unit</string>
<string>your_simulation_state</string>
</list>
</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>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_quantity_unit</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>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_dialog_mode_category</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>
<item>
<key> <string>title</string> </key>
<value> <string>Quantity Unit</string> </value>
</item>
</dictionary>
</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