Commit 6731412e authored by Nicolas Delaby's avatar Nicolas Delaby

Add new action on Internal Orders to apply trade conditions.

As both 'Sale Trade Condition' and 'Purchase Trade Condition' might applied on Internal Orders,
The both will be accepted and searchPredicateList will find the best match in both modules.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40864 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d3686bee
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ActionInformation" module="Products.CMFCore.ActionInformation"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_action</string>
</tuple>
</value>
</item>
<item>
<key> <string>category</string> </key>
<value> <string>object_action</string> </value>
</item>
<item>
<key> <string>condition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>icon</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>apply_trade_condition</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>Modify portal content</string>
</tuple>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Action Information</string> </value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>9.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Apply Trade Condition</string> </value>
</item>
<item>
<key> <string>visible</string> </key>
<value> <int>1</int> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/InternalOrder_viewApplyInternalTradeConditionDialog</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -100,10 +100,18 @@
<key> <string>proxy_listbox_ids</string> </key>
<value>
<list>
<tuple>
<string>Base_viewRelatedObjectListBase/listbox</string>
<string>All</string>
</tuple>
<tuple>
<string>PurchaseTradeConditionModule_viewPurchaseTradeConditionList/listbox</string>
<string>Purchase Trade Conditions</string>
</tuple>
<tuple>
<string>SaleTradeConditionModule_viewsaleTradeConditionList/listbox</string>
<string>Sale Trade Conditions</string>
</tuple>
</list>
</value>
</item>
......@@ -113,7 +121,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Internal Trade Condition</string> </value>
<value> <string>Trade Condition</string> </value>
</item>
</dictionary>
</value>
......
<?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 encoding="cdata"><![CDATA[
# This script searches for a trade condition matching the order\n
# and tries to complete some fields\n
\n
order = context\n
Base_translateString = context.Base_translateString\n
trade_condition_portal_type_list = (\'Purchase Trade Condition\', \'Sale Trade Condition\',)\n
\n
trade_condition_list = order.getSpecialiseValueList(\n
portal_type=trade_condition_portal_type_list)\n
\n
tested_base_category_list = [ ]\n
for base_category in (\'source_section\', \'source\',\n
\'destination_section\', \'destination\', ):\n
if context.getProperty(base_category):\n
tested_base_category_list.append(base_category)\n
\n
count = len(tested_base_category_list) + 1\n
\n
# if no date is defined, use today\'s date to retrieve predicate that define start_date_range_min/max\n
if order.getStartDate() is None:\n
predicate_context = order.asContext(start_date=DateTime())\n
else:\n
predicate_context = order\n
\n
def rank_method(trade_condition):\n
rank = 0\n
destination_section = trade_condition.getDestinationSection()\n
if destination_section:\n
if destination_section == context.getDestinationSection():\n
rank += 10\n
else:\n
rank -= 2\n
destination = trade_condition.getDestination()\n
if destination:\n
if destination == context.getDestination():\n
rank += 10\n
else:\n
rank -= 2\n
if trade_condition.getSourceSection():\n
rank += 1\n
if trade_condition.getSource():\n
rank += 1\n
rank += len(trade_condition.getSpecialiseList())\n
if trade_condition.getValidationState() == \'validated\':\n
rank += 2\n
return rank\n
\n
def sort_method(a, b):\n
return -cmp(rank_method(a), rank_method(b))\n
\n
while count > 0 and len(trade_condition_list) == 0:\n
count -= 1\n
trade_condition_list = context.portal_domains.searchPredicateList(\n
predicate_context, portal_type=trade_condition_portal_type_list,\n
tested_base_category_list=tested_base_category_list[:count],\n
sort_method=sort_method)\n
\n
if len(trade_condition_list ) == 0:\n
message = Base_translateString(\'No trade condition.\')\n
else :\n
# if more than one trade condition is found, simply apply the first one\n
trade_condition=trade_condition_list[0].getObject()\n
\n
order.Order_applyTradeCondition(trade_condition, force=force)\n
# set date\n
if hasattr(order, \'getReceivedDate\') and order.getReceivedDate() is None:\n
context.setReceivedDate(DateTime())\n
\n
message = Base_translateString(\'Order updated.\')\n
\n
if not batch_mode:\n
return context.Base_redirect(form_id,\n
keep_items=dict(portal_status_message=message))\n
]]></string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>form_id=\'view\', batch_mode=0, force=1</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>form_id</string>
<string>batch_mode</string>
<string>force</string>
<string>context</string>
<string>order</string>
<string>_getattr_</string>
<string>Base_translateString</string>
<string>trade_condition_portal_type_list</string>
<string>trade_condition_list</string>
<string>tested_base_category_list</string>
<string>_getiter_</string>
<string>base_category</string>
<string>len</string>
<string>count</string>
<string>None</string>
<string>DateTime</string>
<string>predicate_context</string>
<string>rank_method</string>
<string>sort_method</string>
<string>_inplacevar_</string>
<string>_getitem_</string>
<string>message</string>
<string>trade_condition</string>
<string>hasattr</string>
<string>dict</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<tuple>
<string>view</string>
<int>0</int>
<int>1</int>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>InternalOrder_applyTradeCondition</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ERP5Form" module="Products.ERP5Form.Form"/>
</pickle>
<pickle>
<dictionary>
<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/>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>action</string> </key>
<value> <string>InternalOrder_applyTradeCondition</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>edit_order</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>enctype</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
<list>
<string>left</string>
<string>right</string>
<string>center</string>
<string>bottom</string>
<string>hidden</string>
</list>
</value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
<dictionary>
<item>
<key> <string>bottom</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>center</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>hidden</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>left</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>right</string> </key>
<value>
<list/>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>InternalOrder_viewApplyInternalTradeConditionDialog</string> </value>
</item>
<item>
<key> <string>method</string> </key>
<value> <string>POST</string> </value>
</item>
<item>
<key> <string>name</string> </key>
<value> <string>InternalOrder_viewApplyInternalTradeConditionDialog</string> </value>
</item>
<item>
<key> <string>pt</string> </key>
<value> <string>form_dialog</string> </value>
</item>
<item>
<key> <string>row_length</string> </key>
<value> <int>4</int> </value>
</item>
<item>
<key> <string>stored_encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Apply Trade Condition</string> </value>
</item>
<item>
<key> <string>unicode_mode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>update_action</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>update_action_title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
1061
\ No newline at end of file
1062
\ No newline at end of file
......@@ -16,6 +16,7 @@ Internal Order Line | profile_view
Internal Order Line | quantity_view
Internal Order Line | view
Internal Order Module | view
Internal Order | apply_trade_condition
Internal Order | fast_input
Internal Order | fast_input_update
Internal Order | jump_to_related_internal_packing_list
......
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