Commit 95e98710 authored by Łukasz Nowak's avatar Łukasz Nowak

Improve interactivity.

Whenever planned Sale Order is reindexed try to fire up ordering alarm.
Whenever ordered Sale Order is reindexed try to fire up confirming alarm.
Whenever Hosting Subscription is reindexed try to fire up update open order alarm.
In all cases obey alarm configuration (if it is subscribed, if alarm is active,
if is not running).

Whenever item is reindexed (Software Instance, Slave Instance, Software
Installation or Computer Partition) try to register recalculation of related
computer cache.

In neither case try to be "smart" (eg. waiting for reindexation to finish) as
this code just tries to speed up the system, it cannot achieve synchronism of
updates.
parent 5f74af39
import hashlib import hashlib
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
from AccessControl.SecurityManagement import getSecurityManager, \
setSecurityManager, newSecurityManager
def getSha512Hexdiest(s): def getSha512Hexdiest(s):
return hashlib.sha512(s).hexdigest() return hashlib.sha512(s).hexdigest()
@UnrestrictedMethod
def getComputerReference(item):
portal_type = item.getPortalType()
computer = None
if portal_type == 'Software Installation':
computer = item.getAggregateValue(portal_type='Computer')
elif portal_type == 'Computer Partition':
computer = item.getParentValue()
elif portal_type in ['Software Instance', 'Slave Instance']:
partition = item.getAggregateValue(portal_type='Computer Partition')
if partition is not None:
computer = partition.getParentValue()
if computer is not None and computer.getValidationState() == 'validated':
return computer.getReference()
return None
def Item_activateFillComputerInformationCache(state_change):
item = state_change['object']
portal = item.getPortalObject()
computer_reference = getComputerReference(item)
if computer_reference is None:
return None
sm = getSecurityManager()
try:
newSecurityManager(None,
portal.acl_users.getUserById(computer_reference))
for full in (True, False):
portal.portal_slap._activateFillComputerInformationCache(
computer_reference, computer_reference, full)
finally:
setSecurityManager(sm)
...@@ -35,6 +35,10 @@ ...@@ -35,6 +35,10 @@
<type>Sale Invoice Transaction</type> <type>Sale Invoice Transaction</type>
<workflow>slap_interaction_workflow</workflow> <workflow>slap_interaction_workflow</workflow>
</chain> </chain>
<chain>
<type>Sale Order</type>
<workflow>slap_interaction_workflow</workflow>
</chain>
<chain> <chain>
<type>Sale Packing List</type> <type>Sale Packing List</type>
<workflow>slap_interaction_workflow</workflow> <workflow>slap_interaction_workflow</workflow>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="InteractionDefinition" module="Products.ERP5.Interaction"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>actbox_category</string> </key>
<value> <string>workflow</string> </value>
</item>
<item>
<key> <string>actbox_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>actbox_url</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>activate_script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>after_script_name</string> </key>
<value>
<list>
<string>HostingSubscription_triggerAlarm</string>
</list>
</value>
</item>
<item>
<key> <string>before_commit_script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>guard</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>HostingSubscription_reindexObject</string> </value>
</item>
<item>
<key> <string>method_id</string> </key>
<value>
<list>
<string>reindexObject</string>
<string>recursiveReindexObject</string>
</list>
</value>
</item>
<item>
<key> <string>once_per_transaction</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>portal_type_filter</string> </key>
<value>
<list>
<string>Hosting Subscription</string>
</list>
</value>
</item>
<item>
<key> <string>script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>temporary_document_disallowed</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="InteractionDefinition" module="Products.ERP5.Interaction"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>actbox_category</string> </key>
<value> <string>workflow</string> </value>
</item>
<item>
<key> <string>actbox_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>actbox_url</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>activate_script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>after_script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>before_commit_script_name</string> </key>
<value>
<list>
<string>Item_activateFillComputerInformationCache</string>
</list>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>guard</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Item_reindexObject</string> </value>
</item>
<item>
<key> <string>method_id</string> </key>
<value>
<list>
<string>reindexObject</string>
<string>recursiveReindexObject</string>
</list>
</value>
</item>
<item>
<key> <string>once_per_transaction</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>portal_type_filter</string> </key>
<value>
<list>
<string>Computer Partition</string>
<string>Slave Instance</string>
<string>Software Installation</string>
<string>Software Instance</string>
</list>
</value>
</item>
<item>
<key> <string>script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>temporary_document_disallowed</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="InteractionDefinition" module="Products.ERP5.Interaction"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>actbox_category</string> </key>
<value> <string>workflow</string> </value>
</item>
<item>
<key> <string>actbox_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>actbox_url</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>activate_script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>after_script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>before_commit_script_name</string> </key>
<value>
<list>
<string>SaleOrder_triggerAlarm</string>
</list>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>guard</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SaleOrder_reindexObject</string> </value>
</item>
<item>
<key> <string>method_id</string> </key>
<value>
<list>
<string>reindexObject</string>
<string>recursiveReindexObject</string>
</list>
</value>
</item>
<item>
<key> <string>once_per_transaction</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>portal_type_filter</string> </key>
<value>
<list>
<string>Sale Order</string>
</list>
</value>
</item>
<item>
<key> <string>script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>temporary_document_disallowed</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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>if alarm.getParentValue().isSubscribed() and not alarm.isActive() and alarm.isEnabled():\n
alarm.activeSense()\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>alarm</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>Alarm_safeTrigger</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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>sale_order = state_change[\'object\']\n
\n
portal = sale_order.getPortalObject()\n
context.Alarm_safeTrigger(portal.portal_alarms.vifib_person_update_open_order)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>state_change</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>HostingSubscription_triggerAlarm</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_function</string> </key>
<value> <string>Item_activateFillComputerInformationCache</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>VifibUtil</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Item_activateFillComputerInformationCache</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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>sale_order = state_change[\'object\']\n
\n
portal = sale_order.getPortalObject()\n
\n
simulation_state = sale_order.getSimulationState()\n
alarm = None\n
if simulation_state == \'planned\':\n
alarm = portal.portal_alarms.order_planned_sale_order\n
elif simulation_state == \'ordered\':\n
alarm = portal.portal_alarms.confirm_ordered_sale_order\n
\n
if alarm is not None:\n
context.Alarm_safeTrigger(alarm)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>state_change</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SaleOrder_triggerAlarm</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
826 827
\ No newline at end of file \ No newline at end of file
...@@ -9,6 +9,7 @@ Person | person_slap_interface_workflow ...@@ -9,6 +9,7 @@ Person | person_slap_interface_workflow
Person | slap_interaction_workflow Person | slap_interaction_workflow
Purchase Packing List | slap_interaction_workflow Purchase Packing List | slap_interaction_workflow
Sale Invoice Transaction | slap_interaction_workflow Sale Invoice Transaction | slap_interaction_workflow
Sale Order | slap_interaction_workflow
Sale Packing List Line | slap_interaction_workflow Sale Packing List Line | slap_interaction_workflow
Sale Packing List | slap_interaction_workflow Sale Packing List | slap_interaction_workflow
Slave Instance | slap_interaction_workflow Slave Instance | slap_interaction_workflow
......
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