Commit 91d60711 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_subscription_request: Use activities everywhere that it is possible to defer heavy actions.

parent 018d5477
......@@ -19,4 +19,4 @@ user_input_dict = {
"amount" : amount}
return context.SubscriptionRequestModule_requestSubscritptionProxy(
default_email_text, user_input_dict=user_input_dict, batch_mode=0)
default_email_text, subscription_reference, user_input_dict=user_input_dict, batch_mode=0)
from zExceptions import Unauthorized
from DateTime import DateTime
import json
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
# You always needs a user here
person = context.SubscriptionRequest_createUser(email, user_input_dict['name'])
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
if person is None:
# Create a Person document in order to generate the invoice.
person = portal.person_module.newContent(
portal_type="Person",
default_email_text=email,
first_name=user_input_dict["name"])
login = person.newContent(portal_type="ERP5 Login",
reference=email,
# Please generate a LAAARGE random password.
password=email)
login.validate()
person.validate()
person.immediateReindexObject()
login.immediateReindexObject()
# Get Subscription condition for this Subscription Request
subscription_configuration = {
"instance_xml": "", #context.getTextContent(),
"title": "%s" % "Subscription for %s %s" % ("vm", email), #(context.getTitle(), email),
"software_type": "cluster",#context.getSourceReference(),
"url": "http://ww.com/sss",#context.getUrlString(),
"shared": 0, #context.getRootSlave(),
"subject_list": [], #context.getSubjectList(),
"sla_xml": "", #context.getSlaXml()
}
software_title = subscription_configuration["title"]
subscription_request = portal.portal_catalog.getResultValue(
portal_type='Subscription Request',
title=software_title,
validation_state=('draft', 'submitted',)
)
# How to consider that an Subscription request is already there.
# Perhaps if a user return, he should be able to resume a subscription process.
if subscription_request is not None:
return json.dumps("already-requested")
now = DateTime()
subscription_request = context.subscription_request_module.newContent(
source_reference=subscription_configuration["software_type"],
title=software_title,
url_string=subscription_configuration["url"],
text_content=subscription_configuration["instance_xml"],
start_date=now,
stop_date=now + 30,
root_slave=subscription_configuration["shared"],
subject_list=subscription_configuration["subject_list"],
portal_type="Subscription Request",
destination_section_value=person
)
subscription_request.setDefaultEmailText(email)
def wrapWithShadow(subscription_request, amount):
def wrapWithShadow(subscription_request, amount, subscription_reference):
subscription_request.activate(tag="subscription_condition_%s" % subscription_request.getId()
).SubscriptionRequest_applyCondition(subscription_reference)
return subscription_request.SubscriptionRequest_requestPaymentTransaction(amount=amount,
tag="subscription_%s" % subscription_request.getId())
tag="subscription_%s" % subscription_request.getId())
payment = person.Person_restrictMethodAsShadowUser(
shadow_document=person,
callable_object=wrapWithShadow,
argument_list=[subscription_request, user_input_dict["amount"]])
argument_list=[subscription_request, user_input_dict["amount"], subscription_reference])
if batch_mode:
return {'subscription' : subscription_request.getRelativeUrl(), 'payment': payment.getRelativeUrl() }
def wrapRedirectWithShadow(payment_transaction, web_site):
return payment_transaction.PaymentTransaction_redirectToManualPayzenPayment(web_site)
return payment.PaymentTransaction_redirectToSubscriptionManualPayzenPayment(context.getWebSiteValue())
return person.Person_restrictMethodAsShadowUser(
shadow_document=person,
callable_object=wrapRedirectWithShadow,
argument_list=[payment, context.getWebSiteValue()])
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>email, user_input_dict={}, batch_mode=True, REQUEST=None</string> </value>
<value> <string>email, subscription_reference, user_input_dict={}, batch_mode=True, REQUEST=None</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
......
......@@ -53,7 +53,9 @@
<item>
<key> <string>bottom</string> </key>
<value>
<list/>
<list>
<string>listbox</string>
</list>
</value>
</item>
<item>
......@@ -71,9 +73,7 @@
<item>
<key> <string>left</string> </key>
<value>
<list>
<string>listbox</string>
</list>
<list/>
</value>
</item>
<item>
......
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
subscription_condition = context.portal_catalog(
portal_type="Subscription Condition",
reference=subscription_reference,
validation_state="validated")
# Get Subscription condition for this Subscription Request
subscription_configuration = {
"instance_xml": subscription_condition.getTextContent(),
"software_type": subscription_condition.getSourceReference(),
"url": subscription_condition.getUrlString(),
"shared": subscription_condition.getRootSlave(),
"subject_list": subscription_condition.getSubjectList(),
"sla_xml": subscription_condition.getSlaXml(),
"specialise": subscription_condition.getRelativeUrl()
}
email = context.getDestinationSectionValue().getDefaultEmailText()
now = DateTime()
context.edit(
source_reference=subscription_configuration["software_type"],
title="Subscription %s for %s" % (subscription_condition.getTitle(), email),
url_string=subscription_configuration["url"],
text_content=subscription_configuration["instance_xml"],
start_date=now,
root_slave=subscription_configuration["shared"],
subject_list=subscription_configuration["subject_list"],
)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>subscription_reference, REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SubscriptionRequest_applyCondition</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
current_invoice = context.getCausalityValue()
if current_invoice is None:
invoice_template_path = "accounting_module/template_pre_payment_subscription_sale_invoice_transaction"
invoice_template = portal.restrictedTraverse(invoice_template_path)
current_invoice = invoice_template.Base_createCloneDocument(batch_mode=1)
context.edit(causality_value=current_invoice)
payment_transaction = invoice_template = portal.restrictedTraverse(payment)
current_invoice.edit(
title="Reservation Fee",
source_value=context.getDestinationSection(),
destination_value=context.getDestinationSection(),
destination_section_value=context.getDestinationSection(),
destination_decision_value=context.getDestinationSection(),
start_date=payment_transaction.getStartDate(),
stop_date=payment_transaction.getStopDate(),
)
current_invoice["1"].setQuantity(amount)
comment = "Validation invoice for subscription request %s" % context.getRelativeUrl()
current_invoice.plan(comment=comment)
current_invoice.confirm(comment=comment)
current_invoice.startBuilding(comment=comment)
payment_transaction.setCausalityValue(current_invoice)
current_invoice.reindexObject(activate_kw={'tag': tag})
return current_invoice
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>amount, tag, payment, REQUEST=None</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SubscriptionRequest_createRelatedSaleInvoiceTransaction</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
if person is None:
# Create a Person document in order to generate the invoice.
person = portal.person_module.newContent(
portal_type="Person",
default_email_text=email,
first_name=name)
login = person.newContent(portal_type="ERP5 Login",
reference=email,
# Please generate a LAAARGE random password.
password=email)
login.validate()
person.validate()
person.immediateReindexObject()
login.immediateReindexObject()
return person
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>email, name, REQUEST=None</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SubscriptionRequest_createUser</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -7,28 +7,6 @@ portal = context.getPortalObject()
current_invoice = context.getCausalityValue()
if current_invoice is None:
# Create the Pre-Payment Invoice invoice
# XXX Hardcoded
invoice_template = portal.restrictedTraverse("accounting_module/template_pre_payment_subscription_sale_invoice_transaction")
current_invoice = invoice_template.Base_createCloneDocument(batch_mode=1)
context.edit(causality_value=current_invoice)
current_invoice.edit(
title="Reservation Fee",
source_value=context.getDestinationSection(),
destination_value=context.getDestinationSection(),
destination_section_value=context.getDestinationSection(),
destination_decision_value=context.getDestinationSection(),
start_date=DateTime(),
stop_date=DateTime(),
)
current_invoice["1"].setQuantity(amount)
comment = "Validation invoice for subscription request %s" % context.getRelativeUrl()
current_invoice.plan(comment=comment)
current_invoice.confirm(comment=comment)
current_invoice.startBuilding(comment=comment)
current_invoice.reindexObject(activate_kw={'tag': tag})
payment_template = portal.restrictedTraverse("accounting_module/slapos_pre_payment_template")
current_payment = payment_template.Base_createCloneDocument(batch_mode=1)
......@@ -39,9 +17,8 @@ if current_invoice is None:
destination_value=context.getDestinationSection(),
destination_section_value=context.getDestinationSection(),
destination_decision_value=context.getDestinationSection(),
start_date=current_invoice.getStartDate(),
stop_date=current_invoice.getStopDate(),
causality_value=current_invoice
start_date=DateTime(),
stop_date=DateTime()
)
quantity = int(amount)*19.95
for line in current_payment.contentValues():
......@@ -59,5 +36,7 @@ if current_invoice is None:
context.immediateReindexObject()
context.reindexObject(activate_kw={'tag': tag})
context.activate(tag=tag).SubscriptionRequest_createRelatedSaleInvoiceTransaction(
amount, tag, current_payment.getRelativeUrl())
return current_payment
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