Commit a98f4acd authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_subscription_request: Allow skip Payment if the user has a acceptable contract

parent 9dddb882
portal = context.getPortalObject()
payment = context.SubscriptionRequest_verifyPaymentBalanceIsReady() payment = context.SubscriptionRequest_verifyPaymentBalanceIsReady()
if payment is not None and payment.getSimulationState() in ['stopped', 'deliveried']:
if payment is not None:
if payment.getSimulationState() in ['stopped', 'deliveried']:
# Payment Transaction is payed # Payment Transaction is payed
return True return True
# Payment Transaction ins't payed person = context.getDestinationSectionValue()
contract = portal.portal_catalog.getResultValue(
portal_type="Cloud Contract",
default_destination_section_uid=person.getUid(),
validation_state=['invalidated', 'validated'],
)
if (contract is not None and contract.getMaximumInvoiceDelay() > 0 and \
not (person.Entity_statSlapOSOutstandingAmount() > 0)):
return True
# Payment Transaction isn't payed
return False return False
...@@ -235,30 +235,37 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin): ...@@ -235,30 +235,37 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
payment = invoice.getCausalityRelatedValue(portal_type="Payment Transaction") payment = invoice.getCausalityRelatedValue(portal_type="Payment Transaction")
self.assertNotEqual(payment, None) self.assertNotEqual(payment, None)
def checkPlannedSubscriptionRequest(self, subscription_request, email, subscription_condition, slave=0): def checkPlannedSubscriptionRequest(self, subscription_request, email,
self.checkSubscriptionRequest(subscription_request, email, subscription_condition, slave=slave) subscription_condition, slave=0):
self.checkSubscriptionRequest(subscription_request, email,
subscription_condition, slave=slave)
self.assertEqual(subscription_request.getSimulationState(), "planned") self.assertEqual(subscription_request.getSimulationState(), "planned")
def checkOrderedSubscriptionRequest(self, subscription_request, email,
def checkOrderedSubscriptionRequest(self, subscription_request, email, subscription_condition, slave=0, subscription_condition, slave=0,
notification_message="subscription_request-confirmation-with-password"): notification_message="subscription_request-confirmation-with-password"):
self.checkSubscriptionRequest(subscription_request, email, subscription_condition, slave=slave) self.checkSubscriptionRequest(subscription_request, email,
subscription_condition, slave=slave)
self.assertEqual(subscription_request.getSimulationState(), "ordered") self.assertEqual(subscription_request.getSimulationState(), "ordered")
self.checkBootstrapUser(subscription_request) self.checkBootstrapUser(subscription_request)
self.checkEmailNotification(subscription_request, notification_message) self.checkEmailNotification(subscription_request, notification_message)
def checkConfirmedSubscriptionRequest(self, subscription_request, email, subscription_condition, slave=0, def checkConfirmedSubscriptionRequest(self, subscription_request, email,
subscription_condition, slave=0,
notification_message="subscription_request-payment-is-ready"): notification_message="subscription_request-payment-is-ready"):
self.checkSubscriptionRequest(subscription_request, email, subscription_condition, slave=slave) self.checkSubscriptionRequest(subscription_request, email,
subscription_condition, slave=slave)
payment = subscription_request.SubscriptionRequest_verifyPaymentBalanceIsReady() payment = subscription_request.SubscriptionRequest_verifyPaymentBalanceIsReady()
self.assertNotEqual(payment, None) self.assertNotEqual(payment, None)
self.assertEqual(payment.getSimulationState(), 'started') self.assertEqual(payment.getSimulationState(), 'started')
self.assertEqual(subscription_request.getSimulationState(), "confirmed") self.assertEqual(subscription_request.getSimulationState(), "confirmed")
self.checkEmailPaymentNotification(subscription_request, notification_message) self.checkEmailPaymentNotification(subscription_request, notification_message)
def checkStartedSubscriptionRequest(self, subscription_request, email, subscription_condition, slave=0, def checkStartedSubscriptionRequest(self, subscription_request, email,
subscription_condition, slave=0,
notification_message="subscription_request-instance-is-ready"): notification_message="subscription_request-instance-is-ready"):
self.checkSubscriptionRequest(subscription_request, email, subscription_condition, slave=slave) self.checkSubscriptionRequest(subscription_request, email,
subscription_condition, slave=slave)
self.assertEqual(subscription_request.getSimulationState(), "started") self.assertEqual(subscription_request.getSimulationState(), "started")
self.checkEmailInstanceNotification(subscription_request, notification_message) self.checkEmailInstanceNotification(subscription_request, notification_message)
...@@ -301,7 +308,8 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin): ...@@ -301,7 +308,8 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
authAmount = (int(self.expected_individual_price_with_tax*100)*1-int(self.expected_reservation_fee*100))*quantity authAmount = (int(self.expected_individual_price_with_tax*100)*1-int(self.expected_reservation_fee*100))*quantity
self.assertEqual(payment.getSourceSection(), self.expected_source_section) self.assertEqual(payment.getSourceSection(), self.expected_source_section)
self.assertEqual(payment.getSourcePayment(), "%s/bank_account" % self.expected_source_section) self.assertEqual(payment.getSourcePayment(),
"%s/bank_account" % self.expected_source_section)
self.assertEqual(int(payment.PaymentTransaction_getTotalPayablePrice()*100), self.assertEqual(int(payment.PaymentTransaction_getTotalPayablePrice()*100),
...@@ -373,7 +381,8 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin): ...@@ -373,7 +381,8 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
# Check Payment # Check Payment
self.assertEqual(payment.getSourceSection(), self.expected_source_section) self.assertEqual(payment.getSourceSection(), self.expected_source_section)
self.assertEqual(payment.getSourcePayment(), "%s/bank_account" % self.expected_source_section) self.assertEqual(payment.getSourcePayment(),
"%s/bank_account" % self.expected_source_section)
self.tic() self.tic()
self.assertEqual(payment.getSimulationState(), "stopped") self.assertEqual(payment.getSimulationState(), "stopped")
...@@ -411,8 +420,10 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin): ...@@ -411,8 +420,10 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
self.assertEqual(line.getQuantity(), quantity) self.assertEqual(line.getQuantity(), quantity)
self.assertEqual(round(line.getPrice(), 2), self.expected_reservation_fee_without_tax) self.assertEqual(round(line.getPrice(), 2), self.expected_reservation_fee_without_tax)
if line.getResource() == "service_module/slapos_tax": if line.getResource() == "service_module/slapos_tax":
self.assertEqual(round(line.getQuantity(), 2), round(self.expected_reservation_quantity_tax*quantity, 2)) self.assertEqual(round(line.getQuantity(), 2),
self.assertEqual(round(line.getTotalPrice(), 2), round(self.expected_reservation_tax*quantity, 2)) round(self.expected_reservation_quantity_tax*quantity, 2))
self.assertEqual(round(line.getTotalPrice(), 2),
round(self.expected_reservation_tax*quantity, 2))
self.assertEqual(round(invoice.getTotalPrice(), 2), self.expected_reservation_fee*quantity) self.assertEqual(round(invoice.getTotalPrice(), 2), self.expected_reservation_fee*quantity)
...@@ -836,13 +847,22 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin): ...@@ -836,13 +847,22 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
# Instances should be allocated # Instances should be allocated
self.checkAllocationOnRelatedInstance(subscription_request) self.checkAllocationOnRelatedInstance(subscription_request)
if not self.expected_free_reservation:
# In a scenario where invitation token is used, we expect
# that this script outputs True as user is below the maximum limit.
expected_test_payment_balance = False
expected_slap_state_after_subscription_is_confirmed = 'stop_requested'
else:
expected_test_payment_balance = True
expected_slap_state_after_subscription_is_confirmed = 'start_requested'
# Check if instance is on confirmed state # Check if instance is on confirmed state
for subscription_request in subscription_request_list: for subscription_request in subscription_request_list:
self.checkConfirmedSubscriptionRequest(subscription_request, self.checkConfirmedSubscriptionRequest(subscription_request,
default_email_text, self.subscription_condition) default_email_text, self.subscription_condition)
# Assert that First month isn't payed self.assertEqual(expected_test_payment_balance,
self.assertFalse(
subscription_request.SubscriptionRequest_testPaymentBalance()) subscription_request.SubscriptionRequest_testPaymentBalance())
self.assertEquals('start_requested', self.assertEquals('start_requested',
...@@ -853,10 +873,10 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin): ...@@ -853,10 +873,10 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
self.tic() self.tic()
for subscription_request in subscription_request_list: for subscription_request in subscription_request_list:
self.assertFalse( self.assertEqual(expected_test_payment_balance,
subscription_request.SubscriptionRequest_testPaymentBalance()) subscription_request.SubscriptionRequest_testPaymentBalance())
self.assertEquals('stop_requested', self.assertEquals(expected_slap_state_after_subscription_is_confirmed,
subscription_request.getAggregateValue().getSlapState()) subscription_request.getAggregateValue().getSlapState())
def checkSubscriptionDeploymentAndSimulationWithReversalTransaction(self, default_email_text, subscription_server): def checkSubscriptionDeploymentAndSimulationWithReversalTransaction(self, default_email_text, subscription_server):
...@@ -882,10 +902,6 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin): ...@@ -882,10 +902,6 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
self.assertEqual('start_requested', self.assertEqual('start_requested',
subscription_request.getAggregateValue().getSlapState()) subscription_request.getAggregateValue().getSlapState())
# It is requireds a second interaction so the instance is
# correctly started
self.assertEqual("confirmed", subscription_request.getSimulationState())
# On the second loop that email is send and state is moved to started # On the second loop that email is send and state is moved to started
self.stepCallSlaposSubscriptionRequestProcessConfirmedAlarm() self.stepCallSlaposSubscriptionRequestProcessConfirmedAlarm()
self.tic() self.tic()
...@@ -907,6 +923,7 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin): ...@@ -907,6 +923,7 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
self._checkSubscriptionDeploymentAndSimulation( self._checkSubscriptionDeploymentAndSimulation(
subscription_request_list, default_email_text, subscription_server) subscription_request_list, default_email_text, subscription_server)
if not self.expected_free_reservation:
for subscription_request in subscription_request_list: for subscription_request in subscription_request_list:
self.checkAndPayFirstMonth(subscription_request) self.checkAndPayFirstMonth(subscription_request)
self.tic() self.tic()
...@@ -921,10 +938,6 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin): ...@@ -921,10 +938,6 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
self.assertEqual('start_requested', self.assertEqual('start_requested',
subscription_request.getAggregateValue().getSlapState()) subscription_request.getAggregateValue().getSlapState())
# It is requireds a second interaction so the instance is
# correctly started
self.assertEqual("confirmed", subscription_request.getSimulationState())
# On the second loop that email is send and state is moved to started # On the second loop that email is send and state is moved to started
self.stepCallSlaposSubscriptionRequestProcessConfirmedAlarm() self.stepCallSlaposSubscriptionRequestProcessConfirmedAlarm()
self.tic() self.tic()
......
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