Commit f8b48a03 authored by Romain Courteaud's avatar Romain Courteaud

slapos_panel: create draft Sale Supply when creating a "payable" project

parent c4e940f6
......@@ -20,9 +20,10 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
owner_person, _, project = self.bootstrapAccountingTest()
# Ensure no unexpected object has been created
# 2 assignment
# 2 sale supply + line
# 2 sale trade condition
# 1 subscription requests
self.assertRelatedObjectCount(project, 5)
self.assertRelatedObjectCount(project, 7)
self.assertFalse(owner_person.Entity_hasOutstandingAmount(include_planned=True))
self.assertFalse(owner_person.Entity_hasOutstandingAmount())
......@@ -75,10 +76,11 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
# 1 open order
# 2 assignment
# 2 simulation movements
# 2 sale supply + line
# 1 sale packing list
# 2 sale trade condition
# 1 subscription requests
self.assertRelatedObjectCount(project, 10)
self.assertRelatedObjectCount(project, 12)
with PinnedDateTime(self, DateTime('2021/07/05')):
self.portal.portal_alarms.update_open_order_simulation.activeSense()
......@@ -98,10 +100,11 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
# 1 open order
# 2 assignment
# 8 simulation movements
# 2 sale supply + line
# 4 sale packing list
# 2 sale trade condition
# 1 subscription requests
self.assertRelatedObjectCount(project, 22)
self.assertRelatedObjectCount(project, 24)
# Try to pay previous period
with PinnedDateTime(self, DateTime('2021/07/06')):
......@@ -128,7 +131,7 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
self.assertEqual(amount_list[0].total_price, 50.4)
self.assertTrue(first_invoice.SaleInvoiceTransaction_isLettered())
# Ensure no unexpected object has been created
self.assertRelatedObjectCount(project, 22)
self.assertRelatedObjectCount(project, 24)
payment_tag = "Entity_createPaymentTransaction_%s" % owner_person.getUid()
owner_person.REQUEST.set(payment_tag, None)
......@@ -152,7 +155,7 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
amount_list = owner_person.Entity_getOutstandingAmountList()
self.assertEqual(len(amount_list), 0)
# Ensure no unexpected object has been created
self.assertRelatedObjectCount(project, 22)
self.assertRelatedObjectCount(project, 24)
with PinnedDateTime(self, DateTime('2021/07/06')):
self.checkERP5StateBeforeExit()
......@@ -173,22 +176,20 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
"instance product", project, software_release_url, software_type
)
# Create supply to buy services
sale_supply = self.portal.sale_supply_module.newContent(
portal_type="Sale Supply",
title="price for %s" % project.getRelativeUrl(),
source_project_value=project,
price_currency_value=currency
self.tic()
sale_supply = self.portal.portal_catalog.getResultValue(
portal_type='Sale Supply',
source_project__uid=project.getUid()
)
sale_supply.searchFolder(
portal_type='Sale Supply Line',
resource__relative_url="service_module/slapos_compute_node_subscription"
)[0].edit(base_price=7)
sale_supply.newContent(
portal_type="Sale Supply Line",
base_price=6,
resource_value=software_product
)
sale_supply.newContent(
portal_type="Sale Supply Line",
base_price=7,
resource="service_module/slapos_compute_node_subscription"
)
sale_supply.validate()
self.tic()
# Ensure no unexpected object has been created
......@@ -324,9 +325,10 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
# Ensure no unexpected object has been created
# 2 assignment
# 2 sale supply + line
# 2 sale trade condition
# 1 subscription requests
self.assertRelatedObjectCount(project, 5)
self.assertRelatedObjectCount(project, 7)
##################################################
# Add deposit (0.1 to prevent discount generation)
......@@ -371,9 +373,10 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
# 1 open order
# 2 assignment
# 4 simulation movements
# 2 sale supply + line
# 2 sale packing lists
# 2 sale trade condition
# 1 subscription requests
self.assertRelatedObjectCount(project, 14)
self.assertRelatedObjectCount(project, 16)
self.checkERP5StateBeforeExit()
......@@ -37,23 +37,21 @@ class TestSlapOSCRMScenario(TestSlapOSVirtualMasterScenarioMixin):
software_product, _, _ = self.addSoftwareProduct(
"instance product", project, software_release_url, software_type
)
# Create supply to buy services
sale_supply = self.portal.sale_supply_module.newContent(
portal_type="Sale Supply",
title="price for %s" % project.getRelativeUrl(),
source_project_value=project,
price_currency_value=currency
self.tic()
sale_supply = self.portal.portal_catalog.getResultValue(
portal_type='Sale Supply',
source_project__uid=project.getUid()
)
sale_supply.searchFolder(
portal_type='Sale Supply Line',
resource__relative_url="service_module/slapos_compute_node_subscription"
)[0].edit(base_price=7)
# Create supply to buy services
sale_supply.newContent(
portal_type="Sale Supply Line",
base_price=6,
resource_value=software_product
)
sale_supply.newContent(
portal_type="Sale Supply Line",
base_price=7,
resource="service_module/slapos_compute_node_subscription"
)
sale_supply.validate()
self.tic()
# Ensure no unexpected object has been created
......
......@@ -314,18 +314,15 @@ class TestSlapOSSubscriptionChangeRequestScenario(TestSlapOSSubscriptionChangeRe
# create a default project
project_relative_url = self.addProject(person=owner_person, currency=currency, is_accountable=True)
sale_supply = self.portal.sale_supply_module.newContent(
portal_type="Sale Supply",
title="price for %s" % project_relative_url,
source_project=project_relative_url,
price_currency_value=currency
)
sale_supply.newContent(
portal_type="Sale Supply Line",
base_price=99,
resource="service_module/slapos_compute_node_subscription"
self.tic()
sale_supply = self.portal.portal_catalog.getResultValue(
portal_type='Sale Supply',
source_project__relative_url=project_relative_url
)
sale_supply.searchFolder(
portal_type='Sale Supply Line',
resource__relative_url="service_module/slapos_compute_node_subscription"
)[0].edit(base_price=99)
sale_supply.validate()
self.logout()
......
......@@ -86,11 +86,10 @@ class TestSlapOSSubscriptionScenario(TestSlapOSSubscriptionScenarioMixin):
self.logout()
self.login(sale_person.getUserId())
sale_supply = self.portal.sale_supply_module.newContent(
portal_type="Sale Supply",
title="price for %s" % project.getRelativeUrl(),
source_project_value=project,
price_currency_value=currency
self.tic()
sale_supply = self.portal.portal_catalog.getResultValue(
portal_type='Sale Supply',
source_project__uid=project.getUid()
)
sale_supply.newContent(
portal_type="Sale Supply Line",
......@@ -249,12 +248,12 @@ class TestSlapOSSubscriptionScenario(TestSlapOSSubscriptionScenarioMixin):
# 5 (can reduce to 2) assignment
# 2 simulation mvt
# 1 packing list / line
# 2 sale supply / line
# 3 sale supply / line
# 2 sale trade condition
# 1 software installation
# 1 software product
# 2 subscription requests
self.assertRelatedObjectCount(project, 21)
self.assertRelatedObjectCount(project, 22)
self.checkERP5StateBeforeExit()
......@@ -352,9 +351,10 @@ class TestSlapOSSubscriptionScenario(TestSlapOSSubscriptionScenarioMixin):
# Ensure no unexpected object has been created
# 1 credential request
# 4 assignment
# 2 Sale Supply + Line
# 2 Sale Trade condition
# 1 subscription request
self.assertRelatedObjectCount(project, 8)
self.assertRelatedObjectCount(project, 10)
self.checkERP5StateBeforeExit()
def test_subscription_request_cancel_after_compute_node_is_invalidated(self):
......@@ -405,22 +405,20 @@ class TestSlapOSSubscriptionScenario(TestSlapOSSubscriptionScenarioMixin):
self.logout()
self.login(sale_person.getUserId())
sale_supply = self.portal.sale_supply_module.newContent(
portal_type="Sale Supply",
title="price for %s" % project.getRelativeUrl(),
source_project_value=project,
price_currency_value=currency
self.tic()
sale_supply = self.portal.portal_catalog.getResultValue(
portal_type='Sale Supply',
source_project__uid=project.getUid()
)
sale_supply.searchFolder(
portal_type='Sale Supply Line',
resource__relative_url="service_module/slapos_compute_node_subscription"
)[0].edit(base_price=99)
sale_supply.newContent(
portal_type="Sale Supply Line",
base_price=9,
resource_value=software_product
)
sale_supply.newContent(
portal_type="Sale Supply Line",
base_price=99,
resource="service_module/slapos_compute_node_subscription"
)
sale_supply.validate()
self.tic()
......@@ -694,22 +692,20 @@ class TestSlapOSSubscriptionScenario(TestSlapOSSubscriptionScenarioMixin):
self.logout()
self.login(sale_person.getUserId())
sale_supply = self.portal.sale_supply_module.newContent(
portal_type="Sale Supply",
title="price for %s" % project.getRelativeUrl(),
source_project_value=project,
price_currency_value=currency
self.tic()
sale_supply = self.portal.portal_catalog.getResultValue(
portal_type='Sale Supply',
source_project__uid=project.getUid()
)
sale_supply.searchFolder(
portal_type='Sale Supply Line',
resource__relative_url="service_module/slapos_compute_node_subscription"
)[0].edit(base_price=99)
sale_supply.newContent(
portal_type="Sale Supply Line",
base_price=9,
resource_value=software_product
)
sale_supply.newContent(
portal_type="Sale Supply Line",
base_price=99,
resource="service_module/slapos_compute_node_subscription"
)
sale_supply.validate()
self.tic()
......
......@@ -611,22 +611,20 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
self.logout()
self.login(sale_person.getUserId())
sale_supply = self.portal.sale_supply_module.newContent(
portal_type="Sale Supply",
title="price for %s" % project.getRelativeUrl(),
source_project_value=project,
price_currency_value=currency
self.tic()
sale_supply = self.portal.portal_catalog.getResultValue(
portal_type='Sale Supply',
source_project__uid=project.getUid()
)
sale_supply.searchFolder(
portal_type='Sale Supply Line',
resource__relative_url="service_module/slapos_compute_node_subscription"
)[0].edit(base_price=99)
sale_supply.newContent(
portal_type="Sale Supply Line",
base_price=9,
resource_value=software_product
)
sale_supply.newContent(
portal_type="Sale Supply Line",
base_price=99,
resource="service_module/slapos_compute_node_subscription"
)
sale_supply.validate()
# some preparation
......@@ -736,7 +734,6 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
public_person = self.portal.portal_catalog.getResultValue(
portal_type='ERP5 Login', reference=public_reference).getParentValue()
self.login(owner_person.getUserId())
# and the instances
self.checkInstanceUnallocation(public_person.getUserId(),
public_reference, public_instance_title,
......@@ -853,22 +850,20 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
self.logout()
self.login(sale_person.getUserId())
sale_supply = self.portal.sale_supply_module.newContent(
portal_type="Sale Supply",
title="price for %s" % project.getRelativeUrl(),
source_project_value=project,
price_currency_value=currency
self.tic()
sale_supply = self.portal.portal_catalog.getResultValue(
portal_type='Sale Supply',
source_project__uid=project.getUid()
)
sale_supply.searchFolder(
portal_type='Sale Supply Line',
resource__relative_url="service_module/slapos_compute_node_subscription"
)[0].edit(base_price=99)
sale_supply.newContent(
portal_type="Sale Supply Line",
base_price=9,
resource_value=software_product
)
sale_supply.newContent(
portal_type="Sale Supply Line",
base_price=99,
resource="service_module/slapos_compute_node_subscription"
)
sale_supply.validate()
self.tic()
......
......@@ -110,6 +110,21 @@ sale_trade_condition = portal.sale_trade_condition_module.newContent(
)
sale_trade_condition.validate()
if is_compute_node_payable or is_instance_tree_payable:
# Create a draft sale supply to buy nodes / instances
# Sale Manager must manually enter the prices on it and validate
sale_supply = portal.sale_supply_module.newContent(
portal_type="Sale Supply",
title="Project Prices for %s" % project.getReference(),
source_project_value=project,
price_currency_value=currency_value
)
if is_compute_node_payable:
sale_supply.newContent(
portal_type="Sale Supply Line",
resource="service_module/slapos_compute_node_subscription"
)
if batch:
return project
return project.Base_redirect()
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