Commit 34925c08 authored by Łukasz Nowak's avatar Łukasz Nowak

Use Hosting Subscription as OSO update condition.

Trigger Open Sale Order update in case of:
  * validated Hosting Subscription without validated OSO Line
  * archived Hosting Subscription without invalidated OSO Line

Trigger change on Person level by using scripts which are locking themselves,
so only one will run per Person.

As alarm is not critical for system operations run it only once by hour.
parent 7dcdc20f
No related merge requests found
......@@ -8,7 +8,7 @@
<dictionary>
<item>
<key> <string>active_sense_method_id</string> </key>
<value> <string>Alarm_updatePersonOpenSaleOrder</string> </value>
<value> <string>Alarm_requestUpdateHostingSubscriptionOpenSaleOrder</string> </value>
</item>
<item>
<key> <string>description</string> </key>
......@@ -22,7 +22,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_person_update_open_sale_order</string> </value>
<value> <string>slapos_request_update_hosting_subscription_open_sale_order</string> </value>
</item>
<item>
<key> <string>periodicity_hour</string> </key>
......@@ -30,15 +30,23 @@
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_hour_frequency</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>periodicity_minute</string> </key>
<value>
<tuple/>
<tuple>
<int>0</int>
</tuple>
</value>
</item>
<item>
<key> <string>periodicity_minute_frequency</string> </key>
<value> <int>1</int> </value>
<value>
<none/>
</value>
</item>
<item>
<key> <string>periodicity_month</string> </key>
......@@ -83,7 +91,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Updates Persons\' Open Order to reflect changes</string> </value>
<value> <string>Updates Open Sale Order for Hosting Subscription which does not have correct OSO</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -50,29 +50,15 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>if params is None:\n
params = {}\n
kw = {}\n
search_kw = {}\n
from DateTime import DateTime\n
from Products.ZSQLCatalog.SQLCatalog import Query\n
from Products.ERP5Type.DateUtils import addToDate\n
<value> <string>portal = context.getPortalObject()\n
path_list = [q.PATH for q in portal.Base_getHostingSubscriptionForOpenSaleOrderLine(hosting_subscription_validation_state=\'validated\', open_sale_order_line_validation_state=\'validated\')]\n
path_list.extend([q.PATH for q in portal.Base_getHostingSubscriptionForOpenSaleOrderLine(hosting_subscription_validation_state=\'archived\', open_sale_order_line_validation_state=\'invalidated\')])\n
\n
last_active_process = context.getLastActiveProcess()\n
if last_active_process is not None and not(params.get(\'full\', False)):\n
# fetch only objects modified since last alarm run\n
kw[\'modification_date\'] = last_active_process.getStartDate()\n
search_kw[\'modification_date\'] = Query(modification_date=addToDate(last_active_process.getStartDate(), to_add={\'hour\': -1}), range="min")\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=\'Person_storeOpenSaleOrderJournal\',\n
method_kw={\'modification_date\': kw.get(\'modification_date\'), \'tag\': tag, \'stop_date\': params.get(\'stop_date\')},\n
portal.portal_catalog.searchAndActivate(\n
method_id=\'HostingSubscription_requestUpdateOpenSaleOrder\',\n
path=path_list,\n
activate_kw={\'tag\': tag},\n
packet_size=1, # Person_storeOpenSaleOrderJournal generates big transactions\n
portal_type=\'Person\',\n
**search_kw\n
packet_size=1, # HostingSubscription_trigger_Person_storeOpenSaleOrderJournal\n
)\n
\n
context.activate(after_tag=tag).getId()\n
......@@ -84,7 +70,7 @@ context.activate(after_tag=tag).getId()\n
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Alarm_updatePersonOpenSaleOrder</string> </value>
<value> <string>Alarm_requestUpdateHostingSubscriptionOpenSaleOrder</string> </value>
</item>
</dictionary>
</pickle>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="SQL" module="Products.ZSQLMethods.SQL"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>allow_simple_one_argument_traversal</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>arguments_src</string> </key>
<value> <string>hosting_subscription_validation_state\r\n
open_sale_order_line_validation_state</string> </value>
</item>
<item>
<key> <string>cache_time_</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>class_file_</string> </key>
<value> <string>ZSQLCatalog.zsqlbrain</string> </value>
</item>
<item>
<key> <string>class_name_</string> </key>
<value> <string>ZSQLBrain</string> </value>
</item>
<item>
<key> <string>connection_hook</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>connection_id</string> </key>
<value> <string>erp5_sql_connection</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getHostingSubscriptionForOpenSaleOrderLine</string> </value>
</item>
<item>
<key> <string>max_cache_</string> </key>
<value> <int>100</int> </value>
</item>
<item>
<key> <string>max_rows_</string> </key>
<value> <int>1000</int> </value>
</item>
<item>
<key> <string>src</string> </key>
<value> <string encoding="cdata"><![CDATA[
SELECT\n
catalog.uid, catalog.path\n
FROM catalog\n
LEFT JOIN category ON category.category_uid=catalog.uid AND category.base_category_uid=1229\n
LEFT JOIN catalog AS order_catalog ON order_catalog.uid=category.uid AND order_catalog.portal_type=\'Open Sale Order Line\' AND order_catalog.validation_state=<dtml-sqlvar open_sale_order_line_validation_state type="string">\n
WHERE catalog.portal_type=\'Hosting Subscription\' and catalog.validation_state=<dtml-sqlvar hosting_subscription_validation_state type="string">\n
GROUP BY catalog.uid\n
having count(order_catalog.uid) = 0\n
]]></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></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>person = context.getDestinationSectionValue()\n
if person is not None:\n
person.Person_storeOpenSaleOrderJournal()\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>HostingSubscription_requestUpdateOpenSaleOrder</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
3
\ No newline at end of file
4
\ No newline at end of file
......@@ -3,7 +3,7 @@ organisation_module/vifib_client_A/**
organisation_module/vifib_internet
organisation_module/vifib_internet/1
organisation_module/vifib_internet/bank_account
portal_alarms/slapos_person_update_open_sale_order
portal_alarms/slapos_request_update_hosting_subscription_open_sale_order
purchase_trade_condition_module/vifib_purchase_trade_condition
purchase_trade_condition_module/vifib_purchase_trade_condition/**
sale_trade_condition_module/vifib_trade_condition
......
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