Commit 30017fbb authored by Alain Takoudjou's avatar Alain Takoudjou

slapos_crm: create alarm to close personal computer which didn't contact for too long

Change allocation scope to close/outdated
parent e3376cbf
...@@ -4,12 +4,9 @@ category_personal = portal.restrictedTraverse("portal_categories/allocation_scop ...@@ -4,12 +4,9 @@ category_personal = portal.restrictedTraverse("portal_categories/allocation_scop
if category_personal is not None: if category_personal is not None:
portal.portal_catalog.searchAndActivate( portal.portal_catalog.searchAndActivate(
portal_type='Computer', portal_type='Computer',
validation_state='validated', validation_state='validated',
modification_date=(DateTime() - 30).strftime('<=%Y/%m/%d'), default_allocation_scope_uid=category_personal.getUid(),
default_allocation_scope_uid=category_personal.getUid(),
left_join_list=['aggregate_related_uid'],
aggregate_related_uid=None,
method_id='Computer_checkAndUpdatePersonalAllocationScope', method_id='Computer_checkAndUpdatePersonalAllocationScope',
activate_kw={'tag': tag}) activate_kw={'tag': tag})
......
...@@ -31,7 +31,10 @@ if support_request_in_progress is not None: ...@@ -31,7 +31,10 @@ if support_request_in_progress is not None:
support_request_in_progress = context.REQUEST.get("support_request_in_progress", None) support_request_in_progress = context.REQUEST.get("support_request_in_progress", None)
if support_request_in_progress is not None: if support_request_in_progress is not None:
return portal.restrictedTraverse(support_request_in_progress) support_request = portal.restrictedTraverse(support_request_in_progress)
if support_request.getTitle() == title and \
support_request.getSourceProjectUid() == source_project_value.getUid():
return portal.restrictedTraverse(support_request_in_progress)
resource = portal.service_module.\ resource = portal.service_module.\
slapos_crm_monitoring.getRelativeUrl() slapos_crm_monitoring.getRelativeUrl()
......
...@@ -16,25 +16,29 @@ person = computer.getSourceAdministrationValue(portal_type="Person") ...@@ -16,25 +16,29 @@ person = computer.getSourceAdministrationValue(portal_type="Person")
if not person: if not person:
return return
if not person.Person_isServiceProvider(): if check_service_provider and person.Person_isServiceProvider():
edit_kw = { return
'allocation_scope': target_allocation_scope,
} edit_kw = {
'allocation_scope': target_allocation_scope,
# Create a ticket (or re-open it) for this issue! }
request_title = 'We have changed allocation scope for %s' % computer_reference
request_description = 'Allocation scope has been changed to ' \ # Create a ticket (or re-open it) for this issue!
'%s for %s' % (target_allocation_scope, computer_reference) request_title = 'Allocation scope of %s changed to %s' % (computer_reference,
target_allocation_scope)
support_request = context.Base_generateSupportRequestForSlapOS( request_description = 'Allocation scope has been changed to ' \
request_title, '%s for %s' % (target_allocation_scope, computer_reference)
request_description,
computer.getRelativeUrl()
)
support_request = context.Base_generateSupportRequestForSlapOS(
request_title,
request_description,
computer.getRelativeUrl()
)
if support_request is not None:
if support_request.getSimulationState() != "validated": if support_request.getSimulationState() != "validated":
support_request.validate() support_request.validate()
# Send notification message # Send notification message
message = request_description message = request_description
notification_message = portal.portal_notifications.getDocumentValue( notification_message = portal.portal_notifications.getDocumentValue(
...@@ -43,8 +47,9 @@ if not person.Person_isServiceProvider(): ...@@ -43,8 +47,9 @@ if not person.Person_isServiceProvider():
if notification_message is not None: if notification_message is not None:
mapping_dict = {'computer_title':computer.getTitle(), mapping_dict = {'computer_title':computer.getTitle(),
'computer_id':computer_reference, 'computer_id':computer_reference,
'computer_url':computer.getRelativeUrl(),
'allocation_scope':allocation_scope} 'allocation_scope':allocation_scope}
message = notification_message.asText( message = notification_message.asText(
substitution_method_parameter_dict={'mapping_dict': mapping_dict}) substitution_method_parameter_dict={'mapping_dict': mapping_dict})
...@@ -52,6 +57,15 @@ if not person.Person_isServiceProvider(): ...@@ -52,6 +57,15 @@ if not person.Person_isServiceProvider():
request_title, message, person.getRelativeUrl()) request_title, message, person.getRelativeUrl())
if event is not None: if event is not None:
computer.edit(**edit_kw) # event added, suspend ticket
if portal.portal_workflow.isTransitionPossible(support_request, 'suspend'):
support_request.suspend()
elif not force:
return support_request
computer.edit(**edit_kw)
return support_request return support_request
elif force:
# Update computer event if ticket is not created
computer.edit(**edit_kw)
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>target_allocation_scope=\'open/personal\', notification_message_reference=\'slapos-crm-computer_allocation_scope.notification\'</string> </value> <value> <string>target_allocation_scope=\'open/personal\', notification_message_reference=\'slapos-crm-computer_allocation_scope.notification\', check_service_provider=True, force=False</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
if context.Computer_hasContactedRecently():
return
return context.Computer_checkAndUpdateAllocationScope( return context.Computer_checkAndUpdateAllocationScope(
target_allocation_scope = 'close/termination', target_allocation_scope = 'close/outdated',
notification_message_reference='slapos-crm-computer_personal_allocation_scope.notification') notification_message_reference='slapos-crm-computer-allocation-scope-closed.notification',
check_service_provider=False,
force=True)
portal = context.getPortalObject()
computer = context
maximum_days = 31
now_date = DateTime()
if (now_date - computer.getCreationDate()) < maximum_days:
# This computer was created recently skip
return True
memcached_dict = portal.portal_memcached.getMemcachedDict(
key_prefix='slap_tool',
plugin_path='portal_memcached/default_memcached_plugin')
# Check if there is some information in memcached
try:
d = memcached_dict[computer.getReference()]
except KeyError:
message_dict = {}
else:
message_dict = json.loads(d)
if message_dict.has_key('created_at'):
contact_date = DateTime(message_dict.get('created_at').encode('utf-8'))
return (now_date - contact_date) < maximum_days
# If no memcached, check in consumption report
for sale_packing_list in portal.portal_catalog(
portal_type="Sale Packing List Line",
simulation_state="delivered",
default_aggregate_uid=computer.getUid(),
sort_on=[('movement.start_date', 'DESC')],
limit=1):
return (now_date - sale_packing_list.getStartDate()) < maximum_days
return False
<?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>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Computer_hasContactedRecently</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -20,7 +20,8 @@ event.edit( ...@@ -20,7 +20,8 @@ event.edit(
text_content=message, text_content=message,
start_date = DateTime(), start_date = DateTime(),
resource = resource, resource = resource,
source=source_relative_url, source=support_request.getSource(),
destination=destination_relative_url,
follow_up=support_request.getRelativeUrl(), follow_up=support_request.getRelativeUrl(),
) )
event.stop() event.stop()
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>message_title, message, source_relative_url</string> </value> <value> <string>message_title, message, destination_relative_url</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
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