Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Romain Courteaud
slapos.core
Commits
1fb34813
Commit
1fb34813
authored
Feb 28, 2023
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos_accounting: test InstanceTree_requestUpdateOpenSaleOrder
parent
7233f388
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
423 additions
and
551 deletions
+423
-551
master/bt5/slapos_accounting/SkinTemplateItem/portal_skins/slapos_accounting/InstanceTree_requestUpdateOpenSaleOrder.py
...pos_accounting/InstanceTree_requestUpdateOpenSaleOrder.py
+10
-10
master/bt5/slapos_accounting/SkinTemplateItem/portal_skins/slapos_accounting/OpenSaleOrder_updatePeriod.py
...tal_skins/slapos_accounting/OpenSaleOrder_updatePeriod.py
+1
-1
master/bt5/slapos_accounting/TestTemplateItem/portal_components/test.erp5.testSlapOSAccountingAlarm.py
.../portal_components/test.erp5.testSlapOSAccountingAlarm.py
+1
-540
master/bt5/slapos_accounting/TestTemplateItem/portal_components/test.erp5.testSlapOSAccountingSkins.py
.../portal_components/test.erp5.testSlapOSAccountingSkins.py
+411
-0
No files found.
master/bt5/slapos_accounting/SkinTemplateItem/portal_skins/slapos_accounting/InstanceTree_requestUpdateOpenSaleOrder.py
View file @
1fb34813
...
...
@@ -136,24 +136,24 @@ if instance_tree.getCausalityState() == 'diverged':
if
person
is
not
None
:
# Search an existing related open order
open_order_
line
=
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
'Open Sale Order
Line
'
,
default_aggregate
_uid
=
instance_tree
.
getUid
())
open_order_
cell
=
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
'Open Sale Order
Cell
'
,
aggregate_
_uid
=
instance_tree
.
getUid
())
is_open_order_creation_needed
=
False
# Simply check that it has never been simulated
if
instance_tree
.
getSlapState
()
==
'destroy_requested'
:
# Line should be deleted
if
(
open_order_
line
is
not
None
)
and
(
open_order_line
.
getValidationState
()
==
"invalidated"
):
instance_tree
.
converge
(
comment
=
"Last open order: %s"
%
open_order_
line
.
getRelativeUrl
())
elif
open_order_
line
is
None
:
if
(
open_order_
cell
is
not
None
)
and
(
open_order_cell
.
getParentValue
()
.
getValidationState
()
==
"invalidated"
):
instance_tree
.
converge
(
comment
=
"Last open order: %s"
%
open_order_
cell
.
getRelativeUrl
())
elif
open_order_
cell
is
None
:
# User has no Open Sale Order (likely).
# No need to charge, as it was never allocated
is_open_order_creation_needed
=
False
instance_tree
.
converge
(
comment
=
"No open order needed as it was never allocated"
)
elif
open_order_
line
is
None
:
elif
open_order_
cell
is
None
:
# Let's add
is_open_order_creation_needed
=
True
...
...
@@ -205,8 +205,8 @@ if instance_tree.getCausalityState() == 'diverged':
price
=
order_cell
.
getPrice
()
)
if
open_order_
line
is
not
None
:
if
open_order_
cell
is
not
None
:
open_order_line
=
open_order_cell
.
getParentValue
()
assert
open_order_line
.
getResource
().
startswith
(
'software_product'
)
assert
open_order_line
.
getQuantityUnit
()
==
'time/month'
,
open_order_line
.
getQuantityUnit
()
assert
open_order_line
.
getBaseContribution
()
==
'base_amount/invoicing/discounted'
...
...
@@ -215,7 +215,7 @@ if instance_tree.getCausalityState() == 'diverged':
#assert open_order_line.getPrice() == 1, open_order_line.getPrice()
assert
open_order_cell
.
getQuantity
()
==
1
open_
sale_order
.
OpenSaleOrder_updatePeriod
()
open_
order_line
.
getParentValue
()
.
OpenSaleOrder_updatePeriod
()
# Person_storeOpenSaleOrderJournal should fix all divergent Instance Tree in one run
assert
instance_tree
.
getCausalityState
()
==
'solved'
...
...
master/bt5/slapos_accounting/SkinTemplateItem/portal_skins/slapos_accounting/OpenSaleOrder_updatePeriod.py
View file @
1fb34813
...
...
@@ -95,7 +95,7 @@ if open_sale_order.getValidationState() == 'validated':
assert
instance_tree
.
getCausalityState
()
==
'diverged'
instance_tree
.
converge
(
comment
=
"Last open order: %s"
%
open_order_line
.
getRelativeUrl
())
open_sale_order
.
archiv
e
()
open_sale_order
.
invalidat
e
()
storeWorkflowComment
(
open_sale_order
,
"Instance Tree destroyed: %s"
%
instance_tree
.
getRelativeUrl
())
elif
(
instance_tree
.
getCausalityState
()
==
'diverged'
):
instance_tree
.
converge
(
comment
=
"Nothing to do on open order."
)
master/bt5/slapos_accounting/TestTemplateItem/portal_components/test.erp5.testSlapOSAccountingAlarm.py
View file @
1fb34813
...
...
@@ -25,7 +25,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################
import
transaction
import
time
from
functools
import
wraps
...
...
@@ -35,7 +35,6 @@ from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixin, withAbo
import
os
import
tempfile
from
DateTime
import
DateTime
from
erp5.component.module.DateUtils
import
addToDate
#, getClosestDate
from
zExceptions
import
Unauthorized
AGGREGATE_SALE_TRADE_CONDITION_RELATIVE_URL
=
'sale_trade_condition_module/slapos_aggregated_trade_condition_v3'
...
...
@@ -145,544 +144,6 @@ class TestOpenSaleOrderAlarm(SlapOSTestCaseMixin):
'Visited by InstanceTree_requestUpdateOpenSaleOrder'
,
subscription
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
class
TestInstanceTree_requestUpdateOpenSaleOrder
(
SlapOSTestCaseMixin
):
def
test_REQUEST_disallowed
(
self
):
subscription
=
self
.
portal
.
instance_tree_module
\
.
template_instance_tree
.
Base_createCloneDocument
(
batch_mode
=
1
)
self
.
assertRaises
(
Unauthorized
,
subscription
.
InstanceTree_requestUpdateOpenSaleOrder
,
"sale_trade_condition_module/default_subscription_trade_condition"
,
REQUEST
=
{})
def
test_solved_InstanceTree
(
self
):
subscription
=
self
.
portal
.
instance_tree_module
\
.
template_instance_tree
.
Base_createCloneDocument
(
batch_mode
=
1
)
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
subscription
,
'solved'
)
subscription
.
InstanceTree_requestUpdateOpenSaleOrder
(
specialise
=
"sale_trade_condition_module/default_subscription_trade_condition"
)
self
.
assertEqual
(
subscription
.
getCausalityState
(),
'solved'
)
def
test_empty_InstanceTree
(
self
):
person
=
self
.
portal
.
person_module
.
template_member
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
self
.
tic
()
subscription
=
self
.
portal
.
instance_tree_module
\
.
template_instance_tree
.
Base_createCloneDocument
(
batch_mode
=
1
)
subscription
.
edit
(
reference
=
'TESTHS-%s'
%
self
.
generateNewId
(),
destination_section
=
person
.
getRelativeUrl
())
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
subscription
,
'validated'
)
self
.
tic
()
subscription
.
InstanceTree_requestUpdateOpenSaleOrder
(
specialise
=
"sale_trade_condition_module/default_subscription_trade_condition"
)
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
(
1
,
len
(
open_sale_order_list
))
open_sale_order
=
open_sale_order_list
[
0
].
getObject
()
self
.
assertEqual
(
'validated'
,
open_sale_order
.
getValidationState
())
sale_trade_condition
=
open_sale_order
.
getSpecialiseValue
()
self
.
assertEqual
(
"sale_trade_condition_module/default_subscription_trade_condition"
,
sale_trade_condition
.
getRelativeUrl
()
)
sale_supply_line
=
sale_trade_condition
.
searchFolder
(
portal_type
=
"Sale Supply Line"
,
resource__relative_url
=
'service_module/slapos_instance_subscription'
)[
0
]
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
()
hosting_subscription
=
line
.
getAggregateValueList
()[
0
]
self
.
assertEqual
(
"Hosting Subscription"
,
hosting_subscription
.
getPortalType
())
self
.
assertEqual
(
"validated"
,
hosting_subscription
.
getValidationState
())
self
.
assertEqual
(
subscription
.
getRelativeUrl
(),
line
.
getAggregateList
()[
1
])
self
.
assertEqual
(
sale_supply_line
.
getResource
(),
line
.
getResource
())
service
=
line
.
getResourceValue
()
self
.
assertEqual
(
1
,
line
.
getQuantity
())
self
.
assertEqual
(
service
.
getQuantityUnit
(),
line
.
getQuantityUnit
())
self
.
assertEqual
(
service
.
getUse
(),
line
.
getUse
())
self
.
assertSameSet
(
service
.
getBaseContributionList
(),
line
.
getBaseContributionList
())
self
.
assertEqual
(
sale_supply_line
.
getBasePrice
(),
line
.
getPrice
())
self
.
assertEqual
(
DateTime
().
earliestTime
(),
line
.
getStartDate
())
self
.
assertEqual
(
min
(
DateTime
().
day
(),
28
),
hosting_subscription
.
getPeriodicityMonthDay
())
start_date
=
addToDate
(
line
.
getStartDate
(),
to_add
=
{
'month'
:
1
})
start_date
=
addToDate
(
start_date
,
to_add
=
{
'second'
:
-
1
})
while
start_date
.
day
()
>=
28
:
start_date
=
addToDate
(
start_date
,
to_add
=
{
'day'
:
-
1
})
self
.
assertEqual
(
start_date
,
line
.
getStopDate
())
def
test_usualLifetime_InstanceTree
(
self
):
person
=
self
.
portal
.
person_module
.
template_member
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
self
.
tic
()
subscription
=
self
.
portal
.
instance_tree_module
\
.
template_instance_tree
.
Base_createCloneDocument
(
batch_mode
=
1
)
subscription
.
edit
(
reference
=
'TESTHS-%s'
%
self
.
generateNewId
(),
title
=
'Test Title %s'
%
self
.
generateNewId
(),
destination_section
=
person
.
getRelativeUrl
())
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
subscription
,
'validated'
)
request_time
=
DateTime
(
'2012/01/01'
)
subscription
.
workflow_history
[
'instance_slap_interface_workflow'
]
=
[{
'comment'
:
'Simulated request instance'
,
'error_message'
:
''
,
'actor'
:
'ERP5TypeTestCase'
,
'slap_state'
:
'start_requested'
,
'time'
:
request_time
,
'action'
:
'request_instance'
}]
self
.
tic
()
subscription
.
InstanceTree_requestUpdateOpenSaleOrder
(
specialise
=
"sale_trade_condition_module/default_subscription_trade_condition"
)
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
(
1
,
len
(
open_sale_order_list
))
open_sale_order
=
open_sale_order_list
[
0
].
getObject
()
self
.
assertEqual
(
'validated'
,
open_sale_order
.
getValidationState
())
open_sale_order_line_list
=
open_sale_order
.
contentValues
(
portal_type
=
'Open Sale Order Line'
)
sale_trade_condition
=
open_sale_order
.
getSpecialiseValue
()
self
.
assertEqual
(
"sale_trade_condition_module/default_subscription_trade_condition"
,
sale_trade_condition
.
getRelativeUrl
()
)
sale_supply_line
=
sale_trade_condition
.
searchFolder
(
portal_type
=
"Sale Supply Line"
,
resource__relative_url
=
'service_module/slapos_instance_subscription'
)[
0
]
self
.
assertEqual
(
1
,
len
(
open_sale_order_line_list
))
line
=
open_sale_order_line_list
[
0
].
getObject
()
hosting_subscription
=
line
.
getAggregateValueList
()[
0
]
# self.assertEqual(hosting_subscription.getPeriodicityMonthDay(), 1)
self
.
assertEqual
(
"Hosting Subscription"
,
hosting_subscription
.
getPortalType
())
self
.
assertEqual
(
"validated"
,
hosting_subscription
.
getValidationState
())
self
.
assertEqual
(
subscription
.
getRelativeUrl
(),
line
.
getAggregateList
()[
1
])
self
.
assertEqual
(
sale_supply_line
.
getResource
(),
line
.
getResource
())
service
=
line
.
getResourceValue
()
self
.
assertEqual
(
service
.
getQuantityUnit
(),
line
.
getQuantityUnit
())
self
.
assertEqual
(
service
.
getUse
(),
line
.
getUse
())
self
.
assertSameSet
(
service
.
getBaseContributionList
(),
line
.
getBaseContributionList
())
self
.
assertEqual
(
1
,
line
.
getQuantity
())
self
.
assertEqual
(
sale_supply_line
.
getBasePrice
(),
line
.
getPrice
())
self
.
assertEqual
(
DateTime
().
earliestTime
(),
line
.
getStartDate
())
self
.
assertEqual
(
min
(
DateTime
().
day
(),
28
),
hosting_subscription
.
getPeriodicityMonthDay
())
start_date
=
addToDate
(
line
.
getStartDate
(),
to_add
=
{
'month'
:
1
})
start_date
=
addToDate
(
start_date
,
to_add
=
{
'second'
:
-
1
})
while
start_date
.
day
()
>=
28
:
start_date
=
addToDate
(
start_date
,
to_add
=
{
'day'
:
-
1
})
self
.
assertEqual
(
start_date
,
line
.
getStopDate
())
destroy_time
=
DateTime
(
'2112/02/01'
)
subscription
.
workflow_history
[
'instance_slap_interface_workflow'
].
append
({
'comment'
:
'Simulated request instance'
,
'error_message'
:
''
,
'actor'
:
'ERP5TypeTestCase'
,
'slap_state'
:
'destroy_requested'
,
'time'
:
destroy_time
,
'action'
:
'request_destroy'
})
subscription
.
diverge
()
self
.
tic
()
subscription
.
InstanceTree_requestUpdateOpenSaleOrder
(
specialise
=
"sale_trade_condition_module/default_subscription_trade_condition"
)
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
(
1
,
len
(
open_sale_order_list
))
validated_open_sale_order_list
=
[
q
for
q
in
open_sale_order_list
if
q
.
getValidationState
()
==
'validated'
]
archived_open_sale_order_list
=
[
q
for
q
in
open_sale_order_list
if
q
.
getValidationState
()
==
'archived'
]
self
.
assertEqual
(
0
,
len
(
validated_open_sale_order_list
))
self
.
assertEqual
(
1
,
len
(
archived_open_sale_order_list
))
archived_open_sale_order
=
archived_open_sale_order_list
[
0
]
\
.
getObject
()
self
.
assertEqual
(
open_sale_order
.
getRelativeUrl
(),
archived_open_sale_order
.
getRelativeUrl
())
archived_line_list
=
archived_open_sale_order
.
contentValues
(
portal_type
=
'Open Sale Order Line'
)
self
.
assertEqual
(
1
,
len
(
archived_line_list
))
archived_line
=
archived_line_list
[
0
].
getObject
()
self
.
assertEqual
(
line
.
getRelativeUrl
(),
archived_line
.
getRelativeUrl
())
self
.
assertEqual
(
subscription
.
getRelativeUrl
(),
archived_line
.
getAggregateList
()[
1
])
self
.
assertEqual
(
sale_supply_line
.
getResource
(),
archived_line
.
getResource
())
self
.
assertEqual
(
service
.
getQuantityUnit
(),
archived_line
.
getQuantityUnit
())
self
.
assertEqual
(
service
.
getUse
(),
archived_line
.
getUse
())
self
.
assertSameSet
(
service
.
getBaseContributionList
(),
archived_line
.
getBaseContributionList
())
self
.
assertEqual
(
1
,
line
.
getQuantity
())
self
.
assertEqual
(
sale_supply_line
.
getBasePrice
(),
line
.
getPrice
())
self
.
assertEqual
(
DateTime
().
earliestTime
(),
archived_line
.
getStartDate
())
self
.
assertEqual
(
DateTime
(
'2112/02/02'
),
line
.
getStopDate
())
def
test_lateAnalysed_InstanceTree
(
self
):
person
=
self
.
portal
.
person_module
.
template_member
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
self
.
tic
()
subscription
=
self
.
portal
.
instance_tree_module
\
.
template_instance_tree
.
Base_createCloneDocument
(
batch_mode
=
1
)
subscription
.
edit
(
reference
=
'TESTHS-%s'
%
self
.
generateNewId
(),
title
=
'Test Title %s'
%
self
.
generateNewId
(),
destination_section
=
person
.
getRelativeUrl
())
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
subscription
,
'validated'
)
subscription
.
workflow_history
[
'instance_slap_interface_workflow'
]
=
[]
request_time
=
DateTime
(
'2012/01/01'
)
subscription
.
workflow_history
[
'instance_slap_interface_workflow'
].
append
({
'comment'
:
'Simulated request instance'
,
'error_message'
:
''
,
'actor'
:
'ERP5TypeTestCase'
,
'slap_state'
:
'start_requested'
,
'time'
:
request_time
,
'action'
:
'request_instance'
})
destroy_time
=
DateTime
(
'2012/02/01'
)
subscription
.
workflow_history
[
'instance_slap_interface_workflow'
].
append
({
'comment'
:
'Simulated request instance'
,
'error_message'
:
''
,
'actor'
:
'ERP5TypeTestCase'
,
'slap_state'
:
'destroy_requested'
,
'time'
:
destroy_time
,
'action'
:
'request_destroy'
})
subscription
.
edit
(
periodicity_month_day_list
=
[])
subscription
.
fixConsistency
()
self
.
tic
()
subscription
.
InstanceTree_requestUpdateOpenSaleOrder
(
specialise
=
"sale_trade_condition_module/default_subscription_trade_condition"
)
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
(
0
,
len
(
open_sale_order_list
))
def
test_two_InstanceTree
(
self
):
person
=
self
.
portal
.
person_module
.
template_member
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
self
.
tic
()
subscription
=
self
.
portal
.
instance_tree_module
\
.
template_instance_tree
.
Base_createCloneDocument
(
batch_mode
=
1
)
subscription
.
edit
(
reference
=
'TESTHS-%s'
%
self
.
generateNewId
(),
title
=
'Test Title %s'
%
self
.
generateNewId
(),
destination_section
=
person
.
getRelativeUrl
())
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
subscription
,
'validated'
)
request_time
=
DateTime
(
'2012/01/01'
)
subscription
.
workflow_history
[
'instance_slap_interface_workflow'
]
=
[{
'comment'
:
'Simulated request instance'
,
'error_message'
:
''
,
'actor'
:
'ERP5TypeTestCase'
,
'slap_state'
:
'start_requested'
,
'time'
:
request_time
,
'action'
:
'request_instance'
}]
self
.
tic
()
subscription
.
InstanceTree_requestUpdateOpenSaleOrder
(
specialise
=
"sale_trade_condition_module/default_subscription_trade_condition"
)
self
.
tic
()
open_sale_order_list
=
self
.
portal
.
portal_catalog
(
portal_type
=
'Open Sale Order'
,
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
())
sale_trade_condition
=
open_sale_order
.
getSpecialiseValue
()
self
.
assertEqual
(
"sale_trade_condition_module/default_subscription_trade_condition"
,
sale_trade_condition
.
getRelativeUrl
()
)
sale_supply_line
=
sale_trade_condition
.
searchFolder
(
portal_type
=
"Sale Supply Line"
,
resource__relative_url
=
'service_module/slapos_instance_subscription'
)[
0
]
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
(
"Hosting Subscription"
,
line
.
getAggregateValueList
()[
0
].
getPortalType
())
self
.
assertEqual
(
"validated"
,
line
.
getAggregateValueList
()[
0
].
getValidationState
())
self
.
assertEqual
(
subscription
.
getRelativeUrl
(),
line
.
getAggregateList
()[
1
])
self
.
assertEqual
(
sale_supply_line
.
getResource
(),
line
.
getResource
())
service
=
line
.
getResourceValue
()
self
.
assertEqual
(
1
,
line
.
getQuantity
())
self
.
assertEqual
(
service
.
getQuantityUnit
(),
line
.
getQuantityUnit
())
self
.
assertEqual
(
service
.
getUse
(),
line
.
getUse
())
self
.
assertSameSet
(
service
.
getBaseContributionList
(),
line
.
getBaseContributionList
())
self
.
assertEqual
(
sale_supply_line
.
getBasePrice
(),
line
.
getPrice
())
subscription2
=
self
.
portal
.
instance_tree_module
\
.
template_instance_tree
.
Base_createCloneDocument
(
batch_mode
=
1
)
subscription2
.
edit
(
reference
=
'TESTHS-%s'
%
self
.
generateNewId
(),
title
=
'Test Title %s'
%
self
.
generateNewId
(),
destination_section
=
person
.
getRelativeUrl
())
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
subscription2
,
'validated'
)
request_time_2
=
DateTime
(
'2012/08/01'
)
subscription2
.
workflow_history
[
'instance_slap_interface_workflow'
]
=
[{
'comment'
:
'Simulated request instance'
,
'error_message'
:
''
,
'actor'
:
'ERP5TypeTestCase'
,
'slap_state'
:
'start_requested'
,
'time'
:
request_time_2
,
'action'
:
'request_instance'
}]
subscription2
.
edit
(
periodicity_month_day_list
=
[])
subscription2
.
fixConsistency
()
self
.
tic
()
subscription2
.
InstanceTree_requestUpdateOpenSaleOrder
(
specialise
=
"sale_trade_condition_module/default_subscription_trade_condition"
)
self
.
tic
()
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
))
validated_open_sale_order_list
=
[
q
for
q
in
open_sale_order_list
if
q
.
getValidationState
()
==
'validated'
]
archived_open_sale_order_list
=
[
q
for
q
in
open_sale_order_list
if
q
.
getValidationState
()
==
'archived'
]
self
.
assertEqual
(
2
,
len
(
validated_open_sale_order_list
))
self
.
assertEqual
(
0
,
len
(
archived_open_sale_order_list
))
open_sale_order_2
=
[
x
for
x
in
validated_open_sale_order_list
if
x
.
getRelativeUrl
()
!=
open_sale_order
.
getRelativeUrl
()][
0
]
self
.
assertEqual
(
open_sale_order
.
getRelativeUrl
(),
[
x
for
x
in
validated_open_sale_order_list
if
x
.
getRelativeUrl
()
==
open_sale_order
.
getRelativeUrl
()][
0
].
getRelativeUrl
())
sale_trade_condition2
=
open_sale_order
.
getSpecialiseValue
()
self
.
assertEqual
(
"sale_trade_condition_module/default_subscription_trade_condition"
,
sale_trade_condition2
.
getRelativeUrl
()
)
validated_line_list
=
open_sale_order_2
.
contentValues
(
portal_type
=
'Open Sale Order Line'
)
self
.
assertEqual
(
1
,
len
(
validated_line_list
))
validated_line_2
=
validated_line_list
[
0
]
validated_line_1
=
line
self
.
assertEqual
(
1
,
line
.
getQuantity
())
self
.
assertEqual
(
sale_supply_line
.
getBasePrice
(),
line
.
getPrice
())
hosting_subscription_2
=
validated_line_2
.
getAggregateValueList
()[
0
]
self
.
assertEqual
(
"Hosting Subscription"
,
hosting_subscription_2
.
getPortalType
())
self
.
assertEqual
(
"validated"
,
hosting_subscription_2
.
getValidationState
())
self
.
assertEqual
(
subscription2
.
getRelativeUrl
(),
validated_line_2
.
getAggregateList
()[
1
])
self
.
assertEqual
(
service
.
getQuantityUnit
(),
validated_line_1
.
getQuantityUnit
())
self
.
assertEqual
(
service
.
getUse
(),
validated_line_1
.
getUse
())
self
.
assertSameSet
(
service
.
getBaseContributionList
(),
validated_line_1
.
getBaseContributionList
())
self
.
assertEqual
(
sale_supply_line
.
getResource
(),
validated_line_1
.
getResource
())
self
.
assertEqual
(
1
,
line
.
getQuantity
())
self
.
assertEqual
(
sale_supply_line
.
getBasePrice
(),
line
.
getPrice
())
#self.assertEqual(request_time, validated_line_1.getStartDate())
#self.assertEqual(stop_date, validated_line_1.getStopDate())
self
.
assertEqual
(
service
.
getQuantityUnit
(),
validated_line_2
.
getQuantityUnit
())
self
.
assertEqual
(
service
.
getUse
(),
validated_line_2
.
getUse
())
self
.
assertSameSet
(
service
.
getBaseContributionList
(),
validated_line_2
.
getBaseContributionList
())
self
.
assertEqual
(
sale_supply_line
.
getResource
(),
validated_line_2
.
getResource
())
self
.
assertEqual
(
1
,
line
.
getQuantity
())
self
.
assertEqual
(
sale_supply_line
.
getBasePrice
(),
line
.
getPrice
())
#self.assertEqual(request_time_2, validated_line_2.getStartDate())
#self.assertEqual(stop_date_2, validated_line_2.getStopDate())
def
test_instance_tree_start_date_not_changed
(
self
):
# if there was no request_instance the getCreationDate has been used
# but if request_instance appeared start_date is not changed
person
=
self
.
portal
.
person_module
.
template_member
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
self
.
tic
()
subscription
=
self
.
portal
.
instance_tree_module
\
.
template_instance_tree
.
Base_createCloneDocument
(
batch_mode
=
1
)
subscription
.
edit
(
reference
=
'TESTHS-%s'
%
self
.
generateNewId
(),
destination_section
=
person
.
getRelativeUrl
())
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
subscription
,
'validated'
)
self
.
tic
()
subscription
.
InstanceTree_requestUpdateOpenSaleOrder
(
specialise
=
"sale_trade_condition_module/default_subscription_trade_condition"
)
self
.
tic
()
request_time
=
DateTime
(
'2112/01/01'
)
subscription
.
workflow_history
[
'instance_slap_interface_workflow'
].
append
({
'comment'
:
'Simulated request instance'
,
'error_message'
:
''
,
'actor'
:
'ERP5TypeTestCase'
,
'slap_state'
:
'start_requested'
,
'time'
:
request_time
,
'action'
:
'request_instance'
})
self
.
tic
()
subscription
.
InstanceTree_requestUpdateOpenSaleOrder
(
specialise
=
"sale_trade_condition_module/default_subscription_trade_condition"
)
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
(
1
,
len
(
open_sale_order_list
))
open_sale_order
=
open_sale_order_list
[
0
].
getObject
()
self
.
assertEqual
(
'validated'
,
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
.
getCreationDate
().
earliestTime
(),
line
.
getStartDate
())
def
test_instance_tree_diverged_to_solve
(
self
):
# check that HS becomes solved even if not modification is needed on open
# order
person
=
self
.
portal
.
person_module
.
template_member
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
self
.
tic
()
subscription
=
self
.
portal
.
instance_tree_module
\
.
template_instance_tree
.
Base_createCloneDocument
(
batch_mode
=
1
)
subscription
.
edit
(
reference
=
'TESTHS-%s'
%
self
.
generateNewId
(),
destination_section
=
person
.
getRelativeUrl
())
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
subscription
,
'validated'
)
self
.
assertEqual
(
subscription
.
getCausalityState
(),
'diverged'
)
self
.
tic
()
subscription
.
InstanceTree_requestUpdateOpenSaleOrder
(
specialise
=
"sale_trade_condition_module/default_subscription_trade_condition"
)
self
.
tic
()
self
.
assertEqual
(
subscription
.
getCausalityState
(),
'solved'
)
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
subscription
,
'diverged'
)
subscription
.
reindexObject
()
self
.
assertEqual
(
subscription
.
getCausalityState
(),
'diverged'
)
self
.
assertEqual
(
subscription
.
getSlapState
(),
'draft'
)
self
.
tic
()
subscription
.
InstanceTree_requestUpdateOpenSaleOrder
(
specialise
=
"sale_trade_condition_module/default_subscription_trade_condition"
)
self
.
tic
()
self
.
assertEqual
(
subscription
.
getCausalityState
(),
'solved'
)
def
test_empty_destroyed_InstanceTree
(
self
):
person
=
self
.
portal
.
person_module
.
template_member
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
self
.
tic
()
subscription
=
self
.
portal
.
instance_tree_module
\
.
template_instance_tree
.
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
.
InstanceTree_requestUpdateOpenSaleOrder
(
specialise
=
"sale_trade_condition_module/default_subscription_trade_condition"
)
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
(
0
,
len
(
open_sale_order_list
))
class
TestSlapOSTriggerBuildAlarm
(
SlapOSTestCaseMixin
):
@
simulateByTitlewMark
(
'SimulationMovement_buildSlapOS'
)
...
...
master/bt5/slapos_accounting/TestTemplateItem/portal_components/test.erp5.testSlapOSAccountingSkins.py
View file @
1fb34813
...
...
@@ -832,3 +832,414 @@ class TestSlapOSAccounting(SlapOSTestCaseMixin):
self
.
assertEqual
(
"started"
,
payment_transaction
.
getSimulationState
())
class
TestInstanceTree_requestUpdateOpenSaleOrder
(
SlapOSTestCaseMixin
):
def
test_REQUEST_disallowed
(
self
):
subscription
=
self
.
portal
.
instance_tree_module
\
.
template_instance_tree
.
Base_createCloneDocument
(
batch_mode
=
1
)
self
.
assertRaises
(
Unauthorized
,
subscription
.
InstanceTree_requestUpdateOpenSaleOrder
,
REQUEST
=
{})
def
test_solved_InstanceTree
(
self
):
subscription
=
self
.
portal
.
instance_tree_module
\
.
template_instance_tree
.
Base_createCloneDocument
(
batch_mode
=
1
)
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
subscription
,
'solved'
)
open_sale_order
=
subscription
.
InstanceTree_requestUpdateOpenSaleOrder
()
self
.
assertEqual
(
subscription
.
getCausalityState
(),
'solved'
)
self
.
assertEqual
(
open_sale_order
,
None
)
def
test_empty_InstanceTree
(
self
):
software_product
,
release_variation
,
type_variation
,
_
,
_
,
instance_tree
=
self
.
bootstrapAllocableInstanceTree
(
is_accountable
=
True
,
base_price
=
42
)
project
=
instance_tree
.
getFollowUpValue
()
person
=
instance_tree
.
getDestinationSectionValue
()
self
.
assertEqual
(
instance_tree
.
getCausalityState
(),
'diverged'
)
open_sale_order
=
instance_tree
.
InstanceTree_requestUpdateOpenSaleOrder
()
self
.
assertEqual
(
instance_tree
.
getCausalityState
(),
'solved'
)
self
.
assertNotEqual
(
open_sale_order
,
None
)
self
.
assertEqual
(
'validated'
,
open_sale_order
.
getValidationState
())
self
.
tic
()
# Check Open Sale Order
self
.
assertEqual
(
open_sale_order
.
getLedger
(),
"automated"
)
self
.
assertEqual
(
open_sale_order
.
getPriceCurrency
(),
project
.
Project_getAccountingCurrency
()
)
sale_trade_condition
=
open_sale_order
.
getSpecialiseValue
()
self
.
assertEqual
(
open_sale_order
.
getSpecialise
(),
sale_trade_condition
.
getRelativeUrl
()
)
self
.
assertEqual
(
open_sale_order
.
getSource
(),
sale_trade_condition
.
getSource
()
)
self
.
assertEqual
(
open_sale_order
.
getSourceSection
(),
sale_trade_condition
.
getSourceSection
()
)
self
.
assertEqual
(
open_sale_order
.
getDestinationProject
(),
project
.
getRelativeUrl
()
)
self
.
assertEqual
(
open_sale_order
.
getDestination
(),
person
.
getRelativeUrl
()
)
self
.
assertEqual
(
open_sale_order
.
getDestinationSection
(),
person
.
getRelativeUrl
()
)
self
.
assertEqual
(
open_sale_order
.
getDestinationDecision
(),
person
.
getRelativeUrl
()
)
# Check Open Sale Order Line
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
(
line
.
getResource
(),
software_product
.
getRelativeUrl
()
)
self
.
assertEqual
(
line
.
getSoftwareRelease
(),
release_variation
.
getRelativeUrl
()
)
self
.
assertEqual
(
line
.
getSoftwareType
(),
type_variation
.
getRelativeUrl
()
)
self
.
assertEqual
(
line
.
getTotalQuantity
(),
1
)
self
.
assertEqual
(
software_product
.
getQuantityUnit
(),
line
.
getQuantityUnit
()
)
self
.
assertEqual
(
software_product
.
getUse
(),
line
.
getUse
()
)
self
.
assertSameSet
(
software_product
.
getBaseContributionList
(),
line
.
getBaseContributionList
()
)
self
.
assertEqual
(
line
.
getTotalPrice
(),
42
)
self
.
assertEqual
(
line
.
getPriceCurrency
(),
project
.
Project_getAccountingCurrency
()
)
# Check Open Sale Order Cell
open_sale_order_cell_list
=
line
.
contentValues
(
portal_type
=
'Open Sale Order Cell'
)
self
.
assertEqual
(
1
,
len
(
open_sale_order_cell_list
))
cell
=
open_sale_order_cell_list
[
0
].
getObject
()
self
.
assertEqual
(
cell
.
getQuantity
(),
1
)
self
.
assertEqual
(
cell
.
getPrice
(),
42
)
hosting_subscription
=
cell
.
getAggregateValue
(
portal_type
=
"Hosting Subscription"
)
self
.
assertSameSet
(
cell
.
getAggregateList
(),
[
hosting_subscription
.
getRelativeUrl
(),
instance_tree
.
getRelativeUrl
()]
)
self
.
assertEqual
(
"validated"
,
hosting_subscription
.
getValidationState
())
"""
self.assertEqual(DateTime().earliestTime(), line.getStartDate())
self.assertEqual(min(DateTime().day(), 28),
hosting_subscription.getPeriodicityMonthDay())
start_date = addToDate(line.getStartDate(), to_add={'month': 1})
start_date = addToDate(start_date, to_add={'second': -1})
while start_date.day() >= 28:
start_date = addToDate(start_date, to_add={'day': -1})
self.assertEqual(start_date, line.getStopDate())
# XXX XXX Open Order start_date, stop_date, effective_date
"""
def
test_empty_InstanceTree_noPerson
(
self
):
_
,
_
,
_
,
_
,
_
,
instance_tree
=
self
.
bootstrapAllocableInstanceTree
(
is_accountable
=
True
,
base_price
=
42
)
instance_tree
.
setDestinationSection
(
None
)
self
.
assertEqual
(
instance_tree
.
getCausalityState
(),
'diverged'
)
open_sale_order
=
instance_tree
.
InstanceTree_requestUpdateOpenSaleOrder
()
self
.
assertEqual
(
instance_tree
.
getCausalityState
(),
'diverged'
)
self
.
assertEqual
(
open_sale_order
,
None
)
self
.
assertEqual
(
self
.
portal
.
portal_workflow
.
getInfoFor
(
ob
=
instance_tree
,
name
=
'comment'
,
wf_id
=
'edit_workflow'
),
None
)
def
test_empty_InstanceTree_noProduct
(
self
):
_
,
_
,
_
,
_
,
_
,
instance_tree
=
self
.
bootstrapAllocableInstanceTree
(
is_accountable
=
True
,
base_price
=
42
)
instance_tree
.
setUrlString
(
instance_tree
.
getUrlString
()
+
'foo'
)
self
.
assertEqual
(
instance_tree
.
getCausalityState
(),
'diverged'
)
open_sale_order
=
instance_tree
.
InstanceTree_requestUpdateOpenSaleOrder
()
self
.
assertEqual
(
instance_tree
.
getCausalityState
(),
'diverged'
)
self
.
assertEqual
(
open_sale_order
,
None
)
self
.
assertEqual
(
self
.
portal
.
portal_workflow
.
getInfoFor
(
ob
=
instance_tree
,
name
=
'comment'
,
wf_id
=
'edit_workflow'
),
"No software product found"
)
def
test_empty_InstanceTree_noCurrency
(
self
):
_
,
_
,
_
,
_
,
_
,
instance_tree
=
self
.
bootstrapAllocableInstanceTree
()
self
.
assertEqual
(
instance_tree
.
getCausalityState
(),
'diverged'
)
open_sale_order
=
instance_tree
.
InstanceTree_requestUpdateOpenSaleOrder
()
self
.
assertEqual
(
instance_tree
.
getCausalityState
(),
'diverged'
)
self
.
assertEqual
(
open_sale_order
,
None
)
self
.
assertEqual
(
self
.
portal
.
portal_workflow
.
getInfoFor
(
ob
=
instance_tree
,
name
=
'comment'
,
wf_id
=
'edit_workflow'
),
"No currency found"
)
def
test_empty_InstanceTree_noPrice
(
self
):
_
,
_
,
_
,
_
,
_
,
instance_tree
=
self
.
bootstrapAllocableInstanceTree
(
is_accountable
=
True
)
self
.
assertEqual
(
instance_tree
.
getCausalityState
(),
'diverged'
)
open_sale_order
=
instance_tree
.
InstanceTree_requestUpdateOpenSaleOrder
()
self
.
assertEqual
(
instance_tree
.
getCausalityState
(),
'diverged'
)
self
.
assertEqual
(
open_sale_order
,
None
)
self
.
assertEqual
(
self
.
portal
.
portal_workflow
.
getInfoFor
(
ob
=
instance_tree
,
name
=
'comment'
,
wf_id
=
'edit_workflow'
),
"No price found"
)
def
test_usualLifetime_InstanceTree
(
self
):
_
,
_
,
_
,
_
,
_
,
instance_tree
=
self
.
bootstrapAllocableInstanceTree
(
is_accountable
=
True
,
base_price
=
9
)
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
instance_tree
,
'validated'
)
person
=
instance_tree
.
getDestinationSectionValue
()
request_time
=
DateTime
(
'2012/01/01'
)
instance_tree
.
workflow_history
[
'instance_slap_interface_workflow'
]
=
[{
'comment'
:
'Simulated request instance'
,
'error_message'
:
''
,
'actor'
:
'ERP5TypeTestCase'
,
'slap_state'
:
'start_requested'
,
'time'
:
request_time
,
'action'
:
'request_instance'
}]
self
.
tic
()
open_sale_order
=
instance_tree
.
InstanceTree_requestUpdateOpenSaleOrder
()
self
.
tic
()
self
.
assertEqual
(
instance_tree
.
getCausalityState
(),
'solved'
)
self
.
assertEqual
(
'validated'
,
open_sale_order
.
getValidationState
())
destroy_time
=
DateTime
(
'2112/02/01'
)
instance_tree
.
workflow_history
[
'instance_slap_interface_workflow'
].
append
({
'comment'
:
'Simulated request instance'
,
'error_message'
:
''
,
'actor'
:
'ERP5TypeTestCase'
,
'slap_state'
:
'destroy_requested'
,
'time'
:
destroy_time
,
'action'
:
'request_destroy'
})
instance_tree
.
diverge
()
self
.
tic
()
second_open_sale_order
=
instance_tree
.
InstanceTree_requestUpdateOpenSaleOrder
()
self
.
assertEqual
(
second_open_sale_order
,
None
)
self
.
tic
()
self
.
assertEqual
(
instance_tree
.
getCausalityState
(),
'solved'
)
open_sale_order_list
=
self
.
portal
.
portal_catalog
(
portal_type
=
'Open Sale Order'
,
default_destination_uid
=
person
.
getUid
()
)
self
.
assertEqual
(
1
,
len
(
open_sale_order_list
))
self
.
assertEqual
(
'invalidated'
,
open_sale_order
.
getValidationState
())
# self.assertEqual(DateTime().earliestTime(), archived_line.getStartDate())
# self.assertEqual(DateTime('2112/02/02'), line.getStopDate())
def
test_lateAnalysed_InstanceTree
(
self
):
_
,
_
,
_
,
_
,
_
,
instance_tree
=
self
.
bootstrapAllocableInstanceTree
(
is_accountable
=
True
,
base_price
=
9
)
person
=
instance_tree
.
getDestinationSectionValue
()
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
instance_tree
,
'validated'
)
instance_tree
.
workflow_history
[
'instance_slap_interface_workflow'
]
=
[]
request_time
=
DateTime
(
'2012/01/01'
)
instance_tree
.
workflow_history
[
'instance_slap_interface_workflow'
].
append
({
'comment'
:
'Simulated request instance'
,
'error_message'
:
''
,
'actor'
:
'ERP5TypeTestCase'
,
'slap_state'
:
'start_requested'
,
'time'
:
request_time
,
'action'
:
'request_instance'
})
destroy_time
=
DateTime
(
'2012/02/01'
)
instance_tree
.
workflow_history
[
'instance_slap_interface_workflow'
].
append
({
'comment'
:
'Simulated request instance'
,
'error_message'
:
''
,
'actor'
:
'ERP5TypeTestCase'
,
'slap_state'
:
'destroy_requested'
,
'time'
:
destroy_time
,
'action'
:
'request_destroy'
})
instance_tree
.
edit
(
periodicity_month_day_list
=
[])
instance_tree
.
fixConsistency
()
self
.
tic
()
open_order
=
instance_tree
.
InstanceTree_requestUpdateOpenSaleOrder
()
self
.
assertEqual
(
open_order
,
None
)
self
.
tic
()
self
.
assertEqual
(
instance_tree
.
getCausalityState
(),
'solved'
)
open_sale_order_list
=
self
.
portal
.
portal_catalog
(
portal_type
=
'Open Sale Order'
,
default_destination_uid
=
person
.
getUid
()
)
self
.
assertEqual
(
0
,
len
(
open_sale_order_list
))
self
.
assertEqual
(
self
.
portal
.
portal_workflow
.
getInfoFor
(
ob
=
instance_tree
,
name
=
'comment'
,
wf_id
=
'slapos_api_invoicing_workflow'
),
"No open order needed as it was never allocated"
)
def
test_two_InstanceTree
(
self
):
_
,
_
,
_
,
_
,
_
,
instance_tree
=
self
.
bootstrapAllocableInstanceTree
(
is_accountable
=
True
,
base_price
=
9
)
person
=
instance_tree
.
getDestinationSectionValue
()
open_sale_order
=
instance_tree
.
InstanceTree_requestUpdateOpenSaleOrder
()
self
.
assertEqual
(
instance_tree
.
getCausalityState
(),
'solved'
)
self
.
assertEqual
(
'validated'
,
open_sale_order
.
getValidationState
())
instance_tree2
=
instance_tree
.
Base_createCloneDocument
(
batch_mode
=
1
)
instance_tree2
.
edit
(
reference
=
'TESTHS-%s'
%
self
.
generateNewId
(),
title
=
'Test Title %s'
%
self
.
generateNewId
())
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
instance_tree2
,
'validated'
)
open_sale_order2
=
instance_tree2
.
InstanceTree_requestUpdateOpenSaleOrder
()
self
.
assertEqual
(
instance_tree2
.
getCausalityState
(),
'solved'
)
self
.
assertEqual
(
'validated'
,
open_sale_order2
.
getValidationState
())
self
.
tic
()
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
))
def
test_instance_tree_start_date_not_changed
(
self
):
# if there was no request_instance the getCreationDate has been used
# but if request_instance appeared start_date is not changed
_
,
_
,
_
,
_
,
_
,
subscription
=
self
.
bootstrapAllocableInstanceTree
(
is_accountable
=
True
,
base_price
=
9
)
person
=
subscription
.
getDestinationSectionValue
()
subscription
.
InstanceTree_requestUpdateOpenSaleOrder
()
self
.
tic
()
request_time
=
DateTime
(
'2112/01/01'
)
subscription
.
workflow_history
[
'instance_slap_interface_workflow'
].
append
({
'comment'
:
'Simulated request instance'
,
'error_message'
:
''
,
'actor'
:
'ERP5TypeTestCase'
,
'slap_state'
:
'start_requested'
,
'time'
:
request_time
,
'action'
:
'request_instance'
})
self
.
tic
()
subscription
.
InstanceTree_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
(
1
,
len
(
open_sale_order_list
))
open_sale_order
=
open_sale_order_list
[
0
].
getObject
()
self
.
assertEqual
(
'validated'
,
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
.
getCreationDate
().
earliestTime
(),
line
.
getStartDate
())
def
test_instance_tree_diverged_to_solve
(
self
):
# check that HS becomes solved even if not modification is needed on open
# order
_
,
_
,
_
,
_
,
_
,
instance_tree
=
self
.
bootstrapAllocableInstanceTree
(
is_accountable
=
True
,
base_price
=
9
)
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
instance_tree
,
'validated'
)
self
.
assertEqual
(
instance_tree
.
getCausalityState
(),
'diverged'
)
self
.
tic
()
open_sale_order
=
instance_tree
.
InstanceTree_requestUpdateOpenSaleOrder
()
self
.
tic
()
self
.
assertEqual
(
instance_tree
.
getCausalityState
(),
'solved'
)
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
instance_tree
,
'diverged'
)
instance_tree
.
reindexObject
()
self
.
assertEqual
(
instance_tree
.
getCausalityState
(),
'diverged'
)
self
.
assertEqual
(
instance_tree
.
getSlapState
(),
'start_requested'
)
self
.
tic
()
open_sale_order2
=
instance_tree
.
InstanceTree_requestUpdateOpenSaleOrder
()
self
.
tic
()
self
.
assertEqual
(
open_sale_order2
,
None
)
self
.
assertEqual
(
open_sale_order
.
getValidationState
(),
'validated'
)
self
.
assertEqual
(
instance_tree
.
getCausalityState
(),
'solved'
)
self
.
assertEqual
(
self
.
portal
.
portal_workflow
.
getInfoFor
(
ob
=
instance_tree
,
name
=
'comment'
,
wf_id
=
'slapos_api_invoicing_workflow'
),
"Nothing to do on open order."
)
def
test_empty_destroyed_InstanceTree
(
self
):
person
=
self
.
portal
.
person_module
.
template_member
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
self
.
tic
()
subscription
=
self
.
portal
.
instance_tree_module
\
.
template_instance_tree
.
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
()
open_sale_order
=
subscription
.
InstanceTree_requestUpdateOpenSaleOrder
()
self
.
assertEqual
(
open_sale_order
,
None
)
self
.
tic
()
self
.
assertEqual
(
subscription
.
getCausalityState
(),
'solved'
)
self
.
assertEqual
(
self
.
portal
.
portal_workflow
.
getInfoFor
(
ob
=
subscription
,
name
=
'comment'
,
wf_id
=
'slapos_api_invoicing_workflow'
),
"No open order needed as it was never allocated"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment