Commit 2432350b authored by Łukasz Nowak's avatar Łukasz Nowak

Clone too old cleanup deliveries.

It might happen that something else is newer then cleanup delivery (eg. because
of user was able to ask to stop/start just after cleanup).

So clone currently waiting cleanup delivery with date newer then previous one
and replace it. Thanks to this instance destruction will be possible.
parent 25425df9
<?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_cloneCleanupPartition</string> </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>vifib_clone_destroy_partition</string> </value>
</item>
<item>
<key> <string>periodicity_day_frequency</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>periodicity_hour</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_minute</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_minute_frequency</string> </key>
<value> <int>5</int> </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_start_date</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>3660.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>title</string> </key>
<value> <string>Clone destroy partition</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>portal = context.getPortalObject()\n
cleanup_service = portal.portal_preferences.getPreferredInstanceCleanupResource()\n
\n
portal.portal_catalog.searchAndActivate(\n
portal_type=\'Sale Packing List Line\',\n
default_resource_uid=portal.restrictedTraverse(cleanup_service).getUid(),\n
aggregate_portal_type="Software Instance",\n
simulation_state="confirmed",\n
method_id=\'SalePackingListLine_checkAndCloneCleanupPartition\',\n
activate_kw={\'tag\': tag}\n
)\n
\n
# Register activity in order to have only one alarm running in the same time\n
context.activate(after_tag=tag).getId()\n
</string> </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_cloneCleanupPartition</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 encoding="cdata"><![CDATA[
from Products.ZSQLCatalog.SQLCatalog import Query, NegatedQuery\n
from DateTime import DateTime\n
movement = context\n
portal = movement.getPortalObject()\n
cleanup_service = portal.portal_preferences.getPreferredInstanceCleanupResource()\n
\n
instance = movement.getAggregateValue(portal_type="Software Instance")\n
# Search for other cleanup packing list (generated by UI double click for\n
# example)\n
newer_movement = portal.portal_catalog.getResultValue(\n
portal_type="Sale Packing List Line",\n
default_resource_uid=portal.restrictedTraverse(cleanup_service).getUid(),\n
default_aggregate_uid=instance.getUid(),\n
uid=NegatedQuery(Query(uid=movement.getUid())),\n
simulation_state="confirmed",\n
**{\'movement.start_date\': Query(**{\'movement.start_date\': movement.getStartDate(), \'range\': \'min\'})}\n
)\n
\n
if (newer_movement is not None) and (newer_movement.getSimulationState() == \'confirmed\'):\n
# another cleanup packing list was found, cannot clone\n
return\n
\n
# Search for the non cleanup newest packing list which is newer then current cleanup\n
# resource is ignored, as cleanups deliveries are already analysed before\n
newer_newest_movement = portal.portal_catalog.getResultValue(\n
portal_type="Sale Packing List Line",\n
default_aggregate_uid=instance.getUid(),\n
**{\'movement.start_date\': Query(**{\'movement.start_date\': movement.getStartDate(), \'range\': \'max\'})}\n
)\n
\n
if newer_newest_movement is not None:\n
cleanup_delivery = movement.getParentValue()\n
# setup new cleanup date to now, as it will be newer then any existing document\n
now = DateTime()\n
if now < newer_newest_movement:\n
raise ValueError(\'The movement %s is newer then current time %s so it is impossible to move delivery %s as newer\' % (newer_newest_movement.getRelativeUrl(), now, cleanup_delivery.getRelativeUrl()))\n
new_cleanup_delivery = cleanup_delivery.Base_createCloneDocument(batch_mode=1)\n
new_cleanup_delivery.setStartDate(DateTime())\n
cleanup_delivery.cancel(comment=\'Cancelled as newer clone is created: %s\' % new_cleanup_delivery.getPath())\n
new_cleanup_delivery.confirm(comment=\'Replaced too old cleanup delivery: %s\' % cleanup_delivery.getPath())\n
]]></string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SalePackingListLine_checkAndCloneCleanupPartition</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
587
\ No newline at end of file
588
\ No newline at end of file
......@@ -5,6 +5,7 @@ portal_alarms/stop_confirmed_sale_invoice_transaction
portal_alarms/vifib_cancel_destroy_partition
portal_alarms/vifib_cancel_update_partition
portal_alarms/vifib_check_consistency
portal_alarms/vifib_clone_destroy_partition
portal_alarms/vifib_desactivate_dead_computer
portal_alarms/vifib_destroy_non_instanciated_partition
portal_alarms/vifib_lock_person
......
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