Commit 96c10a67 authored by Łukasz Nowak's avatar Łukasz Nowak Committed by Alain Takoudjou

Update Open Order simulation in alarm.

Also minimise activity hurricane by calling expand directly.

Open Orders are searched using indexation timestamp, which allows to see them
in "windows", and does not repeat expand if not needed.

Conflicts:
	bt5/erp5_open_trade/SkinTemplateItem/portal_skins/erp5_open_trade/OpenOrder_updateSimulation.xml
	bt5/erp5_open_trade/bt/revision
parent b9f0e215
<?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_updateOpenOrderSimulation</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>update_open_order_simulation</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>Updates Open Orders Simulation</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[
kw = {}\n
\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().getRelativeUrl()\n
\n
portal = context.getPortalObject()\n
\n
kw[\'portal_type\'] = portal.getPortalOpenOrderTypeList()\n
\n
portal.portal_catalog.searchAndActivate(\n
method_id=\'OpenOrder_updateSimulation\', # XXX: OpenOrder_updateSimulation can generate big transaction...\n
method_kw={\'activity\': False},\n
activate_kw={\'tag\':tag},\n
**kw # XXX: In one query put parents of last modified lines\n
)\n
\n
# make alarm run once at 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_updateOpenOrderSimulation</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -52,18 +52,31 @@ ...@@ -52,18 +52,31 @@
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>subscription_item_set = set()\n <value> <string>subscription_item_set = set()\n
\n \n
for open_order_line in context.objectValues():\n for open_order_line in context.contentValues():\n
for ob in [open_order_line] + open_order_line.getCellValueList():\n for path in [open_order_line] + open_order_line.getCellValueList():\n
for item in ob.getAggregateValueList():\n for item in path.getAggregateValueList():\n
if getattr(item.aq_explicit, \'updateSimulation\', None) is not None and \\\n if item.providesIExpandableItem(): # XXX hack to make it fails\n
item not in subscription_item_set:\n subscription_item_dict[item] = 1\n
subscription_item_set.add(item)\n \n
item.updateSimulation(expand_root=1)\n # XXX tag / after tag !\n
for item in subscription_item_dict:\n
activate_kw = dict(tag=\'%s_expand\' % item.getPath())\n
applied_rule = item.getCausalityRelatedValue(portal_type=\'Applied Rule\')\n
if applied_rule is not None:\n
if activity:\n
applied_rule.activate(activate_kw=activate_kw).expand(activate_kw=activate_kw)\n
else:\n
applied_rule.expand(activate_kw=activate_kw)\n
else:\n
if activity:\n
item.activate(activate_kw=activate_kw).expand(activate_kw=activate_kw)\n
else:\n
item.expand(activate_kw=activate_kw)\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string>activity=True</string> </value>
</item> </item>
<item> <item>
<key> <string>_proxy_roles</string> </key> <key> <string>_proxy_roles</string> </key>
......
portal_alarms/update_open_order_simulation
\ 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