Commit 5098f660 authored by Romain Courteaud's avatar Romain Courteaud 🐸

Force open sale order indexation when line is modified.

It is needed by the open order simulation alarm, which uses the indexation
timestamp.
parent da9b1c03
<?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_reindexOpenSaleOrderWithModifiedLine</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>slapos_reindex_open_sale_order</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_hour_frequency</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>periodicity_minute</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_minute_frequency</string> </key>
<value>
<none/>
</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>Reindex open order with modified lines</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
\n
portal.portal_catalog.searchAndActivate(\n
# XXX Filter directly the right open sale order\n
method_id=\'OpenSaleOrder_reindexIfIndexedBeforeLine\',\n
portal_type="Open Sale Order",\n
children_portal_type="Open Sale Order Line",\n
activate_kw={\'tag\': tag},\n
)\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_reindexOpenSaleOrderWithModifiedLine</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>from zExceptions import Unauthorized\n
if REQUEST is not None:\n
raise Unauthorized\n
\n
order = context\n
portal = context.getPortalObject()\n
indexation_timestamp = portal.portal_catalog(\n
uid=order.getUid(),\n
select_dict={\'indexation_timestamp\': None})[0].indexation_timestamp\n
\n
line_list = portal.portal_catalog(\n
portal_type="Open Sale Order Line", \n
parent_uid=order.getUid(),\n
indexation_timestamp={\'query\': indexation_timestamp, \'range\': \'nlt\'},\n
limit=1)\n
\n
if len(line_list):\n
order.activate().immediateReindexObject()\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>OpenSaleOrder_reindexIfIndexedBeforeLine</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -1835,3 +1835,60 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by O
self.assertNotEqual(
'Visited by OpenSaleOrder_updatePeriod',
open_order.workflow_history['edit_workflow'][-1]['comment'])
class TestSlapOSReindexOpenSaleOrder(testSlapOSMixin):
def createOpenOrder(self):
open_order = self.portal.open_sale_order_module\
.slapos_accounting_open_sale_order_template.\
Base_createCloneDocument(batch_mode=1)
open_order.edit(
title=self.generateNewSoftwareTitle(),
reference="TESTHS-%s" % self.generateNewId(),
)
return open_order
def _simulateOpenSaleOrder_reindexIfIndexedBeforeLine(self):
script_name = 'OpenSaleOrder_reindexIfIndexedBeforeLine'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kwargs',
'# Script body\n'
"""portal_workflow = context.portal_workflow
portal_workflow.doActionFor(context, action='edit_action', comment='Visited by OpenSaleOrder_reindexIfIndexedBeforeLine') """ )
transaction.commit()
def _dropOpenSaleOrder_reindexIfIndexedBeforeLine(self):
script_name = 'OpenSaleOrder_reindexIfIndexedBeforeLine'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_alarm(self):
open_order = self.createOpenOrder()
open_order.newContent(portal_type="Open Sale Order Line")
self.tic()
self._simulateOpenSaleOrder_reindexIfIndexedBeforeLine()
try:
self.portal.portal_alarms.slapos_reindex_open_sale_order.activeSense()
self.tic()
finally:
self._dropOpenSaleOrder_reindexIfIndexedBeforeLine()
self.assertEqual(
'Visited by OpenSaleOrder_reindexIfIndexedBeforeLine',
open_order.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_no_line(self):
open_order = self.createOpenOrder()
self.tic()
self._simulateOpenSaleOrder_reindexIfIndexedBeforeLine()
try:
self.portal.portal_alarms.slapos_reindex_open_sale_order.activeSense()
self.tic()
finally:
self._dropOpenSaleOrder_reindexIfIndexedBeforeLine()
self.assertNotEqual(
'Visited by OpenSaleOrder_reindexIfIndexedBeforeLine',
open_order.workflow_history['edit_workflow'][-1]['comment'])
......@@ -9,6 +9,7 @@ from Products.SlapOS.tests.testSlapOSMixin import \
testSlapOSMixin, withAbort
from zExceptions import Unauthorized
from DateTime import DateTime
import time
class TestSlapOSAccounting(testSlapOSMixin):
......@@ -20,6 +21,14 @@ class TestSlapOSAccounting(testSlapOSMixin):
reference="TESTHS-%s" % new_id,
)
def createOpenSaleOrder(self):
new_id = self.generateNewId()
return self.portal.open_sale_order_module.newContent(
portal_type='Open Sale Order',
title="OpenSaleOrder %s" % new_id,
reference="TESTOSO-%s" % new_id,
)
@withAbort
def test_Service_getPriceCalculationOperandDict(self):
service = self.portal.service_module.newContent(portal_type='Service')
......@@ -123,3 +132,64 @@ class TestSlapOSAccounting(testSlapOSMixin):
item.workflow_history['instance_slap_interface_workflow'] = []
date = item.HostingSubscription_calculateSubscriptionStopDate()
self.assertEqual(date, None)
def test_OpenSaleOrder_reindexIfIndexedBeforeLine_no_line(self):
portal = self.portal
order = self.createOpenSaleOrder()
self.tic()
indexation_timestamp = portal.portal_catalog(
uid=order.getUid(),
select_dict={'indexation_timestamp': None})[0].indexation_timestamp
order.OpenSaleOrder_reindexIfIndexedBeforeLine()
self.tic()
new_indexation_timestamp = portal.portal_catalog(
uid=order.getUid(),
select_dict={'indexation_timestamp': None})[0].indexation_timestamp
self.assertEquals(new_indexation_timestamp,
indexation_timestamp)
def test_OpenSaleOrder_reindexIfIndexedBeforeLine_line_indexed_after(self):
portal = self.portal
order = self.createOpenSaleOrder()
line = order.newContent(portal_type="Open Sale Order Line")
self.tic()
line.activate().immediateReindexObject()
# XXX One more kitten killed
time.sleep(1)
self.tic()
indexation_timestamp = portal.portal_catalog(
uid=order.getUid(),
select_dict={'indexation_timestamp': None})[0].indexation_timestamp
order.OpenSaleOrder_reindexIfIndexedBeforeLine()
self.tic()
new_indexation_timestamp = portal.portal_catalog(
uid=order.getUid(),
select_dict={'indexation_timestamp': None})[0].indexation_timestamp
self.assertNotEquals(new_indexation_timestamp,
indexation_timestamp)
def test_OpenSaleOrder_reindexIfIndexedBeforeLine_line_indexed_before(self):
portal = self.portal
order = self.createOpenSaleOrder()
line = order.newContent(portal_type="Open Sale Order Line")
self.tic()
order.activate().immediateReindexObject()
# XXX One more kitten killed
time.sleep(1)
self.tic()
indexation_timestamp = portal.portal_catalog(
uid=order.getUid(),
select_dict={'indexation_timestamp': None})[0].indexation_timestamp
order.OpenSaleOrder_reindexIfIndexedBeforeLine()
self.tic()
new_indexation_timestamp = portal.portal_catalog(
uid=order.getUid(),
select_dict={'indexation_timestamp': None})[0].indexation_timestamp
self.assertEquals(new_indexation_timestamp,
indexation_timestamp)
def test_OpenSaleOrder_reindexIfIndexedBeforeLine_REQUEST_disallowed(self):
self.assertRaises(
Unauthorized,
self.portal.OpenSaleOrder_reindexIfIndexedBeforeLine,
REQUEST={})
251
\ No newline at end of file
252
\ No newline at end of file
......@@ -24,6 +24,7 @@ organisation_module/slapos/bank_account
portal_alarms/slapos_deliver_confirmed_aggregated_sale_packing_list
portal_alarms/slapos_instance_invoicing
portal_alarms/slapos_manage_building_calculating_delivery
portal_alarms/slapos_reindex_open_sale_order
portal_alarms/slapos_remove_bogus_delivery_link
portal_alarms/slapos_request_update_hosting_subscription_open_sale_order
portal_alarms/slapos_stop_confirmed_aggregated_sale_invoice_transaction
......
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