Commit 0f2be0e3 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_erp5: (test) Replace the way we add deposit organisation

   For now we rely on Base_createExternalPaymentTransactionFromOutstandingAmountAndRedirect for pay subscriptions for customer organisation because it requires update security and review the procedure and how UI will handle it.

  So we invoke directly Entity_createDepositPaymentTransaction with the organisation's subscriptions.
parent 06723fd9
...@@ -8,7 +8,7 @@ from Products.ERP5Type.Message import translateString ...@@ -8,7 +8,7 @@ from Products.ERP5Type.Message import translateString
portal = context.getPortalObject() portal = context.getPortalObject()
if not subscription_list: if not subscription_list:
raise ValueError('You need to provide at least one Invoice transaction') raise ValueError('You need to provide at least one Subscription Request')
payment_tag = 'Entity_addDepositPayment_%s' % context.getUid() payment_tag = 'Entity_addDepositPayment_%s' % context.getUid()
if context.REQUEST.get(payment_tag, None) is not None: if context.REQUEST.get(payment_tag, None) is not None:
......
...@@ -17,7 +17,7 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -17,7 +17,7 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
User does not pay the subscription, which is cancelled after some time User does not pay the subscription, which is cancelled after some time
""" """
with PinnedDateTime(self, DateTime('2020/05/19')): with PinnedDateTime(self, DateTime('2020/05/19')):
owner_person, currency, project = self.bootstrapAccountingTest() owner_person, _, project = self.bootstrapAccountingTest()
# Ensure no unexpected object has been created # Ensure no unexpected object has been created
# 2 assignment # 2 assignment
# 2 sale trade condition # 2 sale trade condition
...@@ -32,9 +32,14 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -32,9 +32,14 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
aggregate__uid=project.getUid() aggregate__uid=project.getUid()
) )
self.assertEqual(subscription_request.getSimulationState(), "submitted") self.assertEqual(subscription_request.getSimulationState(), "submitted")
deposit_outstanding_amount_list = owner_person.Entity_getOutstandingDepositAmountList()
self.assertEqual(len(deposit_outstanding_amount_list), 1)
self.assertEqual(subscription_request.getUid(),
deposit_outstanding_amount_list[0].getUid())
with PinnedDateTime(self, DateTime('2021/04/04')): with PinnedDateTime(self, DateTime('2021/04/04')):
payment_transaction = owner_person.Entity_addDepositPayment(99*10, currency.getRelativeUrl()) payment_transaction = owner_person.Entity_createDepositPaymentTransaction(
deposit_outstanding_amount_list)
# payzen interface will only stop the payment # payzen interface will only stop the payment
payment_transaction.stop() payment_transaction.stop()
self.tic() self.tic()
...@@ -209,9 +214,24 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -209,9 +214,24 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
# Add deposit # Add deposit
with PinnedDateTime(self, creation_date + 2): with PinnedDateTime(self, creation_date + 2):
for person in person_list: for person in person_list:
payment_transaction = person.Entity_addDepositPayment(99*100, currency.getRelativeUrl()) # Just add some large sum, so instances dont get blocked.
tmp_subscription_request = self.portal.portal_trash.newContent(
portal_type='Subscription Request',
temp_object=True,
start_date=DateTime(),
# source_section rely on default trade condition, like the rest.
destination_value=person,
destination_section_value=person,
ledger_value=self.portal.portal_categories.ledger.automated,
price_currency=currency.getRelativeUrl(),
total_price=99 * 10
)
payment_transaction = person.Entity_createDepositPaymentTransaction(
[tmp_subscription_request])
# payzen interface will only stop the payment # payzen interface will only stop the payment
payment_transaction.stop() payment_transaction.stop()
self.tic()
################################################## ##################################################
# Add first batch of service, and generate invoices # Add first batch of service, and generate invoices
...@@ -299,7 +319,7 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -299,7 +319,7 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
""" """
creation_date = DateTime('2020/02/19') creation_date = DateTime('2020/02/19')
with PinnedDateTime(self, creation_date): with PinnedDateTime(self, creation_date):
owner_person, currency, project = self.bootstrapAccountingTest() owner_person, _, project = self.bootstrapAccountingTest()
owner_person.edit(default_address_region='america/south/brazil') owner_person.edit(default_address_region='america/south/brazil')
# Ensure no unexpected object has been created # Ensure no unexpected object has been created
...@@ -310,10 +330,16 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -310,10 +330,16 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
################################################## ##################################################
# Add deposit (0.1 to prevent discount generation) # Add deposit (0.1 to prevent discount generation)
deposit_outstanding_amount_list = owner_person.Entity_getOutstandingDepositAmountList()
self.assertEqual(len(deposit_outstanding_amount_list), 1)
self.assertEqual(sum([i.total_price for i in deposit_outstanding_amount_list]), 42)
with PinnedDateTime(self, creation_date + 0.1): with PinnedDateTime(self, creation_date + 0.1):
payment_transaction = owner_person.Entity_addDepositPayment(99*100, currency.getRelativeUrl()) payment_transaction = owner_person.Entity_createDepositPaymentTransaction(
deposit_outstanding_amount_list)
# payzen interface will only stop the payment # payzen interface will only stop the payment
payment_transaction.stop() payment_transaction.stop()
self.tic()
self.logout() self.logout()
self.login() self.login()
......
...@@ -56,9 +56,38 @@ class TestSlapOSCRMScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -56,9 +56,38 @@ class TestSlapOSCRMScenario(TestSlapOSVirtualMasterScenarioMixin):
################################################## ##################################################
# Add deposit # Add deposit
with PinnedDateTime(self, creation_date): with PinnedDateTime(self, creation_date):
payment_transaction = owner_person.Entity_addDepositPayment(99*100, currency.getRelativeUrl()) # Pay deposit to validate virtual master
# payzen interface will only stop the payment self.login(owner_person.getUserId())
deposit_amount = 42.0
ledger = self.portal.portal_categories.ledger.automated
outstanding_amount_list = 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)
# Ensure to pay from the website
outstanding_amount = self.web_site.restrictedTraverse(outstanding_amount_list[0].getRelativeUrl())
outstanding_amount.Base_createExternalPaymentTransactionFromOutstandingAmountAndRedirect()
self.tic()
self.logout()
self.login()
payment_transaction = self.portal.portal_catalog.getResultValue(
portal_type="Payment Transaction",
destination_section_uid=owner_person.getUid(),
simulation_state="started"
)
self.assertEqual(payment_transaction.getSpecialiseValue().getTradeConditionType(), "deposit")
# payzen/wechat or accountant will only stop the payment
payment_transaction.stop() payment_transaction.stop()
self.tic()
assert payment_transaction.receivable.getGroupingReference(None) is not None
self.login(owner_person.getUserId())
amount = sum([i.total_price for i in owner_person.Entity_getOutstandingDepositAmountList(
currency.getUid(), ledger_uid=ledger.getUid())])
self.assertEqual(0, amount)
################################################## ##################################################
# Add first batch of service, and generate invoices # Add first batch of service, and generate invoices
......
...@@ -150,7 +150,6 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template): ...@@ -150,7 +150,6 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template):
'slapos_accounting/OpenSaleOrder_archiveIfUnusedItem', 'slapos_accounting/OpenSaleOrder_archiveIfUnusedItem',
'slapos_accounting/Base_getAccountForUse', 'slapos_accounting/Base_getAccountForUse',
'slapos_accounting/Entity_createPaymentTransactionAction', 'slapos_accounting/Entity_createPaymentTransactionAction',
'slapos_accounting/Entity_getDepositBalanceAmount',
'slapos_accounting/Movement_getPriceCalculationOperandDict', 'slapos_accounting/Movement_getPriceCalculationOperandDict',
'slapos_accounting/PaymentTransaction_acceptDepositPayment', 'slapos_accounting/PaymentTransaction_acceptDepositPayment',
'slapos_accounting/PaymentTransaction_getExternalPaymentId', 'slapos_accounting/PaymentTransaction_getExternalPaymentId',
...@@ -239,7 +238,6 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template): ...@@ -239,7 +238,6 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template):
'slapos_panel/ComputerNetwork_getNewsDict', 'slapos_panel/ComputerNetwork_getNewsDict',
'slapos_panel/ComputerNetwork_invalidateOnSlaposPanel', 'slapos_panel/ComputerNetwork_invalidateOnSlaposPanel',
'slapos_panel/Document_getNewsDict', 'slapos_panel/Document_getNewsDict',
'slapos_panel/Entity_createExternalPaymentTransactionFromDepositAndRedirect',
'slapos_panel/Event_getSafeSourceTitle', 'slapos_panel/Event_getSafeSourceTitle',
'slapos_panel/InstanceNode_addSlapOSAllocationSupply', 'slapos_panel/InstanceNode_addSlapOSAllocationSupply',
'slapos_panel/InstanceTreeModule_selectRequestProject', 'slapos_panel/InstanceTreeModule_selectRequestProject',
...@@ -286,7 +284,6 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template): ...@@ -286,7 +284,6 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template):
'slapos_panel/InstanceTree_proposeUpgradeDecision', 'slapos_panel/InstanceTree_proposeUpgradeDecision',
'slapos_panel/InstanceTree_searchUpgradableSoftwareReleaseList', 'slapos_panel/InstanceTree_searchUpgradableSoftwareReleaseList',
'slapos_panel/PaymentTransaction_triggerPaymentCheckAlarmAndRedirectToPanel', 'slapos_panel/PaymentTransaction_triggerPaymentCheckAlarmAndRedirectToPanel',
'slapos_panel/SaleInvoiceTransaction_createExternalPaymentTransactionFromAmountAndRedirect',
'slapos_panel_compatibility/Base_getComputerToken', 'slapos_panel_compatibility/Base_getComputerToken',
'slapos_parameter_editor/SoftwareProductModule_updateParameterEditorTestDialog', 'slapos_parameter_editor/SoftwareProductModule_updateParameterEditorTestDialog',
'slapos_parameter_editor/SoftwareProductModule_validateParameterEditorTestDialog', 'slapos_parameter_editor/SoftwareProductModule_validateParameterEditorTestDialog',
......
...@@ -338,7 +338,7 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -338,7 +338,7 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
owner_person = self.portal.portal_catalog.getResultValue( owner_person = self.portal.portal_catalog.getResultValue(
portal_type="ERP5 Login", portal_type="ERP5 Login",
reference=owner_reference).getParentValue() reference=owner_reference).getParentValue()
#owner_person.setCareerSubordinationValue(seller_organisation) # owner_person.setCareerSubordinationValue(seller_organisation)
self.tic() self.tic()
...@@ -479,9 +479,24 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -479,9 +479,24 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
# to check if other services are ok # to check if other services are ok
total_price = 1234 total_price = 1234
# Action to submit project subscription # Action to submit project subscription
def wrapWithShadow(person, *arg): def wrapWithShadow(person, total_price, currency):
return person.Entity_addDepositPayment(*arg) # pre-include a large amount of w/o any subscription request using a temp
# object. It requires to be created under shadow user for security reasons.
tmp_subscription_request = self.portal.portal_trash.newContent(
portal_type='Subscription Request',
temp_object=True,
start_date=DateTime(),
destination_value=person,
destination_section_value=person,
ledger_value=self.portal.portal_categories.ledger.automated,
price_currency=currency,
total_price=total_price
)
return person.Entity_createDepositPaymentTransaction([tmp_subscription_request])
payment_transaction = owner_person.Person_restrictMethodAsShadowUser( payment_transaction = owner_person.Person_restrictMethodAsShadowUser(
shadow_document=owner_person, shadow_document=owner_person,
callable_object=wrapWithShadow, callable_object=wrapWithShadow,
...@@ -496,6 +511,13 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -496,6 +511,13 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
assert payment_transaction.receivable.getGroupingReference(None) is not None assert payment_transaction.receivable.getGroupingReference(None) is not None
# Check if the Deposit lead to proper balance.
self.assertEqual(
owner_person.Entity_getDepositBalanceAmount(
currency_uid=currency.getUid(),
mirror_section_uid=payment_transaction.getSourceSectionUid()),
total_price)
self.checkERP5StateBeforeExit() self.checkERP5StateBeforeExit()
...@@ -562,11 +584,6 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -562,11 +584,6 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
self.login() self.login()
project = self.portal.restrictedTraverse(project_relative_url) project = self.portal.restrictedTraverse(project_relative_url)
payment_transaction = customer_section_organisation.Entity_addDepositPayment(99*10, currency.getRelativeUrl())
# payzen interface will only stop the payment
payment_transaction.stop()
self.tic()
preference = self.portal.portal_preferences.slapos_default_system_preference preference = self.portal.portal_preferences.slapos_default_system_preference
preference.edit( preference.edit(
preferred_subscription_assignment_category_list=[ preferred_subscription_assignment_category_list=[
...@@ -674,6 +691,30 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -674,6 +691,30 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
dedicated_trade_condition.validate() dedicated_trade_condition.validate()
self.tic() self.tic()
# Pay deposit to validate virtual master + one computer, for the organisation
# For now we cannot rely on user payments
deposit_amount = 42.0 + 99.0
ledger = self.portal.portal_categories.ledger.automated
outstanding_amount_list = customer_section_organisation.Entity_getOutstandingDepositAmountList(
currency.getUid(), ledger_uid=ledger.getUid())
amount = sum([i.total_price for i in outstanding_amount_list])
self.assertEqual(amount, deposit_amount)
payment_transaction = customer_section_organisation.Entity_createDepositPaymentTransaction(
outstanding_amount_list)
self.tic()
self.assertEqual(payment_transaction.getSpecialiseValue().getTradeConditionType(), "deposit")
# payzen/wechat or accountant will only stop the payment
payment_transaction.stop()
self.tic()
assert payment_transaction.receivable.getGroupingReference(None) is not None
outstanding_amount_list = customer_section_organisation.Entity_getOutstandingDepositAmountList(
currency.getUid(), ledger_uid=ledger.getUid())
self.assertEqual(0, sum([i.total_price for i in outstanding_amount_list]))
with PinnedDateTime(self, DateTime('2024/02/17 01:01')): with PinnedDateTime(self, DateTime('2024/02/17 01:01')):
public_instance_title = 'Public title %s' % self.generateNewId() public_instance_title = 'Public title %s' % self.generateNewId()
self.checkInstanceAllocation(public_person.getUserId(), self.checkInstanceAllocation(public_person.getUserId(),
...@@ -727,8 +768,8 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -727,8 +768,8 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
# Check accounting # Check accounting
transaction_list = self.portal.account_module.receivable.Account_getAccountingTransactionList(mirror_section_uid=customer_section_organisation.getUid()) transaction_list = self.portal.account_module.receivable.Account_getAccountingTransactionList(mirror_section_uid=customer_section_organisation.getUid())
assert len(transaction_list) == 2, len(transaction_list) assert len(transaction_list) == 2, len(transaction_list)
assert transaction_list[0].total_price == 990.0, transaction_list[0].total_price assert transaction_list[0].total_price == 141.0, transaction_list[0].total_price
assert transaction_list[1].total_price == -990.0, transaction_list[1].total_price assert transaction_list[1].total_price == -141.0, transaction_list[1].total_price
self.login() self.login()
...@@ -737,6 +778,7 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -737,6 +778,7 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
# 3 allocation supply / line / cell # 3 allocation supply / line / cell
# 1 compute node # 1 compute node
# 2 credential request # 2 credential request
# 1 event
# 1 instance tree # 1 instance tree
# 6 open sale order / line # 6 open sale order / line
# 5 (can reduce to 2) assignment # 5 (can reduce to 2) assignment
...@@ -748,7 +790,7 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -748,7 +790,7 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
# 1 software instance # 1 software instance
# 1 software product # 1 software product
# 3 subscription requests # 3 subscription requests
self.assertRelatedObjectCount(project, 52) self.assertRelatedObjectCount(project, 53)
self.checkERP5StateBeforeExit() 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