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
......@@ -6,10 +6,7 @@ if category_personal is not None:
portal.portal_catalog.searchAndActivate(
portal_type='Computer',
validation_state='validated',
modification_date=(DateTime() - 30).strftime('<=%Y/%m/%d'),
default_allocation_scope_uid=category_personal.getUid(),
left_join_list=['aggregate_related_uid'],
aggregate_related_uid=None,
method_id='Computer_checkAndUpdatePersonalAllocationScope',
activate_kw={'tag': tag})
......
......@@ -31,6 +31,9 @@ if support_request_in_progress is not None:
support_request_in_progress = context.REQUEST.get("support_request_in_progress", None)
if support_request_in_progress is not None:
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.\
......
......@@ -16,22 +16,26 @@ person = computer.getSourceAdministrationValue(portal_type="Person")
if not person:
return
if not person.Person_isServiceProvider():
edit_kw = {
if check_service_provider and person.Person_isServiceProvider():
return
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!
request_title = 'Allocation scope of %s changed to %s' % (computer_reference,
target_allocation_scope)
request_description = 'Allocation scope has been changed to ' \
'%s for %s' % (target_allocation_scope, computer_reference)
support_request = context.Base_generateSupportRequestForSlapOS(
support_request = context.Base_generateSupportRequestForSlapOS(
request_title,
request_description,
computer.getRelativeUrl()
)
if support_request is not None:
if support_request.getSimulationState() != "validated":
support_request.validate()
......@@ -43,6 +47,7 @@ if not person.Person_isServiceProvider():
if notification_message is not None:
mapping_dict = {'computer_title':computer.getTitle(),
'computer_id':computer_reference,
'computer_url':computer.getRelativeUrl(),
'allocation_scope':allocation_scope}
message = notification_message.asText(
......@@ -52,6 +57,15 @@ if not person.Person_isServiceProvider():
request_title, message, person.getRelativeUrl())
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
elif force:
# Update computer event if ticket is not created
computer.edit(**edit_kw)
......@@ -50,7 +50,7 @@
</item>
<item>
<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>
<key> <string>id</string> </key>
......
if context.Computer_hasContactedRecently():
return
return context.Computer_checkAndUpdateAllocationScope(
target_allocation_scope = 'close/termination',
notification_message_reference='slapos-crm-computer_personal_allocation_scope.notification')
target_allocation_scope = 'close/outdated',
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(
text_content=message,
start_date = DateTime(),
resource = resource,
source=source_relative_url,
source=support_request.getSource(),
destination=destination_relative_url,
follow_up=support_request.getRelativeUrl(),
)
event.stop()
......
......@@ -50,7 +50,7 @@
</item>
<item>
<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>
<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