Commit 5ce2609c authored by Romain Courteaud's avatar Romain Courteaud

slapos_accounting: test that dedicated trade condition / supply are applied

parent c9049e41
......@@ -849,7 +849,7 @@ class TestInstanceTree_requestUpdateOpenSaleOrder(SlapOSTestCaseMixin):
self.assertEqual(subscription.getCausalityState(), 'solved')
self.assertEqual(open_sale_order, None)
def test_empty_InstanceTree(self):
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()
......@@ -870,7 +870,7 @@ class TestInstanceTree_requestUpdateOpenSaleOrder(SlapOSTestCaseMixin):
open_sale_order.getPriceCurrency(),
project.Project_getAccountingCurrency()
)
sale_trade_condition = open_sale_order.getSpecialiseValue()
sale_trade_condition = project.getSpecialiseValue()
self.assertEqual(
open_sale_order.getSpecialise(),
sale_trade_condition.getRelativeUrl()
......@@ -969,6 +969,152 @@ class TestInstanceTree_requestUpdateOpenSaleOrder(SlapOSTestCaseMixin):
# 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)
......
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