Commit d5bd9901 authored by Romain Courteaud's avatar Romain Courteaud

slapos_accounting: test: InstanceTree_requestUpdateOpenSaleOrder was dropped

parent ee99acde
......@@ -832,560 +832,3 @@ 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_ok(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 = project.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_withDedicatedTradeConditionAndSupply(self):
software_product, release_variation, type_variation, _, _, instance_tree = self.bootstrapAllocableInstanceTree(is_accountable=True, base_price=42, has_organisation=True)
project = instance_tree.getFollowUpValue()
person = instance_tree.getDestinationSectionValue()
self.assertEqual(instance_tree.getCausalityState(), 'diverged')
sale_trade_condition = project.getSpecialiseValue()
# Create dedicated trade condition and supply
dedicated_sale_trade_condition = self.portal.sale_trade_condition_module.newContent(
portal_type="Sale Trade Condition",
reference='customer_%s' % person.getTitle(),
# XXX hardcoded
specialise_value=sale_trade_condition,
destination_project_value=project,
destination_section_value=person
)
dedicated_sale_trade_condition.validate()
dedicated_sale_supply = self.portal.sale_supply_module.newContent(
portal_type="Sale Supply",
destination_project_value=project,
destination_section_value=person,
price_currency=project.Project_getAccountingCurrency()
)
dedicated_sale_supply.newContent(
portal_type="Sale Supply Line",
base_price=43,
resource_value=software_product
)
dedicated_sale_supply.validate()
self.tic()
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()
)
self.assertEqual(
open_sale_order.getSpecialise(),
dedicated_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(),
43
)
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(), 43)
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('archived', 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"
)
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