Commit d5db6e2c authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_accounting: Update source when while clone Open Sale Order

parent 49c5a91a
...@@ -11,13 +11,16 @@ if portal.portal_activities.countMessageWithTag(tag) > 0: ...@@ -11,13 +11,16 @@ if portal.portal_activities.countMessageWithTag(tag) > 0:
return return
def newOpenOrder(open_sale_order): def newOpenOrder(open_sale_order):
open_sale_order_template = portal.restrictedTraverse(
portal.portal_preferences.getPreferredOpenSaleOrderTemplate())
open_order_edit_kw = { open_order_edit_kw = {
'effective_date': DateTime(), 'effective_date': DateTime(),
'activate_kw': activate_kw, 'activate_kw': activate_kw,
'source': open_sale_order_template.getSource(),
'source_section': open_sale_order_template.getSourceSection()
} }
if open_sale_order is None: if open_sale_order is None:
open_sale_order_template = portal.restrictedTraverse(
portal.portal_preferences.getPreferredOpenSaleOrderTemplate())
new_open_sale_order = open_sale_order_template.Base_createCloneDocument(batch_mode=1) new_open_sale_order = open_sale_order_template.Base_createCloneDocument(batch_mode=1)
open_order_edit_kw.update({ open_order_edit_kw.update({
'destination': person.getRelativeUrl(), 'destination': person.getRelativeUrl(),
...@@ -201,6 +204,7 @@ if (delete_line_list): ...@@ -201,6 +204,7 @@ if (delete_line_list):
open_order_explanation += "Removed %s." % str(delete_line_list) open_order_explanation += "Removed %s." % str(delete_line_list)
storeWorkflowComment(new_open_sale_order, open_order_explanation) storeWorkflowComment(new_open_sale_order, open_order_explanation)
open_sale_order = new_open_sale_order
if open_sale_order is not None: if open_sale_order is not None:
if not len(open_sale_order.contentValues( if not len(open_sale_order.contentValues(
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# Copyright (c) 2012 Nexedi SA and Contributors. All Rights Reserved. # Copyright (c) 2012 Nexedi SA and Contributors. All Rights Reserved.
# #
############################################################################## ##############################################################################
import transaction import transaction
import time import time
from functools import wraps from functools import wraps
...@@ -296,19 +296,23 @@ class TestHostingSubscription_requestUpdateOpenSaleOrder(SlapOSTestCaseMixin): ...@@ -296,19 +296,23 @@ class TestHostingSubscription_requestUpdateOpenSaleOrder(SlapOSTestCaseMixin):
if q.getValidationState() == 'validated'] if q.getValidationState() == 'validated']
archived_open_sale_order_list = [q for q in open_sale_order_list archived_open_sale_order_list = [q for q in open_sale_order_list
if q.getValidationState() == 'archived'] if q.getValidationState() == 'archived']
self.assertEqual(1, len(validated_open_sale_order_list))
self.assertEqual(1, len(archived_open_sale_order_list)) self.assertEqual(0, len(validated_open_sale_order_list))
validated_open_sale_order = validated_open_sale_order_list[0].getObject() self.assertEqual(2, len(archived_open_sale_order_list))
archived_open_sale_order_list.sort(key=lambda x: x.getCreationDate())
last_open_sale_order = archived_open_sale_order_list[-1].getObject()
archived_open_sale_order = archived_open_sale_order_list[0]\ archived_open_sale_order = archived_open_sale_order_list[0]\
.getObject() .getObject()
self.assertEqual(open_sale_order.getRelativeUrl(), self.assertEqual(open_sale_order.getRelativeUrl(),
archived_open_sale_order.getRelativeUrl()) archived_open_sale_order.getRelativeUrl())
validated_line_list = validated_open_sale_order.contentValues( last_line_list = last_open_sale_order.contentValues(
portal_type='Open Sale Order Line') portal_type='Open Sale Order Line')
archived_line_list = archived_open_sale_order.contentValues( archived_line_list = archived_open_sale_order.contentValues(
portal_type='Open Sale Order Line') portal_type='Open Sale Order Line')
self.assertEqual(0, len(validated_line_list)) self.assertEqual(0, len(last_line_list))
self.assertEqual(1, len(archived_line_list)) self.assertEqual(1, len(archived_line_list))
archived_line = archived_line_list[0].getObject() archived_line = archived_line_list[0].getObject()
...@@ -373,8 +377,13 @@ class TestHostingSubscription_requestUpdateOpenSaleOrder(SlapOSTestCaseMixin): ...@@ -373,8 +377,13 @@ class TestHostingSubscription_requestUpdateOpenSaleOrder(SlapOSTestCaseMixin):
) )
self.assertEqual(2, len(open_sale_order_list)) self.assertEqual(2, len(open_sale_order_list))
open_sale_order = [x for x in open_sale_order_list \ archived_open_sale_order_list = [x for x in open_sale_order_list \
if x.getValidationState() != 'validated'][0].getObject() if x.getValidationState() != 'validated' and \
len(x.objectValues()) > 0]
self.assertEqual(1, len(archived_open_sale_order_list))
open_sale_order = archived_open_sale_order_list[0].getObject()
self.assertEqual('archived', open_sale_order.getValidationState()) self.assertEqual('archived', open_sale_order.getValidationState())
open_sale_order_line_list = open_sale_order.contentValues( open_sale_order_line_list = open_sale_order.contentValues(
...@@ -398,9 +407,18 @@ class TestHostingSubscription_requestUpdateOpenSaleOrder(SlapOSTestCaseMixin): ...@@ -398,9 +407,18 @@ class TestHostingSubscription_requestUpdateOpenSaleOrder(SlapOSTestCaseMixin):
self.assertEqual(DateTime('2012/02/02'), line.getStopDate()) self.assertEqual(DateTime('2012/02/02'), line.getStopDate())
new_open_sale_order = [x for x in open_sale_order_list \ new_validated_open_sale_order_list = [x for x in open_sale_order_list \
if x.getValidationState() == 'validated'][0].getObject() if x.getValidationState() == 'validated']
self.assertEqual('validated', new_open_sale_order.getValidationState()) self.assertEqual(0, len(new_validated_open_sale_order_list))
archived_open_sale_order_list = [x for x in open_sale_order_list \
if x.getValidationState() != 'validated']
archived_open_sale_order_list.sort(key=lambda x: x.getCreationDate(), reverse=True)
new_open_sale_order = archived_open_sale_order_list[0]
# The OSO is archived as soon it has no lines anymore.
self.assertEqual('archived', new_open_sale_order.getValidationState())
open_sale_order_line_list = new_open_sale_order.contentValues( open_sale_order_line_list = new_open_sale_order.contentValues(
portal_type='Open Sale Order Line') portal_type='Open Sale Order Line')
self.assertEqual(0, len(open_sale_order_line_list)) self.assertEqual(0, len(open_sale_order_line_list))
...@@ -650,8 +668,12 @@ class TestHostingSubscription_requestUpdateOpenSaleOrder(SlapOSTestCaseMixin): ...@@ -650,8 +668,12 @@ class TestHostingSubscription_requestUpdateOpenSaleOrder(SlapOSTestCaseMixin):
) )
self.assertEqual(2,len(open_sale_order_list)) self.assertEqual(2,len(open_sale_order_list))
open_sale_order = [x for x in open_sale_order_list \ archived_open_sale_order_list = [x for x in open_sale_order_list \
if x.getValidationState() != 'validated'][0].getObject() if x.getValidationState() != 'validated']
archived_open_sale_order_list.sort(key=lambda x: x.getCreationDate())
open_sale_order = archived_open_sale_order_list[0].getObject()
self.assertEqual('archived', open_sale_order.getValidationState()) self.assertEqual('archived', open_sale_order.getValidationState())
open_sale_order_line_list = open_sale_order.contentValues( open_sale_order_line_list = open_sale_order.contentValues(
...@@ -676,9 +698,13 @@ class TestHostingSubscription_requestUpdateOpenSaleOrder(SlapOSTestCaseMixin): ...@@ -676,9 +698,13 @@ class TestHostingSubscription_requestUpdateOpenSaleOrder(SlapOSTestCaseMixin):
self.assertEqual(addToDate(line.getStartDate(), to_add={'day': 1}), self.assertEqual(addToDate(line.getStartDate(), to_add={'day': 1}),
line.getStopDate()) line.getStopDate())
new_open_sale_order = [x for x in open_sale_order_list \ archived_open_sale_order_list = [x for x in open_sale_order_list \
if x.getValidationState() == 'validated'][0].getObject() if x.getValidationState() != 'validated']
self.assertEqual('validated', new_open_sale_order.getValidationState())
archived_open_sale_order_list.sort(key=lambda x: x.getCreationDate())
new_open_sale_order = archived_open_sale_order_list[-1].getObject()
self.assertEqual('archived', new_open_sale_order.getValidationState())
new_effective_date = new_open_sale_order.getEffectiveDate() new_effective_date = new_open_sale_order.getEffectiveDate()
open_sale_order_line_list = new_open_sale_order.contentValues( open_sale_order_line_list = new_open_sale_order.contentValues(
portal_type='Open Sale Order Line') portal_type='Open Sale Order Line')
......
...@@ -47,16 +47,16 @@ ...@@ -47,16 +47,16 @@
<value> <value>
<tuple> <tuple>
<string>W: 31, 10: Use of eval (eval-used)</string> <string>W: 31, 10: Use of eval (eval-used)</string>
<string>W:759, 20: Use of eval (eval-used)</string> <string>W:785, 20: Use of eval (eval-used)</string>
<string>W:760, 23: Use of eval (eval-used)</string> <string>W:786, 23: Use of eval (eval-used)</string>
<string>W:781, 20: Use of eval (eval-used)</string> <string>W:807, 20: Use of eval (eval-used)</string>
<string>W:782, 23: Use of eval (eval-used)</string> <string>W:808, 23: Use of eval (eval-used)</string>
<string>W:847, 20: Use of eval (eval-used)</string> <string>W:873, 20: Use of eval (eval-used)</string>
<string>W:848, 23: Use of eval (eval-used)</string> <string>W:874, 23: Use of eval (eval-used)</string>
<string>W:857, 20: Use of eval (eval-used)</string> <string>W:883, 20: Use of eval (eval-used)</string>
<string>W:858, 23: Use of eval (eval-used)</string> <string>W:884, 23: Use of eval (eval-used)</string>
<string>W:921, 35: Use of eval (eval-used)</string> <string>W:947, 35: Use of eval (eval-used)</string>
<string>W:922, 31: Use of eval (eval-used)</string> <string>W:948, 31: Use of eval (eval-used)</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
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