Commit 0ee6eae7 authored by Jérome Perrin's avatar Jérome Perrin

Introduce a new script to get the workflow states for a given portal type

The new approach is a script named ERP5Site_getWorkflowStateItemList that receives the portal type and the state variable (simulation_state/validation_state) as parameters and it will returns the states for the workflow chained to the portal type. This way all the standard dialogs works out of the box even if you customize a workflow chain
parent c97834f0
......@@ -280,7 +280,7 @@
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python:here.Base_getTranslatedAccountingWorkflowStateItemList()</string> </value>
<value> <string>python: context.ERP5Site_getWorkflowStateItemList(portal_type=\'Accounting Transaction\', state_var=\'simulation_state\', display_none_category=False)</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -280,7 +280,7 @@
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python:here.Base_getTranslatedAccountingWorkflowStateItemList()</string> </value>
<value> <string>python: context.ERP5Site_getWorkflowStateItemList(portal_type=\'Accounting Transaction\', state_var=\'simulation_state\', display_none_category=False)</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -293,7 +293,7 @@
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python:[(\'\', \'\')] + here.Base_getTranslatedAccountingWorkflowStateItemList()</string> </value>
<value> <string>python: context.ERP5Site_getWorkflowStateItemList(portal_type=\'Accounting Transaction\', state_var=\'simulation_state\')</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -278,7 +278,7 @@
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python:here.Base_getTranslatedAccountingWorkflowStateItemList()</string> </value>
<value> <string>python: context.ERP5Site_getWorkflowStateItemList(portal_type=\'Accounting Transaction\', state_var=\'simulation_state\')</string> </value>
</item>
</dictionary>
</pickle>
......
<?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>return \'accounting_workflow\'\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getAccountingWorkflowId</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -293,7 +293,7 @@
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python:[(\'\', \'\')] + context.Base_getTranslatedAccountingWorkflowStateItemList()</string> </value>
<value> <string>python: context.ERP5Site_getWorkflowStateItemList(portal_type=\'Accounting Transaction\', state_var=\'simulation_state\')</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -82,7 +82,8 @@ portal = context.getPortalObject()\n
total_payable_price_per_node_section = dict()\n
\n
if simulation_state is None:\n
state_list = [x[1] for x in context.Base_getTranslatedAccountingWorkflowStateItemList()]\n
state_list = [x[1] for x in context.ERP5Site_getWorkflowStateItemList(\n
portal_type=\'Accounting Transaction\', state_var=\'simulation_state\')]\n
simulation_state = [x for x in state_list\n
if x not in (\'draft\', \'cancelled\', \'deleted\', \'rejected\')]\n
\n
......
1532
\ No newline at end of file
1533
\ No newline at end of file
......@@ -280,7 +280,7 @@
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python:here.Base_getTranslatedWorkflowStateItemList(wf_id=\'budget_workflow\')</string> </value>
<value> <string>python: context.ERP5Site_getWorkflowStateItemList(portal_type=\'Budget\', state_var=\'validation_state\')</string> </value>
</item>
</dictionary>
</pickle>
......
365
\ No newline at end of file
366
\ No newline at end of file
......@@ -10,9 +10,9 @@
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>title</string>
<string>items</string>
<string>size</string>
<string>title</string>
</list>
</value>
</item>
......@@ -123,26 +123,20 @@
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python:here.Base_getTranslatedWorkflowStateItemList(wf_id=\'sale_opportunity_workflow\')</string> </value>
<value> <string>python: context.ERP5Site_getWorkflowStateItemList(portal_type=\'Sale Opportunity\', state_var=\'validation_state\')</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
......
......@@ -10,9 +10,9 @@
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>title</string>
<string>items</string>
<string>size</string>
<string>title</string>
</list>
</value>
</item>
......@@ -123,26 +123,20 @@
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python:here.Base_getTranslatedWorkflowStateItemList(wf_id=\'ticket_workflow\')</string> </value>
<value> <string>python: context.ERP5Site_getWorkflowStateItemList(portal_type=\'Campaign\', state_var=\'validation_state\')</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
......
......@@ -10,10 +10,10 @@
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>title</string>
<string>default</string>
<string>items</string>
<string>enabled</string>
<string>items</string>
<string>title</string>
</list>
</value>
</item>
......@@ -136,10 +136,7 @@
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
......@@ -152,10 +149,7 @@
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
......@@ -168,16 +162,13 @@
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: here.Base_getTranslatedWorkflowStateItemList(wf_id="sale_opportunity_workflow")</string> </value>
<value> <string>python: context.ERP5Site_getWorkflowStateItemList(portal_type=\'Sale Opportunity\', state_var=\'validation_state\')</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -10,10 +10,10 @@
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>title</string>
<string>default</string>
<string>items</string>
<string>enabled</string>
<string>items</string>
<string>title</string>
</list>
</value>
</item>
......@@ -136,10 +136,7 @@
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
......@@ -152,10 +149,7 @@
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
......@@ -168,16 +162,13 @@
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: here.Base_getTranslatedWorkflowStateItemList(wf_id="ticket_workflow")</string> </value>
<value> <string>python: context.ERP5Site_getWorkflowStateItemList(portal_type=\'Campaign\', state_var=\'validation_state\')</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -79,8 +79,8 @@ if request_stop_date:\n
query=request_stop_date.latestTime())\n
\n
#Get direction workfolow state list (simulation states)\n
for state in portal.Base_getTranslatedWorkflowStateItemList(\n
wf_id=\'event_simulation_workflow\'):\n
for state in portal.ERP5Site_getWorkflowStateItemList(\n
portal_type=portal.getPortalEventTypeList(), state_var=\'simulation_state\'):\n
if state[1] in direction_state_list:\n
#count number of objects in state with request parameters\n
obj = Object(uid="new_")\n
......
......@@ -55,7 +55,8 @@
from Products.PythonScripts.standard import Object\n
request = container.REQUEST\n
portal = context.getPortalObject()\n
state_item_list=[x[1] for x in context.Base_getTranslatedWorkflowStateItemList(wf_id=\'event_simulation_workflow\')]\n
state_item_list=[x[1] for x in portal.ERP5Site_getWorkflowStateItemList(\n
portal_type=portal.getPortalEventTypeList(), state_var=\'simulation_state\')]\n
#remove deteted state\n
if \'deleted\' in state_item_list:\n
state_item_list.remove(\'deleted\')\n
......
......@@ -59,7 +59,8 @@ selection_columns.append((\'ticket_type\', \'Module\'))\n
selection_columns.append((\'resource\',\'Type\'))\n
#Add dynamicaly event states columns to the form\n
#The name of column must be without spaces\n
for event_state in context.Base_getWorkflowStateItemList(\'event_simulation_workflow\'):\n
for event_state in context.ERP5Site_getWorkflowStateItemList(\n
portal_type=context.getPortalEventTypeList(), state_var=\'simulation_state\', translate=False):\n
if event_state[1]!=\'deleted\':\n
selection_columns.append((event_state[1],event_state[0]))\n
selection_columns.append((\'total\', \'Total\'))\n
......
658
\ No newline at end of file
659
\ No newline at end of file
......@@ -127,10 +127,7 @@
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
......@@ -143,26 +140,20 @@
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: here.Base_getTranslatedWorkflowStateItemList(wf_id=\'project_workflow\')</string> </value>
<value> <string>python: context.ERP5Site_getWorkflowStateItemList(portal_type=\'Project\', state_var=\'validation_state\', display_none_category=False)</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
......
......@@ -261,10 +261,7 @@
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
......@@ -277,10 +274,7 @@
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
......@@ -293,16 +287,13 @@
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python:[(\'\', \'\')] + here.Base_getTranslatedWorkflowStateItemList(wf_id=\'accounting_workflow\')</string> </value>
<value> <string>python: context.ERP5Site_getWorkflowStateItemList(portal_type=\'Accounting Transaction\', state_var=\'simulation_state\')</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -67,6 +67,10 @@
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>required</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
......@@ -108,16 +112,13 @@
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python:here.Base_getTranslatedWorkflowStateItemList(wf_id=(\'task_workflow\',\'task_report_workflow\'))</string> </value>
<value> <string>python:ERP5Site_getWorkflowStateItemList(portal_type=(\'Task\', \'Task Report\') state_var=\'simulation_state\', display_none_category=False)</string> </value>
</item>
</dictionary>
</pickle>
......
828
\ No newline at end of file
829
\ No newline at end of file
......@@ -50,8 +50,12 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string># wf_id is a bad argument name. But I will keep this for backward compatibility.\n
# wf_id : the id of workflow. It can be string, list or tuple.\n
<value> <string>"""Returns the state item list of a given workflow.\n
wf_id : the id of workflow. It can be string, list or tuple.\n
\n
This script is deprecated, it is much recommended to use\n
ERP5Site_getWorkflowStateItemList by passing the portal type instead.\n
"""\n
\n
Base_translateString = context.Base_translateString\n
\n
......
......@@ -50,7 +50,11 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>from Products.CMFCore.utils import getToolByName\n
<value> <string>\'\'\'This script is deprecated, it is much recommended to use\n
ERP5Site_getWorkflowStateItemList by passing the portal type and state_var instead.\n
\'\'\'\n
\n
from Products.CMFCore.utils import getToolByName\n
\n
if not (same_type(workflow_id_list, []) or same_type(workflow_id_list, ())):\n
workflow_id_list = (workflow_id_list,)\n
......
......@@ -50,16 +50,78 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>return context.Base_getTranslatedWorkflowStateItemList(wf_id=context.Base_getAccountingWorkflowId())\n
</string> </value>
<value> <string encoding="cdata"><![CDATA[
\'\'\'Returns a list of items (state_title, state_id) of the workflows that are chained\n
to the given portal_type(s). This can also be filtered to workflows that are using\n
a given state_var (simulation_state, validation_state etc).\n
\n
display_none_category argument controls wether the list will contain an empty item \n
as first element or not (just like category tool API)\n
\n
The state titles will be translated unless you pass translate=False\n
\'\'\'\n
if translate:\n
from Products.ERP5Type.Message import translateString\n
else:\n
translateString = lambda msg: msg\n
\n
workflow_tool = context.getPortalObject().portal_workflow\n
workflow_set = set() # existing workflows.\n
state_set = set([\'deleted\']) # existing state ids (we do not want to return a same state id twice \n
# if more than one workflow define the same state). Also note that we\n
# always ignore deleted state.\n
\n
result_list = display_none_category and [(\'\', \'\')] or []\n
\n
if isinstance(portal_type, basestring):\n
portal_type = portal_type,\n
\n
chain_dict = workflow_tool.getWorkflowChainDict()\n
for portal_type in portal_type:\n
for workflow_id in chain_dict[\'chain_%s\' % portal_type].split(\',\'):\n
workflow_id = workflow_id.strip()\n
if workflow_id in workflow_set:\n
continue\n
workflow_set.add(workflow_id)\n
\n
workflow = workflow_tool[workflow_id]\n
\n
# skip interaction workflows or workflows with only one state (such as edit_workflow)\n
if workflow.states is None or len(workflow.states.objectIds()) <= 1:\n
continue\n
\n
# skip workflows using another state variable\n
if state_var not in (None, workflow.variables.getStateVar()):\n
continue\n
\n
for state in workflow.states.objectValues():\n
if state.id in state_set:\n
continue\n
state_set.add(state.id)\n
\n
result_list.append((str(translateString(state.title)), state.id))\n
\n
return result_list\n
]]></string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
<value> <string>portal_type=(), state_var=None, display_none_category=True, translate=True</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getTranslatedAccountingWorkflowStateItemList</string> </value>
<value> <string>ERP5Site_getWorkflowStateItemList</string> </value>
</item>
</dictionary>
</pickle>
......
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