Commit c954ee83 authored by Romain Courteaud's avatar Romain Courteaud

slapos_accounting: calculating the outstanding deposit amount need to also...

slapos_accounting: calculating the outstanding deposit amount need to also check the balance which include the VAT

Test: ensure a second service can be ordered
parent 53993ff4
Pipeline #38309 failed with stage
in 0 seconds
......@@ -36,4 +36,5 @@ for subscription_request_brain in portal.portal_catalog(
object_dict[object_index] = [object_dict[object_index][0],
subscription_request_total_price]
return [s.asContext(total_price=price) for s, price in object_dict.values()]
# Add the current balance, to ensure customer provide enough deposit to match the VAT
return [s.asContext(total_price=price - s.getDestinationSectionValue().Entity_getDepositBalanceAmount([s])) for s, price in object_dict.values()]
......@@ -676,7 +676,10 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
self.assertEqual(person.getUserId(), person_user_id)
subscription_request = self.checkServiceSubscriptionRequest(instance_tree, 'submitted')
self.assertEqual(subscription_request.getTotalPrice(), deposit_amount)
self.assertEqual(
subscription_request.getTotalPrice() - person.Entity_getDepositBalanceAmount([subscription_request]),
deposit_amount
)
self.tic()
......@@ -689,7 +692,7 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
# Ensure to pay from the website
outstanding_amount = self.web_site.restrictedTraverse(outstanding_amount_list[0].getRelativeUrl())
outstanding_amount.Base_createExternalPaymentTransactionFromOutstandingAmountAndRedirect()
person.REQUEST.set('Entity_addDepositPayment_%s' % person.getUid(), None)
self.tic()
self.logout()
self.login()
......
......@@ -503,13 +503,13 @@ class TestSlapOSSubscriptionScenario(TestSlapOSSubscriptionScenarioMixin):
self.login(project_owner_person.getUserId())
# Pay deposit to validate virtual master
deposit_amount = 99.0
deposit_amount = 102.36
ledger = self.portal.portal_categories.ledger.automated
outstanding_amount_list = project_owner_person.Entity_getOutstandingDepositAmountList(
currency.getUid(), ledger_uid=ledger.getUid())
amount = sum([i.total_price for i in outstanding_amount_list])
self.assertEqual(amount, deposit_amount)
self.assertAlmostEqual(amount, deposit_amount)
self.login()
......
......@@ -956,6 +956,9 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
reference=public_reference).getParentValue()
with PinnedDateTime(self, DateTime('2024/02/17 01:01')):
# Simulate access from compute_node, to open the capacity scope
self.login()
self.simulateSlapgridSR(public_server)
public_instance_title = 'Public title %s' % self.generateNewId()
self.checkInstanceAllocationWithDeposit(public_person.getUserId(),
public_reference, public_instance_title,
......@@ -963,6 +966,14 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
public_server, project.getReference(),
9.0, currency)
with PinnedDateTime(self, DateTime('2024/02/17 01:02')):
public_instance_title2 = 'Public title %s' % self.generateNewId()
self.checkInstanceAllocationWithDeposit(public_person.getUserId(),
public_reference, public_instance_title2,
public_server_software, public_instance_type,
public_server, project.getReference(),
10.8, currency)
self.login()
public_person = self.portal.portal_catalog.getResultValue(
portal_type='ERP5 Login', reference=public_reference).getParentValue()
......@@ -973,6 +984,10 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
public_reference, public_instance_title,
public_server_software, public_instance_type, public_server,
project.getReference())
self.checkInstanceUnallocation(public_person.getUserId(),
public_reference, public_instance_title2,
public_server_software, public_instance_type, public_server,
project.getReference())
# and uninstall some software on them
self.logout()
......@@ -1008,10 +1023,10 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
# Check accounting
transaction_list = self.portal.account_module.receivable.Account_getAccountingTransactionList(mirror_section_uid=public_person.getUid())
assert len(transaction_list) == 2, len(transaction_list)
assert len(transaction_list) == 4, len(transaction_list)
self.assertSameSet(
[x.total_price for x in transaction_list],
[9.0, -9.0],
[9.0, -9.0, 10.8, -10.8],
[x.total_price for x in transaction_list]
)
......@@ -1022,19 +1037,19 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
# 3 allocation supply / line / cell
# 1 compute node
# 2 credential request
# 2 event
# 1 instance tree
# 6 open sale order / line
# 3 event
# 2 instance tree
# 9 open sale order / line
# 5 (can reduce to 2) assignment
# 16 simulation mvt
# 3 packing list / line
# 23 simulation mvt
# 4 packing list / line
# 3 sale supply / line
# 2 sale trade condition
# 1 software installation
# 1 software instance
# 2 software instance
# 1 software product
# 3 subscription requests
self.assertRelatedObjectCount(project, 53)
# 4 subscription requests
self.assertRelatedObjectCount(project, 68)
self.checkERP5StateBeforeExit()
......
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