Commit 3d56fe29 authored by Romain Courteaud's avatar Romain Courteaud

slapos_erp5:

* WIP test for variated resource on open order...
* check variation stock
* check accounting
* check transaction total_price
* set the aggregate value on the Open Order Sale
parent ec2c2b36
......@@ -149,7 +149,7 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin):
# 3 (can reduce to 2) assignment, 1 instance tree, 1 compute node, 1 software installation
# 1 software instance
# 2 credential request
related_object_list = project.Base_getRelatedObjectList()
related_object_list = project.Base_getRelatedObjectList(**{'category.category_strict_membership': 1})
assert len(related_object_list) == 9, [x.getRelativeUrl() for x in related_object_list]
self.stepcheckERP5Consistency()
......@@ -159,7 +159,8 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin):
assert last_message is None, last_message
def test_open_order_scenario(self):
def test_open_order_with_service_scenario(self):
# create a default project
project = self.addProject()
person = self.portal.person_module.newContent(
......@@ -189,6 +190,7 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin):
)
sale_trade_condition.validate()
service = self.portal.restrictedTraverse('service_module/slapos_virtual_master_subscription')
for _ in range(1):
hosting_subscription = self.portal.hosting_subscription_module.newContent(
......@@ -222,7 +224,7 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin):
portal_type="Open Sale Order Line",
quantity=10,
price=2,
resource='service_module/slapos_virtual_master_subscription',
resource_value=service,
aggregate_value=[
hosting_subscription,
project
......@@ -238,6 +240,26 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin):
self.stepCallAlarmList()
self.tic()
self.login()
# Check stock
inventory_list = self.portal.portal_simulation.getCurrentInventoryList(**{
'group_by_section': False,
'group_by_node': True,
'group_by_variation': True,
'resource_uid': service.getUid(),
'node_uid': person.getUid(),
'project_uid': project.getUid(),
'ledger_uid': hosting_subscription.getLedgerUid()
})
assert len(inventory_list) == 1, len(inventory_list)
assert inventory_list[0].quantity == 10, inventory_list[0].quantity
assert inventory_list[0].getVariationCategoryList() == [], inventory_list[0].getVariationCategoryList()
# Check accounting
transaction_list = self.portal.account_module.receivable.Account_getAccountingTransactionList(mirror_section_uid=person.getUid())
assert len(transaction_list) == 1, len(transaction_list)
assert transaction_list[0].total_price == 24, transaction_list[0].total_price
# Ensure no unexpected object has been created
# destination project:
# 1 open order
......@@ -256,4 +278,166 @@ class TestSlapOSVirtualMasterScenario(DefaultScenarioMixin):
# after accept, an email is send containing the reset link
last_message = self.portal.MailHost._last_message
assert last_message is None, last_message
\ No newline at end of file
assert last_message is None, last_message
def test_open_order_with_software_product_scenario(self):
# create a default project
project = self.addProject()
person = self.portal.person_module.newContent(
portal_type="Person",
default_email_coordinate_text='a@example.org',
)
organisation = self.portal.organisation_module.newContent(
portal_type="Organisation"
)
sale_trade_condition = self.portal.sale_trade_condition_module.newContent(
portal_type="Sale Trade Condition",
reference='slapos_ultimate_trade_condition',
# XXX hardcoded
specialise="business_process_module/slapos_ultimate_business_process"
)
sale_trade_condition.newContent(
portal_type="Trade Model Line",
reference="VAT",
resource="service_module/slapos_tax",
base_application="base_amount/invoicing/taxable",
trade_phase="slapos/tax",
price=0.2,
quantity=1.0,
membership_criterion_base_category=('price_currency',),
membership_criterion_category=('price_currency/currency_module/EUR',)
)
sale_trade_condition.validate()
software_product = self.portal.software_product_module.newContent(
portal_type="Software Product",
title="foo software product",
follow_up_value=project,
quantity_unit='time/month',
)
software_product.newContent(
portal_type="Software Product Release Variation",
title="my super release"
)
software_product.newContent(
portal_type="Software Product Type Variation",
title="my super type"
)
software_product.validate()
instance_tree = self.portal.instance_tree_module.newContent(
portal_type="Instance Tree",
follow_up_value=project
)
for _ in range(1):
hosting_subscription = self.portal.hosting_subscription_module.newContent(
portal_type="Hosting Subscription",
# XXX hardcoded
ledger="automated",
)
hosting_subscription.validate()
start_date = hosting_subscription.HostingSubscription_calculateSubscriptionStartDate()
# create open order
open_sale_order = self.portal.open_sale_order_module.newContent(
portal_type="Open Sale Order",
ledger=hosting_subscription.getLedger(),
destination_project_value=project,
source_value=organisation,
source_section_value=organisation,
destination_value=person,
destination_section_value=person,
destination_decision_value=person,
price_currency='currency_module/EUR',
payment_mode="payzen",
start_date=start_date,
# Ensure stop date value is higher than start date
# it will be updated by OpenSaleOrder_updatePeriod
stop_date=start_date + 1,
specialise_value=sale_trade_condition
)
resource_vcl = list(software_product.getVariationCategoryList(
omit_individual_variation=0))
resource_vcl.sort()
open_order_line = open_sale_order.newContent(
portal_type="Open Sale Order Line",
resource_value=software_product,
variation_category_list=resource_vcl
)
base_id = 'path'
cell_key = list(open_order_line.getCellKeyList(base_id=base_id))[0]
#cell_key_list.sort()
open_order_cell = open_order_line.newCell(
base_id=base_id,
portal_type='Open Sale Order Cell',
*cell_key
)
open_order_cell.edit(
mapped_value_property_list=['price','quantity'],
price=3,
quantity=4,
predicate_category_list=cell_key,
variation_category_list=cell_key,
aggregate_value=[
hosting_subscription,
instance_tree
],
)
open_sale_order.order()
open_sale_order.validate()
self.tic()
# XXX Do this for every scenario tests
self.logout()
for _ in range(20):
self.stepCallAlarmList()
self.tic()
self.login()
# Check stock
inventory_list = self.portal.portal_simulation.getCurrentInventoryList(**{
'group_by_section': False,
'group_by_node': True,
'group_by_variation': True,
'resource_uid': software_product.getUid(),
'node_uid': person.getUid(),
'project_uid': project.getUid(),
'ledger_uid': hosting_subscription.getLedgerUid()
})
assert len(inventory_list) == 1, len(inventory_list)
assert inventory_list[0].quantity == 4, inventory_list[0].quantity
assert inventory_list[0].getVariationCategoryList() == resource_vcl, inventory_list[0].getVariationCategoryList()
# Check accounting
transaction_list = self.portal.account_module.receivable.Account_getAccountingTransactionList(mirror_section_uid=person.getUid())
assert len(transaction_list) == 1, len(transaction_list)
assert transaction_list[0].total_price == 14.4, transaction_list[0].total_price
# Ensure no unexpected object has been created
# destination project:
# 1 open order
# 2 accounting transaction
# 1 packing list
# 7 simulation mvt
# 1 instance tree
# 1 software product
# acquisition...
# 1 open order line
# 1 open order cell
related_object_list = project.Base_getRelatedObjectList(**{'category.category_strict_membership': 1})
assert len(related_object_list) == 15, [x.getRelativeUrl() for x in related_object_list]
self.stepcheckERP5Consistency()
# after accept, an email is send containing the reset link
last_message = self.portal.MailHost._last_message
assert last_message is None, last_message
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