Commit 94b271eb authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_trade: packing list report

parent ea1b573f
......@@ -11,8 +11,12 @@ simulation_state = request.get('simulation_state', ())
# define some parameter dependings on module
if "Sale" in context.getPortalType():
report_type = "sale"
line_portal_type = "Sale Order Line"
doc_portal_type = "Sale Order"
if 'Sale Order' in context.getPortalType():
line_portal_type = "Sale Order Line"
doc_portal_type = "Sale Order"
else:
line_portal_type = "Sale Packing List Line"
doc_portal_type = "Sale Packing List"
elif "Purchase" in context.getPortalType():
report_type = "purchase"
line_portal_type = "Purchase Order Line"
......
......@@ -15,8 +15,12 @@ simulation_state = request.get('simulation_state', ())
# define some parameter dependings on module
if "Sale" in context.getPortalType():
report_type = "sale"
line_portal_type = "Sale Order Line"
doc_portal_type = "Sale Order"
if 'Sale Order' in context.getPortalType():
doc_portal_type = "Sale Order"
line_portal_type = "Sale Order Line"
else:
line_portal_type = "Sale Packing List Line"
doc_portal_type = "Sale Packing List"
elif "Purchase" in context.getPortalType():
report_type = "purchase"
line_portal_type = "Purchase Order Line"
......@@ -43,7 +47,7 @@ if from_date is None:
from_date = DateTime()
result_list = context.portal_catalog(
sort_on=(('delivery.start_date','ascending'),),
portal_type='Sale Order',
portal_type=doc_portal_type,
query=q,
limit=1)
if result_list:
......
......@@ -15,6 +15,8 @@ incoterm = request.get('incoterm', None)
section_category = request.get('section_category', None)
order = request.get('order', None)
delivery_mode = request.get('delivery_mode', None)
product_line = request.get('product_line', None)
price_type = request.get('price_type', 'sale_price')
catalog_params = {}
......@@ -76,7 +78,16 @@ else:
simulation_state=simulation_state,
sort_on=sort_on_list,
**catalog_params)
def Sale_getTotalPrice(sale):
total_price = 0
for line in sale.contentValues(filter = {'portal_type':line_portal_type}):
if product_line and line.getResourceValue().getProductLine() == product_line:
if price_type == 'sale_price':
total_price = total_price + line.getTotalPrice()
else:
purchase_price = resource_value.getPurchaseSupplyLineBasePrice() or 0
total_price = total_price + line.getTotalQuantity() * purchase_price
return total_price
# we build two dict, one that store amount per period per client
# and another that either store amount per period per product and per client
......@@ -98,9 +109,9 @@ for result in result_list:
if not client_dict.has_key(client_title):
client_dict[client_title] = {}
if client_dict[client_title].has_key(period):
client_dict[client_title][period]['amount'] = client_dict[client_title][period]['amount'] + result.getTotalPrice()
client_dict[client_title][period]['amount'] = client_dict[client_title][period]['amount'] + Sale_getTotalPrice(result)
else:
client_dict[client_title][period] = {'amount' : result.getTotalPrice()}
client_dict[client_title][period] = {'amount' : Sale_getTotalPrice(result)}
if not product_dict.has_key(client_title):
line_dict = product_dict[client_title] = {}
else:
......@@ -112,6 +123,9 @@ for result in result_list:
# client_title -> product_title -> period -> amount/quantity...
# or product_title -> period -> amount/quantity...
for line in result.contentValues(filter = {'portal_type':line_portal_type}):
if product_line:
if line.getResourceValue().getProductLine() != product_line:
continue
# Filter by quantity_unit
if quantity_unit:
if line.getQuantityUnit() != quantity_unit:
......@@ -124,18 +138,26 @@ for result in result_list:
product_title = line.getDestinationFunctionTitle()
else:
product_title = line.getResourceTitle()
resource_title_dict[product_title] = line.getResourceReference()
resource_value = line.getResourceValue()
resource_title_dict[product_title] = resource_value.getReference()
if price_type == 'sale_price':
total_price = line.getTotalPrice()
else:
purchase_price = resource_value.getPurchaseSupplyLineBasePrice() or 0
total_price = line.getTotalQuantity() * purchase_price
if not line_dict.has_key(product_title):
line_dict[product_title] = {period :{"amount" : line.getTotalPrice(),
line_dict[product_title] = {period :{"amount" : total_price,
"quantity" : line.getTotalQuantity(),
"quantity_unit" : line.getQuantityUnitTranslatedTitle()}}
else:
if not line_dict[product_title].has_key(period):
line_dict[product_title][period] = {"amount" : line.getTotalPrice(),
line_dict[product_title][period] = {"amount" : total_price,
"quantity" : line.getTotalQuantity(),
"quantity_unit" : line.getQuantityUnitTranslatedTitle()}
else:
line_dict[product_title][period]['amount'] = line_dict[product_title][period]['amount'] + line.getTotalPrice()
line_dict[product_title][period]['amount'] = line_dict[product_title][period]['amount'] + total_price
line_dict[product_title][period]['quantity'] = line_dict[product_title][period]['quantity'] + line.getTotalQuantity()
......
......@@ -103,6 +103,8 @@
<string>your_incoterm</string>
<string>your_order</string>
<string>your_section_category</string>
<string>your_price_type</string>
<string>your_product_line</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>default</string>
<string>enabled</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_price_type</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>default</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>enabled</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<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>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_report_mode_order</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewTradeFieldLibrary</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>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>request/price_type | nothing</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>request/price_type | nothing</string> </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>default</string>
<string>enabled</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_product_line</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>default</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>enabled</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<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>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_report_mode_order</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewTradeFieldLibrary</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>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>request/product_line | nothing</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>request/product_line | nothing</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -112,6 +112,8 @@
<list>
<string>your_aggregation_level</string>
<string>your_group_by</string>
<string>your_product_line</string>
<string>your_price_type</string>
<string>your_simulation_state</string>
</list>
</value>
......
......@@ -9,7 +9,9 @@
<item>
<key> <string>delegated_list</string> </key>
<value>
<list/>
<list>
<string>items</string>
</list>
</value>
</item>
<item>
......@@ -58,6 +60,12 @@
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>items</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
......@@ -77,6 +85,12 @@
<key> <string>form_id</string> </key>
<value> <string>Base_viewTradeFieldLibrary</string> </value>
</item>
<item>
<key> <string>items</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
......@@ -87,4 +101,17 @@
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: [(context.Base_translateString(x[0]), x[1]) for x in ((\'Product\', \'product\'), (\'Third Party\', \'client\'), (\'Third Party / Product\', \'both\'), (context.AccountingTransactionLine_getFunctionBaseCategoryTitle(), \'function\'))]</string> </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>items</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_product_line</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>items</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</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_product_line</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewPDMFieldLibrary</string> </value>
</item>
<item>
<key> <string>items</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: getattr(here.portal_categories[field.getId().replace(\'your_\', \'\', 1)], preferences.getPreference(\'preferred_category_child_item_list_method_id\', \'getCategoryChildCompactLogicalPathItemList\'))(local_sort_id=(\'int_index\', \'translated_title\'), checked_permission=\'View\')</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -9,7 +9,9 @@
<item>
<key> <string>delegated_list</string> </key>
<value>
<list/>
<list>
<string>items</string>
</list>
</value>
</item>
<item>
......@@ -58,6 +60,12 @@
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>items</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
......@@ -77,6 +85,12 @@
<key> <string>form_id</string> </key>
<value> <string>Base_viewTradeFieldLibrary</string> </value>
</item>
<item>
<key> <string>items</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
......@@ -87,4 +101,17 @@
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python:here.Base_getTranslatedWorkflowStateItemList(wf_id=\'packing_list_workflow\')</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