Commit 7dd086b7 authored by Romain Courteaud's avatar Romain Courteaud

Do not rely on transition to calculate the stop date.

Use the state value only.
Correctly handle destroyed subscription which has never been associated to an
open order.
parent 574fcde7
......@@ -116,7 +116,7 @@ def getHostingSubscriptionSimulationStopDate(hosting_subscription, start_date):\
wf_id=\'instance_slap_interface_workflow\')\n
end_date = now\n
for item in workflow_item_list:\n
if item.get(\'action\') == \'request_destroy\':\n
if item.get(\'slap_state\') == \'destroy_requested\':\n
end_date = item.get(\'time\')\n
break\n
\n
......@@ -189,7 +189,7 @@ if open_sale_order is not None:\n
deleted_hosting_subscription_dict[hosting_subscription.getRelativeUrl()] = None\n
updated_hosting_subscription_dict[hosting_subscription.getRelativeUrl()] = None\n
\n
if hosting_subscription.getCausalityState() == \'diverged\':\n
elif (hosting_subscription.getCausalityState() == \'diverged\'):\n
hosting_subscription.converge(comment="Nothing to do on open order.")\n
updated_hosting_subscription_dict[hosting_subscription.getRelativeUrl()] = None\n
\n
......@@ -214,25 +214,12 @@ for hosting_subscription in portal.portal_catalog(\n
assert (hosting_subscription.getRelativeUrl() in deleted_hosting_subscription_dict) or \\\n
(hosting_subscription.getRelativeUrl() in updated_hosting_subscription_dict)\n
\n
new_open_sale_order = None\n
if (delete_line_list):\n
# All Verifications done. Time to clone/create open order\n
new_open_sale_order = newOpenOrder(open_sale_order)\n
\n
open_order_explanation = ""\n
# Remove lines\n
new_open_sale_order.deleteContent(delete_line_list)\n
open_order_explanation += "Removed %s." % str(delete_line_list)\n
\n
storeWorkflowComment(new_open_sale_order, open_order_explanation)\n
\n
manual_archive = False\n
if (add_line_list):\n
# No need to create a new open order to add lines\n
if (new_open_sale_order) is None:\n
if open_sale_order is None:\n
new_open_sale_order = newOpenOrder(None)\n
else:\n
new_open_sale_order = open_sale_order\n
if open_sale_order is None:\n
open_sale_order = newOpenOrder(None)\n
manual_archive = True\n
\n
open_order_explanation = ""\n
# Add lines\n
......@@ -241,7 +228,7 @@ if (add_line_list):\n
portal.portal_preferences.getPreferredOpenSaleOrderLineTemplate())\n
for hosting_subscription in add_line_list:\n
open_sale_order_line = open_sale_order_line_template.Base_createCloneDocument(batch_mode=1,\n
destination=new_open_sale_order)\n
destination=open_sale_order)\n
start_date = getHostingSubscriptionSimulationStartDate(hosting_subscription)\n
open_sale_order_line.edit(\n
activate_kw=activate_kw,\n
......@@ -251,9 +238,28 @@ if (add_line_list):\n
aggregate_value=hosting_subscription,\n
)\n
storeWorkflowComment(open_sale_order_line, "Created for %s" % hosting_subscription.getRelativeUrl())\n
hosting_subscription.converge(comment="First open order: %s" % open_sale_order_line.getRelativeUrl())\n
if (hosting_subscription.getSlapState() == \'destroy_requested\'):\n
# Added line to delete immediately\n
delete_line_list.append(open_sale_order_line.getId())\n
hosting_subscription.converge(comment="Last open order: %s" % open_sale_order_line.getRelativeUrl())\n
else:\n
hosting_subscription.converge(comment="First open order: %s" % open_sale_order_line.getRelativeUrl())\n
added_line_list.append(open_sale_order_line.getId())\n
open_order_explanation += "Added %s." % str(added_line_list)\n
\n
new_open_sale_order = None\n
if (delete_line_list):\n
# All Verifications done. Time to clone/create open order\n
new_open_sale_order = newOpenOrder(open_sale_order)\n
if manual_archive == True:\n
open_sale_order.archive()\n
\n
open_order_explanation = ""\n
# Remove lines\n
new_open_sale_order.deleteContent(delete_line_list)\n
open_order_explanation += "Removed %s." % str(delete_line_list)\n
\n
storeWorkflowComment(new_open_sale_order, open_order_explanation)\n
]]></string> </value>
......
......@@ -964,9 +964,10 @@ class TestHostingSubscription_requestUpdateOpenSaleOrder(testSlapOSMixin):
default_destination_uid=person.getUid()
)
self.assertEqual(1, len(open_sale_order_list))
open_sale_order = open_sale_order_list[0].getObject()
self.assertEqual('validated', open_sale_order.getValidationState())
self.assertEqual(2, len(open_sale_order_list))
open_sale_order = [x for x in open_sale_order_list \
if x.getValidationState() != 'validated'][0].getObject()
self.assertEqual('archived', open_sale_order.getValidationState())
open_sale_order_line_list = open_sale_order.contentValues(
portal_type='Open Sale Order Line')
......@@ -992,6 +993,13 @@ class TestHostingSubscription_requestUpdateOpenSaleOrder(testSlapOSMixin):
stop_date = addToDate(stop_date, to_add={'month': 1})
self.assertEqual(stop_date, line.getStopDate())
new_open_sale_order = [x for x in open_sale_order_list \
if x.getValidationState() == 'validated'][0].getObject()
self.assertEqual('validated', new_open_sale_order.getValidationState())
open_sale_order_line_list = new_open_sale_order.contentValues(
portal_type='Open Sale Order Line')
self.assertEqual(0, len(open_sale_order_line_list))
def test_two_HostingSubscription(self):
person = self.portal.person_module.template_member\
.Base_createCloneDocument(batch_mode=1)
......@@ -1205,6 +1213,59 @@ class TestHostingSubscription_requestUpdateOpenSaleOrder(testSlapOSMixin):
self.tic()
self.assertEqual(subscription.getCausalityState(), 'solved')
def test_empty_destroyed_HostingSubscription(self):
person = self.portal.person_module.template_member\
.Base_createCloneDocument(batch_mode=1)
self.tic()
subscription = self.portal.hosting_subscription_module\
.template_hosting_subscription.Base_createCloneDocument(batch_mode=1)
subscription.edit(reference='TESTHS-%s' % self.generateNewId(),
destination_section=person.getRelativeUrl())
self.portal.portal_workflow._jumpToStateFor(subscription, 'validated')
self.portal.portal_workflow._jumpToStateFor(subscription, 'destroy_requested')
self.tic()
subscription.HostingSubscription_requestUpdateOpenSaleOrder()
self.tic()
self.assertEqual(subscription.getCausalityState(), 'solved')
open_sale_order_list = self.portal.portal_catalog(
portal_type='Open Sale Order',
default_destination_uid=person.getUid()
)
self.assertEqual(2,len(open_sale_order_list))
open_sale_order = [x for x in open_sale_order_list \
if x.getValidationState() != 'validated'][0].getObject()
self.assertEqual('archived', open_sale_order.getValidationState())
open_sale_order_line_list = open_sale_order.contentValues(
portal_type='Open Sale Order Line')
self.assertEqual(1, len(open_sale_order_line_list))
line = open_sale_order_line_list[0].getObject()
self.assertEqual(subscription.getRelativeUrl(), line.getAggregate())
open_sale_order_line_template = self.portal.restrictedTraverse(
self.portal.portal_preferences.getPreferredOpenSaleOrderLineTemplate())
self.assertEqual(open_sale_order_line_template.getResource(),
line.getResource())
self.assertTrue(all([q in line.getCategoryList() \
for q in open_sale_order_line_template.getCategoryList()]))
self.assertEqual(open_sale_order_line_template.getQuantity(),
line.getQuantity())
self.assertEqual(open_sale_order_line_template.getPrice(),
line.getPrice())
self.assertEqual(DateTime().earliestTime(), line.getStartDate())
self.assertEqual(addToDate(line.getStartDate(), to_add={'month': 1}),
line.getStopDate())
new_open_sale_order = [x for x in open_sale_order_list \
if x.getValidationState() == 'validated'][0].getObject()
self.assertEqual('validated', new_open_sale_order.getValidationState())
open_sale_order_line_list = new_open_sale_order.contentValues(
portal_type='Open Sale Order Line')
self.assertEqual(0, len(open_sale_order_line_list))
class TestSlapOSTriggerBuildAlarm(testSlapOSMixin):
@simulateByTitlewMark('SimulationMovement_buildSlapOS')
......
237
\ No newline at end of file
238
\ 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