Commit db92c85b authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_subscription_request: Deliver all events from closed Subscription Requests

   On final state, we just deliver all stopped events related to Subscription Requests.

   While the Subscription is submitted, the events will be kept stopped,
   so the manager (accountant/sale) can have it on their worklists.

   Add tests for new alarm

   Invoke alarm to deliver related events, whenever the Susbscription
   Request is invalidated (end of life).
parent 8fcb03d5
...@@ -10,3 +10,6 @@ if ticket.getPortalType() == 'Support Request': ...@@ -10,3 +10,6 @@ if ticket.getPortalType() == 'Support Request':
elif ticket.getPortalType() == 'Regularisation Request': elif ticket.getPortalType() == 'Regularisation Request':
return event.Base_reindexAndSenseAlarm( return event.Base_reindexAndSenseAlarm(
['slapos_crm_check_stopped_event_from_regularisation_request_to_deliver']) ['slapos_crm_check_stopped_event_from_regularisation_request_to_deliver'])
elif ticket.getPortalType() == 'Subscription Request':
return event.Base_reindexAndSenseAlarm(
['slapos_subscription_check_stopped_event_from_subscription_request_to_deliver'])
...@@ -32,6 +32,12 @@ ...@@ -32,6 +32,12 @@
</tuple> </tuple>
</value> </value>
</item> </item>
<item>
<key> <string>comment</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>default_reference</string> </key> <key> <string>default_reference</string> </key>
<value> <string>ticket_workflow</string> </value> <value> <string>ticket_workflow</string> </value>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Alarm" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>active_sense_method_id</string> </key>
<value> <string>Alarm_checkStoppedEventFromSubscriptionRequestToDeliver</string> </value>
</item>
<item>
<key> <string>automatic_solve</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_subscription_check_stopped_event_from_subscription_request_to_deliver</string> </value>
</item>
<item>
<key> <string>periodicity_hour</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_hour_frequency</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>periodicity_minute</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_minute_frequency</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>periodicity_month</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_month_day</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_month_frequency</string> </key>
<value> <int>12</int> </value>
</item>
<item>
<key> <string>periodicity_start_date</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="DateTime" module="DateTime.DateTime"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<tuple>
<float>1288051200.0</float>
<string>GMT</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>periodicity_week</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Alarm</string> </value>
</item>
<item>
<key> <string>sense_method_id</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Check stopped event from subscription request to deliver</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject()
activate_kw = {'tag': tag}
portal.portal_catalog.searchAndActivate(
portal_type=portal.getPortalEventTypeList(),
simulation_state='stopped',
follow_up__portal_type='Subscription Request',
method_id='Event_checkStoppedFromSubscriptionRequestToDeliver',
method_kw={'activate_kw': activate_kw},
activate_kw=activate_kw
)
context.activate(after_tag=tag).getId()
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>_params</string> </key>
<value> <string>tag, fixit, params</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Alarm_checkStoppedEventFromSubscriptionRequestToDeliver</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
event = context
if event.getSimulationState() != 'stopped':
return
ticket = event.getFollowUpValue(portal_type='Subscription Request')
if ticket is None:
# No ticket, don't try doing anything
return
if ticket.getSimulationState() != 'invalidated':
# Only deliver after ticket is closed.
return
comment = 'Ticket was invalidated'
event.deliver(comment=comment)
event.reindexObject(activate_kw=activate_kw)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>_params</string> </key>
<value> <string>activate_kw=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Event_checkStoppedFromSubscriptionRequestToDeliver</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
# #
############################################################################## ##############################################################################
from erp5.component.test.SlapOSTestCaseMixin import \ from erp5.component.test.SlapOSTestCaseMixin import \
SlapOSTestCaseMixin SlapOSTestCaseMixin, TemporaryAlarmScript, SlapOSTestCaseMixinWithAbort
import time
class TestSlapOSSubscriptionRequestProcessAlarm(SlapOSTestCaseMixin): class TestSlapOSSubscriptionRequestProcessAlarm(SlapOSTestCaseMixin):
...@@ -134,3 +135,109 @@ class TestSlapOSSubscriptionChangeRequestValidateAlarm(SlapOSTestCaseMixin): ...@@ -134,3 +135,109 @@ class TestSlapOSSubscriptionChangeRequestValidateAlarm(SlapOSTestCaseMixin):
subscription_request = self._createSubscriptionChangeRequest() subscription_request = self._createSubscriptionChangeRequest()
self.portal.portal_workflow._jumpToStateFor(subscription_request, 'submitted') self.portal.portal_workflow._jumpToStateFor(subscription_request, 'submitted')
self._test_alarm(alarm, subscription_request, script_name) self._test_alarm(alarm, subscription_request, script_name)
class TestSlaposCrmCheckStoppedEventFromSubscriptionRequestToDeliver(SlapOSTestCaseMixinWithAbort):
event_portal_type = 'Web Message'
def _createSubscriptionRequest(self):
return self.portal.subscription_request_module.newContent(
portal_type='Subscription Request',
title="Test subscription %s" % (self.generateNewId())
)
def _makeEvent(self, follow_up_value):
new_id = self.generateNewId()
return self.portal.event_module.newContent(
portal_type=self.event_portal_type,
title='Test %s %s' % (self.event_portal_type, new_id),
follow_up_value=follow_up_value
)
def test_Event_checkStoppedFromSubscriptionRequestToDeliver_alarm_stopped(self):
subscription_request = self._createSubscriptionRequest()
event = self._makeEvent(subscription_request)
event.stop()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm',
"'disabled'", attribute='comment'):
self.tic()
alarm = self.portal.portal_alarms.\
slapos_subscription_check_stopped_event_from_subscription_request_to_deliver
self._test_alarm(alarm, event, "Event_checkStoppedFromSubscriptionRequestToDeliver")
def test_Event_checkStoppedFromSubscriptionRequestToDeliver_alarm_delivered(self):
subscription_request = self._createSubscriptionRequest()
event = self._makeEvent(subscription_request)
event.stop()
event.deliver()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm',
"'disabled'", attribute='comment'):
self.tic()
alarm = self.portal.portal_alarms.\
slapos_subscription_check_stopped_event_from_subscription_request_to_deliver
self._test_alarm_not_visited(alarm, event,
"Event_checkStoppedFromSubscriptionRequestToDeliver")
def test_Event_checkStoppedFromSubscriptionRequestToDeliver_alarm_stoppedWithoutTicket(self):
subscription_request = self._createSubscriptionRequest()
event = self._makeEvent(subscription_request)
event.setFollowUp(None)
event.stop()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm',
"'disabled'", attribute='comment'):
self.tic()
alarm = self.portal.portal_alarms.\
slapos_subscription_check_stopped_event_from_subscription_request_to_deliver
self._test_alarm_not_visited(alarm, event,
"Event_checkStoppedFromSubscriptionRequestToDeliver")
def test_Event_checkStoppedFromSubscriptionRequestToDeliver_script_invalidatedTicket(self):
subscription_request = self._createSubscriptionRequest()
subscription_request.validate()
subscription_request.invalidate()
self.tic()
time.sleep(1)
event = self._makeEvent(subscription_request)
event.stop()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm',
"'disabled'", attribute='comment'):
self.tic()
self.assertEqual(event.getSimulationState(), "stopped")
self.assertEqual(subscription_request.getSimulationState(), "invalidated")
event.Event_checkStoppedFromSubscriptionRequestToDeliver()
self.assertEqual(event.getSimulationState(), "delivered")
self.assertEqual(subscription_request.getSimulationState(), "invalidated")
def test_Event_checkStoppedFromSubscriptionRequestToDeliver_script_validatedTicket(self):
subscription_request = self._createSubscriptionRequest()
subscription_request.validate()
self.tic()
time.sleep(1)
event = self._makeEvent(subscription_request)
event.stop()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm',
"'disabled'", attribute='comment'):
self.tic()
self.assertEqual(event.getSimulationState(), "stopped")
self.assertEqual(subscription_request.getSimulationState(), "validated")
event.Event_checkStoppedFromSubscriptionRequestToDeliver()
self.assertEqual(event.getSimulationState(), "stopped")
self.assertEqual(subscription_request.getSimulationState(), "validated")
def test_Event_checkStoppedFromSubscriptionRequestToDeliver_script_suspendedTicket(self):
subscription_request = self._createSubscriptionRequest()
subscription_request.validate()
subscription_request.suspend()
self.tic()
time.sleep(1)
event = self._makeEvent(subscription_request)
event.stop()
with TemporaryAlarmScript(self.portal, 'Base_reindexAndSenseAlarm',
"'disabled'", attribute='comment'):
self.tic()
self.assertEqual(event.getSimulationState(), "stopped")
self.assertEqual(subscription_request.getSimulationState(), "suspended")
event.Event_checkStoppedFromSubscriptionRequestToDeliver()
self.assertEqual(event.getSimulationState(), "stopped")
self.assertEqual(subscription_request.getSimulationState(), "suspended")
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Interaction Workflow Interaction" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>after_script/portal_workflow/slapos_subscription_request_interaction_workflow/script_Base_triggerCheckStoppedEventToDeliver</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>interaction_SubscriptionRequest_invalidate</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Interaction Workflow Interaction</string> </value>
</item>
<item>
<key> <string>portal_type_filter</string> </key>
<value>
<tuple>
<string>Subscription Request</string>
</tuple>
</value>
</item>
<item>
<key> <string>portal_type_group_filter</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>SubscriptionRequest_invalidate</string> </value>
</item>
<item>
<key> <string>trigger_method_id</string> </key>
<value>
<tuple>
<string>invalidate</string>
</tuple>
</value>
</item>
<item>
<key> <string>trigger_once_per_transaction</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
return state_change['object'].Base_reindexAndSenseAlarm(
['slapos_subscription_check_stopped_event_from_subscription_request_to_deliver'])
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Workflow Script" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>_params</string> </key>
<value> <string>state_change</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>script_Base_triggerCheckStoppedEventToDeliver</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Workflow Script</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value>
<none/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal_alarms/slapos_subscription_change_request_validate_submitted portal_alarms/slapos_subscription_change_request_validate_submitted
portal_alarms/slapos_subscription_check_stopped_event_from_subscription_request_to_deliver
portal_alarms/slapos_subscription_request_create_from_orphaned_item portal_alarms/slapos_subscription_request_create_from_orphaned_item
portal_alarms/slapos_subscription_request_validate_submitted portal_alarms/slapos_subscription_request_validate_submitted
service_module/slapos_reservation_fee_2 service_module/slapos_reservation_fee_2
\ No newline at end of file
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