Commit b2bfe6eb authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_panel: Display and redirect to payment if you need to pay

   Display if the instance is payable (price currency/unit)
   Create and redirect to deposit payment if balance would require a deposit to the instance to work.
parent ce525239
......@@ -15,6 +15,7 @@ if "{uid}" in title:
instance_tree = portal.portal_catalog.getResultValue(
portal_type='Instance Tree',
validation_state="validated",
title={'query': title, 'key': 'ExactMatch'}
)
......@@ -61,5 +62,44 @@ if sla_xml:
</instance>""" % sla_xml
person.requestSoftwareInstance(**request_kw)
# XXX New service created.
return context.REQUEST.get('request_instance_tree').Base_redirect()
request_instance_tree = context.REQUEST.get('request_instance_tree')
def wrapWithShadow(person, instance):
# Evaluate if the user has to pay something,
# Since we need access to organisation_module on Entity_getDepositBalanceAmount
# evaluate as Shadow User.
subscription_request = instance.Item_createSubscriptionRequest(temp_object=True)
# Check if we could create the Subscription Request
if subscription_request is not None:
price = subscription_request.getPrice(None)
if price is not None and price != 0:
balance = person.Entity_getDepositBalanceAmount([subscription_request])
if balance - price < 0:
payment_mode=subscription_request.Base_getPaymentModeForCurrency(
subscription_request.getPriceCurrencyUid())
return person.Entity_createDepositPaymentTransaction(
subscription_list=[
subscription_request.asContext(total_price=price)],
payment_mode=payment_mode
)
web_site = context.getWebSiteValue()
assert web_site is not None
# Use proper acquisiton to generate the payment transaction
person = web_site.restrictedTraverse(person.getRelativeUrl())
payment_transaction = person.Person_restrictMethodAsShadowUser(
shadow_document=person,
callable_object=wrapWithShadow,
argument_list=[person, request_instance_tree])
if payment_transaction is not None:
return context.getPortalObject().REQUEST.RESPONSE.redirect(
payment_transaction.absolute_url() + "/PaymentTransaction_redirectToManualPayment",
status=302,
)
raise ValueError("NO")
return request_instance_tree.Base_redirect()
keep_items = None
portal = context.getPortalObject()
if aggregate_uid is None:
software_product_list = [x for x in context.getPortalObject().portal_catalog(
......@@ -6,13 +7,61 @@ if aggregate_uid is None:
url_string=url_string
) if x.getFollowUpUid() == context.getUid()]
if len(software_product_list) == 1:
keep_items = {
'field_your_aggregate_uid': software_product_list[0].getParentUid(),
'your_aggregate_uid': software_product_list[0].getParentUid(),
'aggregate_uid': software_product_list[0].getParentUid()
software_product = software_product_list[0].getParentValue()
keep_items = {
'field_your_aggregate_uid': software_product.getUid(),
'your_aggregate_uid': software_product.getUid(),
'aggregate_uid': software_product.getUid()
}
context.log('keep_items %s' % str(keep_items))
destination_value = portal.portal_membership.getAuthenticatedMember().getUserValue()
allocation_predicate_list = context.Project_getSoftwareProductPredicateList(
software_product=software_product,
software_product_release=software_product_list[0],
destination_value=destination_value)
if allocation_predicate_list:
def wrapWithShadow(destination_value, allocation_predicate_list, project):
try:
subscription_request = software_product.Resource_createSubscriptionRequest(
destination_value,
# [software_type, software_release],
allocation_predicate_list[0].getVariationCategoryList(),
project,
temp_object=True
)
except AssertionError:
price = 0.0
price_information = None
else:
price = subscription_request.getPrice(None)
is_future_balance_negative = 0
if price is not None and price != 0:
price_information = '%s %s/%s' % (price,
subscription_request.getPriceCurrencyTitle(),
subscription_request.getQuantityUnitTitle())
assert subscription_request.getDestinationDecision() == destination_value.getRelativeUrl()
assert subscription_request.getLedger() == "automated"
balance = destination_value.Entity_getDepositBalanceAmount(
[subscription_request]
)
if balance - price < 0:
is_future_balance_negative = 1
return price_information, is_future_balance_negative
price_information, is_future_balance_negative = destination_value.Person_restrictMethodAsShadowUser(
shadow_document=destination_value,
callable_object=wrapWithShadow,
argument_list=[destination_value, allocation_predicate_list, context])
if price_information is not None:
keep_items['is_future_balance_negative'] = is_future_balance_negative
keep_items['price_information'] = price_information
return context.Base_renderForm(
'Project_viewRequestInstanceTreeDialog', keep_items=keep_items
......
......@@ -106,6 +106,8 @@
<list>
<string>your_url_string</string>
<string>your_title</string>
<string>your_price_information</string>
<string>your_balance_information</string>
</list>
</value>
</item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>default</string>
<string>editable</string>
<string>enabled</string>
<string>required</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_balance_information</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_dialog_mode_title</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Note</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: context.Base_translateString("You are going to be redirected to Payment")</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: request.get(\'is_future_balance_negative\')</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>default</string>
<string>editable</string>
<string>enabled</string>
<string>required</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_price_information</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>enabled</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_dialog_mode_title</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Price</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: request.get(\'price_information\')</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: request.get(\'price_information\')</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>Price Information</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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