Commit 6db19c30 authored by Łukasz Nowak's avatar Łukasz Nowak

Drop spaghetti again.

Use alarm with "windowing" support to slowly remove not needed lines.
parent 6bdc6943
<?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_removeDestroyedOpenOrderLine</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_remove_destroyed_open_order_line</string> </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>0.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>Removes Open Order Lines for freed partitions</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[
if params is None:\n
params = {}\n
kw = {}\n
last_active_process = context.getLastActiveProcess()\n
\n
if last_active_process is not None and params.get(\'full\', False):\n
# fetch only objects modified since last alarm run\n
kw[\'indexation_timestamp\'] = \'>= %s\' % last_active_process.getStartDate().ISO()\n
\n
# register active process in order to have "windows" of last indexed objects\n
context.newActiveProcess()\n
\n
context.getPortalObject().portal_catalog.searchAndActivate(\n
method_id=\'SalePackingListLine_removeNotNeededOpenSaleOrderLine\',\n
portal_type=\'Sale Packing List Line\',\n
simulation_state=\'delivered\',\n
default_resource_uid=context.restrictedTraverse(context.getPortalObject().portal_preferences.getPreferredInstanceCleanupResource()).getUid(),\n
activity_kw={\'tag\': tag},\n
**kw\n
)\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_removeDestroyedOpenOrderLine</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -50,40 +50,38 @@ ...@@ -50,40 +50,38 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string># As Open Sale Order codebase is unstable Assignor proxied role script is introduced\n <value> <string>from Products.ZSQLCatalog.SQLCatalog import NegatedQuery, Query\n
# to cleanup finialised Open Sale Order Line\n
\n
if REQUEST is not None:\n
# protect against direct HTTP access, XML-RPC will still work\n
raise ValueError(\'Not available\')\n
from Products.ZSQLCatalog.SQLCatalog import NegatedQuery, Query\n
\n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
if not(context.getPortalType() == \'Sale Packing List Line\' \n
and context.getSimulationState() == \'delivered\'\n
and context.getResource() == portal.portal_preferences.getPreferredInstanceCleanupResource()):\n
return\n
all_delivered = True\n all_delivered = True\n
for sale_packing_list_line in portal.portal_catalog(\n for sale_packing_list_line in portal.portal_catalog(\n
portal_type="Sale Packing List Line", \n portal_type="Sale Packing List Line", \n
default_aggregate_uid=context.getUid(),\n default_aggregate_uid=context.getAggregateValue(portal_type=\'Software Instance\').getUid(),\n
simulation_state=NegatedQuery(Query(simulation_state="delivered")),\n simulation_state=NegatedQuery(Query(simulation_state=["delivered", "cancelled"])),\n
):\n ):\n
if sale_packing_list_line.getSimulationState() != \'delivered\':\n if sale_packing_list_line.getSimulationState() not in [\'delivered\', \'cancelled\']:\n
raise ValueError(sale_packing_list_line.getPath())\n raise ValueError(sale_packing_list_line.getPath())\n
all_delivered = False\n all_delivered = False\n
break\n
if all_delivered:\n if all_delivered:\n
for open_order_line in portal.portal_catalog(\n for open_order_line in portal.portal_catalog(\n
default_aggregate_uid=context.getUid(),\n default_aggregate_uid=context.getAggregateValue(portal_type=\'Hosting Subscription\').getUid(),\n
portal_type=\'Open Sale Order Line\',\n portal_type=\'Open Sale Order Line\',\n
validation_state=\'validated\'):\n validation_state=\'validated\'):\n
if open_order_line.getValidationState() == \'validated\':\n if open_order_line.getValidationState() == \'validated\':\n
open_order_line.getParentValue().getDestinationDecisionValue().Person_updateOpenOrder(remove_id=open_order_line.getId())\n open_order_line.getParentValue().getDestinationDecisionValue().Person_updateOpenOrder(remove_id_list=[open_order_line.getId()])\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value> <value> <string></string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>HostingSubscription_removeRelatedOpenSaleOrderLine</string> </value> <value> <string>SalePackingListLine_removeNotNeededOpenSaleOrderLine</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -90,9 +90,6 @@ for sale_packing_list_line in portal.portal_catalog(\n ...@@ -90,9 +90,6 @@ for sale_packing_list_line in portal.portal_catalog(\n
sale_packing_list.deliver()\n sale_packing_list.deliver()\n
if sale_packing_list.getSimulationState() != \'delivered\':\n if sale_packing_list.getSimulationState() != \'delivered\':\n
raise ValueError(\'It was not possible to deliver %r during destruction of %r\' % (sale_packing_list.getRelativeUrl(), software_instance.getRelativeUrl()))\n raise ValueError(\'It was not possible to deliver %r during destruction of %r\' % (sale_packing_list.getRelativeUrl(), software_instance.getRelativeUrl()))\n
# Remove unused open sale order line\n
subscription_item = sale_packing_list_line.getAggregateValue(portal_type="Hosting Subscription")\n
subscription_item.HostingSubscription_removeRelatedOpenSaleOrderLine()\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
......
613 614
\ No newline at end of file \ No newline at end of file
...@@ -10,6 +10,7 @@ portal_alarms/vifib_desactivate_dead_computer ...@@ -10,6 +10,7 @@ portal_alarms/vifib_desactivate_dead_computer
portal_alarms/vifib_destroy_non_instanciated_partition portal_alarms/vifib_destroy_non_instanciated_partition
portal_alarms/vifib_lock_person portal_alarms/vifib_lock_person
portal_alarms/vifib_lock_software_instance portal_alarms/vifib_lock_software_instance
portal_alarms/vifib_remove_destroyed_open_order_line
portal_alarms/vifib_trigger_build portal_alarms/vifib_trigger_build
portal_alarms/vifib_unlock_person portal_alarms/vifib_unlock_person
portal_alarms/vifib_unlock_software_instance portal_alarms/vifib_unlock_software_instance
......
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