Commit a6934bf4 authored by Arnaud Fontaine's avatar Arnaud Fontaine

WIP: ERP5Workflow: Workflow PythonScript should not require any change.

Workflow Script context must be created before execution. Otherwise Workflow
Script cannot call other Workflow Scripts.
parent 305512f9
...@@ -13,8 +13,7 @@ section_portal_type_list = ['Person', 'Organisation'] ...@@ -13,8 +13,7 @@ section_portal_type_list = ['Person', 'Organisation']
invalid_state_list = ['invalidated', 'deleted'] invalid_state_list = ['invalidated', 'deleted']
# first of all, validate the transaction itself # first of all, validate the transaction itself
script_id = container.getScriptIdByReference('validateTransaction') container.validateTransaction(state_change)
container.getScriptValueById(script_id)(state_change)
# Check that all lines uses open accounts, and doesn't use invalid third # Check that all lines uses open accounts, and doesn't use invalid third
......
return sci.getPortal().portal_workflow.accounting_workflow.getScriptValueById(script.getId())(sci) return sci.getPortal().portal_workflow.accounting_workflow.scripts[script.getId()](sci)
return sci.getPortal().portal_workflow.accounting_workflow.getScriptValueById(script.getId())(sci) return sci.getPortal().portal_workflow.accounting_workflow.scripts[script.getId()](sci)
return state_change.getPortal().portal_workflow.accounting_workflow.getScriptValueById(script.getId())(state_change) return state_change.getPortal().portal_workflow.accounting_workflow.scripts[script.getId()](state_change)
return state_change.getPortal().portal_workflow.accounting_workflow.getScriptValueById(script.getId())(state_change) return state_change.getPortal().portal_workflow.accounting_workflow.scripts[script.getId()](state_change)
...@@ -7,5 +7,4 @@ if old_state.getId() == 'draft': ...@@ -7,5 +7,4 @@ if old_state.getId() == 'draft':
if internal_invoice.InternalInvoiceTransaction_getAuthenticatedUserSection() == internal_invoice.getDestinationSection(): if internal_invoice.InternalInvoiceTransaction_getAuthenticatedUserSection() == internal_invoice.getDestinationSection():
raise ValidationFailed(translateString("Your entity should not be destination.")) raise ValidationFailed(translateString("Your entity should not be destination."))
script = state_change.getPortal().portal_workflow.accounting_workflow.getScriptValueById(script.getId()) return state_change.getPortal().portal_workflow.accounting_workflow.scripts[script.getId()](state_change)
return script(state_change)
...@@ -344,7 +344,8 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow): ...@@ -344,7 +344,8 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
# between here and when the interaction was executed... So we # between here and when the interaction was executed... So we
# need to switch to the security manager as it was back then # need to switch to the security manager as it was back then
setSecurityManager(security_manager) setSecurityManager(security_manager)
self._getOb(script_name)(sci) script_context = self._asScriptContext()
getattr(script_context, script_name)(sci)
finally: finally:
setSecurityManager(current_security_manager) setSecurityManager(current_security_manager)
......
...@@ -52,7 +52,7 @@ from Products.ERP5Type.id_as_reference import IdAsReferenceMixin ...@@ -52,7 +52,7 @@ from Products.ERP5Type.id_as_reference import IdAsReferenceMixin
from Products.ERP5Type.patches.DCWorkflow import _marker from Products.ERP5Type.patches.DCWorkflow import _marker
from Products.ERP5Type.patches.WorkflowTool import SECURITY_PARAMETER_ID,\ from Products.ERP5Type.patches.WorkflowTool import SECURITY_PARAMETER_ID,\
WORKLIST_METADATA_KEY WORKLIST_METADATA_KEY
from Products.ERP5Type.Utils import UpperCase, convertToMixedCase from Products.ERP5Type.Utils import UpperCase, convertToMixedCase, deprecated
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
#from Products.ERP5Workflow.Document.Transition import TRIGGER_AUTOMATIC,\ #from Products.ERP5Workflow.Document.Transition import TRIGGER_AUTOMATIC,\
...@@ -1416,6 +1416,8 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -1416,6 +1416,8 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
the same purpose, but it was heavyweight: doing a lot of useless the same purpose, but it was heavyweight: doing a lot of useless
operations (each time, it was checking for script_foo, even if foo was a operations (each time, it was checking for script_foo, even if foo was a
transition, state, ...) transition, state, ...)
TODO-ARNAU: Should it be cached somewhere?
""" """
script_context = self.asContext() script_context = self.asContext()
# asContext creates a temporary object and temporary object's "activate" # asContext creates a temporary object and temporary object's "activate"
...@@ -1424,13 +1426,24 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -1424,13 +1426,24 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
# this, we override the temporary object's "activate" method with the one of # this, we override the temporary object's "activate" method with the one of
# the original object. # the original object.
script_context.activate = self.activate script_context.activate = self.activate
script_prefix_len = len(SCRIPT_PREFIX) for script in self.objectValues(portal_type="Workflow Script"):
for script_id in self.objectIds(meta_type="ERP5 Python Script"): setattr(script_context, script.getReference(), script)
if script_id.startswith(SCRIPT_PREFIX):
script = getattr(script_context, script_id)
setattr(script_context, script_id[script_prefix_len:], script)
return script_context return script_context
security.declareProtected(Permissions.AccessContentsInformation,
'scripts')
@property
@deprecated
def scripts(self):
"""
Backward compatibility with DC Workflow to avoid modifying existing Python
Script code
"""
script_dict = {}
for script in self.objectValues(portal_type="Workflow Script"):
script_dict[script.getReference()] = script
return script_dict
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getSourceValue') 'getSourceValue')
def getSourceValue(self): def getSourceValue(self):
......
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