Commit 41d86ad0 authored by Romain Courteaud's avatar Romain Courteaud

slapos_subscription_request: drop unused scripts

parent d9461ebe
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ActionInformation" module="Products.CMFCore.ActionInformation"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_jio_action</string>
</tuple>
</value>
</item>
<item>
<key> <string>category</string> </key>
<value> <string>object_jio_action</string> </value>
</item>
<item>
<key> <string>condition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>icon</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>notify_active_subscriber_list</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Action Information</string> </value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>10.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Notify Active Subscribers</string> </value>
</item>
<item>
<key> <string>visible</string> </key>
<value> <int>1</int> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/SubscriptionRequestModule_viewNotifyActiveSubscriberListDialog</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ActionInformation" module="Products.CMFCore.ActionInformation"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_jio_button</string>
</tuple>
</value>
</item>
<item>
<key> <string>category</string> </key>
<value> <string>object_jio_button</string> </value>
</item>
<item>
<key> <string>condition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>icon</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>rss_view</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Action Information</string> </value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>30.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>RSS Feed</string> </value>
</item>
<item>
<key> <string>visible</string> </key>
<value> <int>1</int> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/SubscriptionRequestModule_viewFeedURLDialog</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:rss_feed_image</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>invitation_token=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Person_applyContractInvitation</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from DateTime import DateTime
portal = context.getPortalObject()
# Notify users with active instances.
ticket_list = []
person_notification_list = []
for subscription_request in portal.subscription_request_module.searchFolder(
portal_type="Subscription Request"):
instance_tree = subscription_request.getAggregateValue()
if instance_tree is None or \
instance_tree.getSlapState() == "destroy_requested":
continue
person_notification_list.append(subscription_request.getDestinationSectionValue())
for destination_decision_value in list(set(person_notification_list)):
support_request_in_progress = portal.portal_catalog.getResultValue(
portal_type = 'Support Request',
title = title,
simulation_state = ["validated", "submitted", "suspended"],
default_destination_decision_uid = destination_decision_value.getUid())
if support_request_in_progress is not None:
return support_request_in_progress
support_request_in_progress = context.REQUEST.get(
"support_request_in_progress_%s" % destination_decision_value.getUid(), None)
if support_request_in_progress is not None:
raise ValueError("There is one ticket in progress for the %s: %s" %
(destination_decision_value.getRelativeUrl(),
support_request_in_progress))
# This might be a bit hard to keep the usage of the template since
# we could like to make ticket portal type selectable.
ticket = portal.restrictedTraverse(
portal.portal_preferences.getPreferredSupportRequestTemplate())\
.Base_createCloneDocument(batch_mode=1)
ticket.edit(
title = title,
description=text_content,
start_date = start_date,
destination_decision_value=destination_decision_value,
source=source,
resource=resource)
# Keep on draft for review before send
if simulation_state == "validated":
ticket.validate()
elif simulation_state == "invalidated":
ticket.validate()
ticket.invalidate()
elif simulation_state == "suspended":
ticket.validate()
ticket.suspend()
context.REQUEST.set(
"support_request_in_progress_%s" % destination_decision_value.getUid(),
ticket.getRelativeUrl())
event = portal.event_module.newContent(
portal_type=portal_type)
ticket.edit(causality_value=event)
# Copy original post into the original message.
event.edit(
title=ticket.getTitle(),
text_content=text_content,
source=source,
destination=ticket.getDestinationDecision())
# Move state before setFollowUp
if send_event:
event.start(comment="Automatic sending notification for the subscriber")
else:
event.plan(comment="Planned to send later")
ticket_list.append(ticket)
if ticket_list:
return ticket.getParentValue().Base_redirect(
keep_items={"portal_message_status": "Ticket Created.",
"uid": [i.getUid() for i in ticket_list]})
return context.Base_redirect(
keep_items={"portal_message_status": "No Ticket Created."})
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>source, resource, title, text_content, simulation_state, send_event=False, portal_type="", start_date=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SubscriptionRequestModule_notifyActiveSubscriberList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from zExceptions import Unauthorized
from DateTime import DateTime
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
web_site = context.getWebSiteValue()
if email in ["", None]:
error = "Email must be provided"
base_url = context.getWebSectionValue().absolute_url()
redirect_url = "%s?field_your_reservation_name=%s&field_your_reservation_email=%s&field_your_reservation_number_of_machines=%s&field_your_reservation_network=%s&field_your_reservation_invitation_token=%s&portal_status_message=%s" % (
base_url,
user_input_dict['name'],
email,
user_input_dict["amount"],
subscription_reference,
token,
error
)
return context.REQUEST.RESPONSE.redirect(redirect_url)
if token:
error = ""
try:
invitation_token = portal.invitation_token_module[token]
except KeyError:
error = context.Base_translateString("Token not Found")
else:
if invitation_token.getValidationState() != "validated":
error = "Token is invalid or it was already used"
if error:
base_url = context.getWebSectionValue().absolute_url()
redirect_url = "%s?field_your_reservation_name=%s&field_your_reservation_email=%s&field_your_reservation_number_of_machines=%s&field_your_reservation_network=%s&field_your_reservation_invitation_token=%s&portal_status_message=%s" % (
base_url,
user_input_dict['name'],
email,
user_input_dict["amount"],
subscription_reference,
token,
error
)
return context.REQUEST.RESPONSE.redirect(redirect_url)
# You always needs a user here
person, person_is_new = context.SubscriptionRequest_createUser(email, user_input_dict['name'])
# Check if user is already exist, otherwise redirect to ask confirmation
if confirmation_required and not person_is_new:
base_url = web_site.absolute_url()
redirect_url = "%s/order_confirmation?field_your_reservation_name=%s&field_your_reservation_email=%s&field_your_reservation_number_of_machines=%s&field_your_reservation_network=%s" % (
base_url,
person.getTitle(),
person.getDefaultEmailText(),
user_input_dict["amount"],
subscription_reference)
if token:
redirect_url += "&field_your_reservation_invitation_token=%s" % token
if variation_reference:
redirect_url += "&field_your_variation_reference=%s" % variation_reference
return context.REQUEST.RESPONSE.redirect(redirect_url)
if target_language is None:
target_language = portal.Localizer.get_selected_language()
contract = None
if token:
contract = person.Person_applyContractInvitation(invitation_token)
subscription_condition = context.portal_catalog.getResultValue(
portal_type="Subscription Condition",
reference=subscription_reference if (target_language != "zh") else (subscription_reference + '_zh'),
validation_state="validated"
)
subscription_request = context.subscription_request_module.newContent(
portal_type="Subscription Request",
destination_section_value=person,
quantity=user_input_dict["amount"],
language=target_language,
specialise_value=subscription_condition,
source_project_value=subscription_condition.getFollowUpValue()
)
subscription_request.setDefaultEmailText(email)
def wrapWithShadow(subscription_request,
subscription_request_id, variation_reference, contract=contract):
subscription_request.activate(tag="subscription_condition_%s" % subscription_request_id
).SubscriptionRequest_applyCondition()
return subscription_request.SubscriptionRequest_requestPaymentTransaction(
tag="subscription_%s" % subscription_request_id,
contract=contract,
variation_reference=variation_reference
)
payment = person.Person_restrictMethodAsShadowUser(
shadow_document=person,
callable_object=wrapWithShadow,
argument_list=[subscription_request,
subscription_request.getId(),
variation_reference, contract])
# Ensure tests crashes in batch mode
assert payment.getPaymentMode() in ['payzen', 'wechat']
if batch_mode:
return {'subscription' : subscription_request.getRelativeUrl(),
'payment': payment.getRelativeUrl() }
def wrapRedirectWithShadow(payment_transaction, web_site):
# getTotalPayble returns a negative value
if payment_transaction.PaymentTransaction_getTotalPayablePrice() < 0:
if payment.getPaymentMode() == 'wechat':
return payment_transaction.PaymentTransaction_redirectToManualWechatPayment(web_site)
elif payment.getPaymentMode() == 'payzen':
return payment_transaction.PaymentTransaction_redirectToManualPayzenPayment(web_site)
else:
raise NotImplementedError('Not supported payment mode (%s) for %s' % (payment.getPaymentMode(), payment.getRelativeUrl()))
return payment_transaction.PaymentTransaction_redirectToManualFreePayment(web_site)
return person.Person_restrictMethodAsShadowUser(
shadow_document=person,
callable_object=wrapRedirectWithShadow,
argument_list=[payment, web_site])
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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, subscription_reference, confirmation_required=False, token=None, user_input_dict=None, variation_reference=None, target_language=None, batch_mode=True, 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>SubscriptionRequestModule_requestSubscriptionProxy</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ERP5 Form" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>action</string> </key>
<value> <string>SubscriptionRequestModule_notifyActiveSubscriberList</string> </value>
</item>
<item>
<key> <string>action_title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>Use this dialog to create a new event and associate it to a Ticket.</string> </value>
</item>
<item>
<key> <string>edit_order</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>enctype</string> </key>
<value> <string>multipart/form-data</string> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
<list>
<string>left</string>
<string>right</string>
<string>center</string>
<string>bottom</string>
<string>hidden</string>
</list>
</value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
<dictionary>
<item>
<key> <string>bottom</string> </key>
<value>
<list>
<string>your_text_content</string>
</list>
</value>
</item>
<item>
<key> <string>center</string> </key>
<value>
<list>
<string>your_content_type</string>
</list>
</value>
</item>
<item>
<key> <string>hidden</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>left</string> </key>
<value>
<list>
<string>your_title</string>
<string>your_portal_type</string>
<string>your_resource</string>
<string>your_start_date</string>
</list>
</value>
</item>
<item>
<key> <string>right</string> </key>
<value>
<list>
<string>your_source</string>
<string>your_simulation_state</string>
</list>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SubscriptionRequestModule_viewNotifyActiveSubscriberListDialog</string> </value>
</item>
<item>
<key> <string>method</string> </key>
<value> <string>POST</string> </value>
</item>
<item>
<key> <string>name</string> </key>
<value> <string>SubscriptionRequestModule_viewNotifyActiveSubscriberListDialog</string> </value>
</item>
<item>
<key> <string>pt</string> </key>
<value> <string>form_dialog</string> </value>
</item>
<item>
<key> <string>row_length</string> </key>
<value> <int>4</int> </value>
</item>
<item>
<key> <string>stored_encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Create one Ticket Per Person</string> </value>
</item>
<item>
<key> <string>unicode_mode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>update_action</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>update_action_title</string> </key>
<value> <string></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>items</string>
<string>orientation</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_content_type</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>
<item>
<key> <string>target</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>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</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>display_width</string> </key>
<value> <int>20</int> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_radio_field</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>items</string> </key>
<value>
<list>
<tuple>
<string>HTML</string>
<string>text/html</string>
</tuple>
<tuple>
<string>Plain Text</string>
<string>text/plain</string>
</tuple>
<tuple>
<string>reStructuredText</string>
<string>text/x-rst</string>
</tuple>
</list>
</value>
</item>
<item>
<key> <string>orientation</string> </key>
<value> <string>horizontal</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Text Format</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.Ticket_getPreferredFollowUpEventContentType()</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>items</string>
<string>required</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_portal_type</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>
<item>
<key> <string>target</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>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>items</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>required</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</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>field_id</string> </key>
<value> <string>my_list_field</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>items</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>required</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Event Type</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.Ticket_getPreferredFollowUpEventPortalType()</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: [(here.Localizer.erp5_ui.gettext(x), x) for x in here.getPortalEventTypeList()]</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>items</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_resource</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>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</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>
<item>
<key> <string>items</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>target</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>field_id</string> </key>
<value> <string>my_list_field</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>items</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Event Nature</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: here.Ticket_getResourceItemList(portal_type=\'Event\', include_context=False)</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>first_item</string>
<string>items</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_simulation_state</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>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</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>
<item>
<key> <string>items</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</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>field_id</string> </key>
<value> <string>my_list_field</string> </value>
</item>
<item>
<key> <string>first_item</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>items</string> </key>
<value>
<list>
<tuple>
<string>Draft</string>
<string>draft</string>
</tuple>
<tuple>
<string>Open</string>
<string>validated</string>
</tuple>
<tuple>
<string>Closed</string>
<string>invalidated</string>
</tuple>
<tuple>
<string>Suspended</string>
<string>suspended</string>
</tuple>
</list>
</value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Ticket State</string> </value>
</item>
</dictionary>
</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>first_item</string>
<string>items</string>
<string>required</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_source</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>
<item>
<key> <string>target</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>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>items</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>required</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</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>field_id</string> </key>
<value> <string>my_list_field</string> </value>
</item>
<item>
<key> <string>first_item</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>items</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>required</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Sender or Caller</string> </value>
</item>
<item>
<key> <string>view_separator</string> </key>
<value> <string encoding="cdata"><![CDATA[
<br />
]]></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.getPortalObject().restrictedTraverse(context.portal_preferences.getPreferredSupportRequestTemplate()).getSource()</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: [(context.getPortalObject().restrictedTraverse(context.portal_preferences.getPreferredSupportRequestTemplate()).getSourceTitle(), context.getPortalObject().restrictedTraverse(context.portal_preferences.getPreferredSupportRequestTemplate()).getSource())]</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_now</string>
<string>editable</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_start_date</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>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>editable</string> </key>
<value> <string></string> </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>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>default_now</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_event_start_date</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewCRMFieldLibrary</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
</dictionary>
</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>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_text_content</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>
<item>
<key> <string>target</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>target</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>1</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_text_content</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewCRMFieldLibrary</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Message</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>string:</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>not: request/mass_workflow_action | nothing</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>enabled</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_title</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>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>enabled</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</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>target</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>enabled</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_string_field</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Title</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>not: request/mass_workflow_action | nothing</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
# Send an email for the user with a URL, so he can set the password.
from Products.ERP5Type.Errors import UnsupportedWorkflowMethod
reference = None
password = None
person = context.getDestinationSectionValue(portal_type="Person")
if person.getDefaultEmailText() is None:
person.setDefaultEmailText(context.getDefaultEmailText())
if person.getLanguage() in [None, ""]:
person.setLanguage(context.getLanguage())
# Should come from subscription condition probably or preference
function_list = ['customer']
open_assignment_list = person.searchFolder(portal_type="Assignment",
validation_state="open")
current_assignment_list = {}
for assignment in open_assignment_list:
function = assignment.getFunction()
if function in current_assignment_list:
current_assignment_list[function].append(assignment)
else:
current_assignment_list[function] = [assignment]
for function in function_list:
if function in current_assignment_list:
# Update assignment (Reset stop/start dates)
for assignment in current_assignment_list[function]:
if assignment.getStartDate() is None or \
assignment.getStopDate() is None:
assignment.update()
assignment.edit(stop_date=None,
start_date=None)
assignment.open(
comment="Start and Stop reset by Subscription Request")
else:
# Create assignment
assignment = person.newContent(
portal_type='Assignment',
title = '%s Assignment' % (function.capitalize()),
function = function,
destination_project=context.getSourceProject()
)
assignment.open(comment="Created by Subscription Request")
login_list = [x for x in person.objectValues(portal_type=['ERP5 Login', 'Google Login', 'Facebook Login']) \
if x.getValidationState() == 'validated']
if not login_list:
raise ValueError('Something is wrong')
login = login_list[0]
# Let's reset password if the user is his first login.
if not open_assignment_list and person.getUserId() == login_list[0].getReference():
login.invalidate()
login.setReference(person.getDefaultEmailText())
reference = person.getDefaultEmailText()
# Update password of the user
password = person.Person_generatePassword()
login.setPassword(password)
login.validate(comment="Updated by Subscription Request")
# Update Roles and Title
try:
person.validate()
except UnsupportedWorkflowMethod:
pass
context.activate(activity='SQLQueue').SubscriptionRequest_sendAcceptedNotification(reference, password)
context.order()
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SubscriptionRequest_boostrapUserAccount</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:
# _init is guarded by the owner role
# but SubscriptionRequest_createRelatedSaleInvoiceTransaction is called with a shadow user
# leading to unauthorized error
# Instead, clone one temp invoice (as there is no _afterClone)
invoice_template = portal.restrictedTraverse(template)
current_invoice = invoice_template.Base_createCloneDocument(batch_mode=1)
assert current_invoice is not None
current_invoice.manage_delObjects([x for x in
current_invoice.contentIds() if x != "1"])
current_invoice.edit(
categories=[],
title=None
)
current_invoice["1"].manage_delObjects([x for x in
current_invoice["1"].contentIds()])
current_invoice["1"].edit(
categories=[],
title=None,
quantity=None,
price=None,
base_unit_price=None,
#index=None,
#variation_base_category_list=None,
#variation_category_list=None,
)
current_invoice["1"].updateCellRange('movement')
context.edit(causality_value=current_invoice)
payment_transaction = portal.restrictedTraverse(payment)
current_invoice.edit(
title="Reservation Fee",
ledger_value=portal.portal_categories.ledger.automated,
source_project_value=context.getSourceProjectValue(),
destination_value=context.getDestinationSection(),
destination_section_value=context.getDestinationSection(),
destination_decision_value=context.getDestinationSection(),
start_date=payment_transaction.getStartDate(),
stop_date=payment_transaction.getStopDate(),
specialise=portal.portal_preferences.getPreferredAggregatedSubscriptionSaleTradeCondition(),
source_section_value=payment_transaction.getSourceSectionValue(),
source_value=payment_transaction.getSourceValue(),
payment_mode_value=payment_transaction.getPaymentModeValue(),
price_currency_value=payment_transaction.getPriceCurrencyValue(),
resource_value=payment_transaction.getResourceValue(),
)
current_invoice["1"].edit(
start_date=payment_transaction.getStartDate(),
stop_date=payment_transaction.getStopDate(),
use="trade/sale",
resource="service_module/slapos_reservation_fee_2",
quantity_unit="unit/piece",
base_contribution_list=[
"base_amount/invoicing/discounted",
"base_amount/invoicing/taxable"
],
quantity=context.getQuantity(),
price=price
)
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>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>price, tag, payment, template, service_variation, 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>
from zExceptions import Unauthorized
import random, string
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
if person is not None:
# Person already existed
return person, False
# Already has login with this.
person = context.SubscriptionRequest_searchExistingUserByEmail(email)
if person is not None:
return person, False
# Create a Person document in order to generate the invoice.
person = portal.person_module.newContent(
portal_type="Person",
first_name=name)
password = [random.choice(string.upper(string.ascii_letters)),
random.choice(string.lower(string.ascii_letters)),
random.choice(string.digits),
random.choice("$!*#%$.;:,")]
chars = string.ascii_letters + string.digits + '!@#$%^&*()'
password.extend([random.choice(chars) for _ in range(26)])
random.shuffle(password)
login = person.newContent(
portal_type="ERP5 Login",
reference=person.getUserId(),
password=''.join(password))
login.validate()
# The rest of the information will be used later.
person.SubscriptionRequest_saveTransactionalUser(person)
# New user is created
return person, True
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal = context.getObject()
if context.REQUEST.get("refund_packing_list_%s" % context.getUid(),
None) is not None:
return
tag = "refund_packing_list_%s_inProfess" % context.getUid()
if (portal.portal_activities.countMessageWithTag(tag) > 0):
return
service = portal.restrictedTraverse(
"service_module/slapos_reservation_refund")
if len(portal.portal_catalog(
default_resource_uid=service.getUid(),
portal_type="Sale Packing List Line",
simulation_state="delivered",
parent_causality_uid=context.getUid())):
# Already generated
return
sale_invoice_transaction = context.getCausalityValue(
portal_type="Sale Invoice Transaction")
if sale_invoice_transaction is None or sale_invoice_transaction.getSimulationState() in ["draft", "cancelled", "deleted"]:
# No invoice generated, nothing to do
return
payment_transaction = sale_invoice_transaction.getCausalityRelatedValue(
portal_type="Payment Transaction")
if payment_transaction is None or payment_transaction.getSimulationState() != "stopped":
# Nothing to do bug wait the payment
return
price_without_tax = None
for invoice_line in sale_invoice_transaction.objectValues(portal_type="Invoice Line"):
# XXX
if invoice_line.getResource() == "service_module/slapos_reservation_fee_2":
price_without_tax = invoice_line.getTotalPrice()
assert price_without_tax is not None, "Something is wrong since price wasn't found"
# Time to create the PL
person = sale_invoice_transaction.getDestinationValue(portal_type="Person")
delivery_template = portal.restrictedTraverse(
portal.portal_preferences.getPreferredInstanceDeliveryTemplate())
delivery = delivery_template.Base_createCloneDocument(batch_mode=1)
delivery.edit(
title="Reservation Deduction",
specialise="sale_trade_condition_module/slapos_reservation_refund_trade_condition",
destination=person.getRelativeUrl(),
destination_decision=person.getRelativeUrl(),
start_date=payment_transaction.getCreationDate(),
causality_uid=context.getUid(),
price_currency=sale_invoice_transaction.getPriceCurrency(),
source=sale_invoice_transaction.getSource(),
source_section=sale_invoice_transaction.getSourceSection(),
ledger_value=portal.portal_categories.ledger.automated,
source_project_value=sale_invoice_transaction.getSourceProjectValue(),
)
line = delivery.newContent(
portal_type="Sale Packing List Line",
title="Reservation Deduction",
quantity=1,
destination_value=person,
destination_decision_value=person,
destination_section_value=person,
resource_value=service,
quantity_unit=service.getQuantityUnit(),
price=-price_without_tax,
causality_uid=context.getUid()
)
delivery.confirm(comment="Created from %s" % context.getRelativeUrl())
delivery.start()
delivery.stop()
delivery.deliver()
delivery.startBuilding()
delivery.reindexObject(activate_kw={'tag': tag})
line.reindexObject(activate_kw={'tag': tag})
context.REQUEST.set("refound_packing_list_%s" % context.getUid(),
delivery)
return delivery
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SubscriptionRequest_generateReservationRefoundSalePackingList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject()
if context.getSimulationState() != "confirmed":
return
instance_tree = context.getAggregateValue()
for instance in instance_tree.getSpecialiseRelatedValueList(portal_type="Software Instance"):
if (not instance.getAggregate()) or instance.SoftwareInstance_hasReportedError():
# Some instance still failing, so instance seems not ready yet.
return
# Instance is ok, we should move foward
portal = context.getPortalObject()
sender = context.getSourceSectionValue(portal_type="Person")
recipient = context.getDestinationSectionValue(portal_type="Person")
language = context.getLanguage(recipient.getLanguage())
# Get message from catalog
notification_reference = 'subscription_request-instance-is-ready'
notification_message = portal.portal_notifications.getDocumentValue(
reference=notification_reference, language=language)
if notification_message is None:
raise ValueError, 'Unable to found Notification Message with reference "%s".' % notification_reference
# Set notification mapping
notification_mapping_dict = {
'name': recipient.getTitle(),
'subscription_title': context.getTitle(),
'instance_tree_relative_url': instance_tree.getRelativeUrl()}
# Preserve HTML else convert to text
if notification_message.getContentType() == "text/html":
mail_text = notification_message.asEntireHTML(
substitution_method_parameter_dict={'mapping_dict':notification_mapping_dict})
else:
mail_text = notification_message.asText(
substitution_method_parameter_dict={'mapping_dict':notification_mapping_dict})
portal.portal_notifications.sendMessage(
sender=sender,
recipient=recipient,
subject=notification_message.getTitle(),
message=mail_text,
message_text_format=notification_message.getContentType(),
notifier_list=(portal.portal_preferences.getPreferredLoginAndPasswordNotifier(),),
store_as_event= portal.portal_preferences.isPreferredStoreEvents(),
event_keyword_argument_dict={'follow_up':context.getRelativeUrl()},
)
return True
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SubscriptionRequest_notifyInstanceIsReady</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject()
if context.getSimulationState() != "ordered":
return
# Instance is ok, we should move foward
portal = context.getPortalObject()
sender = context.getSourceSectionValue(portal_type="Person")
recipient = context.getDestinationSectionValue(portal_type="Person")
# Get message from catalog
notification_reference = 'subscription_request-payment-is-ready'
language = context.getLanguage(recipient.getLanguage())
# This implies the language to notify.
notification_message = portal.portal_notifications.getDocumentValue(
reference=notification_reference, language=language)
if notification_message is None:
raise ValueError, 'Unable to found Notification Message with reference "%s".' % notification_reference
# Set notification mapping
notification_mapping_dict = {
'name': recipient.getTitle(),
'subscription_title': context.getTitle(),
# Possible more actions goes here
'payment_relative_relative_url': invoice.getRelativeUrl()}
# Preserve HTML else convert to text
if notification_message.getContentType() == "text/html":
mail_text = notification_message.asEntireHTML(
substitution_method_parameter_dict={'mapping_dict':notification_mapping_dict})
else:
mail_text = notification_message.asText(
substitution_method_parameter_dict={'mapping_dict':notification_mapping_dict})
portal.portal_notifications.sendMessage(
sender=sender,
recipient=recipient,
subject=notification_message.getTitle(),
message=mail_text,
message_text_format=notification_message.getContentType(),
notifier_list=(portal.portal_preferences.getPreferredLoginAndPasswordNotifier(),),
store_as_event= portal.portal_preferences.isPreferredStoreEvents(),
event_keyword_argument_dict={'follow_up':context.getRelativeUrl()},
)
return True
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>invoice</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SubscriptionRequest_notifyPaymentIsReady</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()
current_payment = None
service_variation = None
if current_invoice is None:
# PaymentTransaction_init is guarded by the owner role
# but SubscriptionRequest_requestPaymentTransaction is called with a shadow user
# leading to unauthorized error
# Instead, clone one temp payment (as there is no PaymentTransaction_afterClone)
payment_template = portal.restrictedTraverse(portal.portal_preferences.getPreferredDefaultPrePaymentTemplate())
current_payment = payment_template.Base_createCloneDocument(batch_mode=1)
assert current_payment is not None
current_payment.manage_delObjects([x for x in
current_payment.contentIds()])
current_payment.edit(
categories=[],
title=None
)
subscription_condition = context.getSpecialiseValue(portal_type='Subscription Condition')
trade_condition = subscription_condition.getSpecialiseValue(portal_type='Sale Trade Condition')
assert trade_condition is not None
# XXX if we have a tree of trade condition, getPaymentMode may be empty (if there is no acquisition)
payment_mode = trade_condition.getPaymentModeValue()
now = DateTime()
current_payment.edit(
title="Payment for Reservation Fee",
ledger_value=portal.portal_categories.ledger.automated,
source_project_value=context.getSourceProjectValue(),
specialise_value=trade_condition,
destination_value=context.getDestinationSection(),
destination_section_value=context.getDestinationSection(),
destination_decision_value=context.getDestinationSection(),
start_date=now,
stop_date=now,
payment_mode_uid=payment_mode.getUid(),
#source_payment_value=trade_condition.getSourcePaymentValue(),
#source_value=trade_condition.getSourceValue(),
#source_section_value=trade_condition.getSourceSectionValue(),
#price_currency_value=trade_condition.getPriceCurrencyValue(),
#resource=
)
current_payment.SaleOrder_applySaleTradeCondition(batch_mode=1, force=1)
current_payment.edit(
specialise_value=None,
)
# Search for matching resource
service = portal.portal_catalog(
# XXX Hardcoded as temporary
id='slapos_reservation_fee_2',
portal_type='Service',
validation_state='validated',
use__relative_url='use/trade/sale'
)[0].getObject()
if context.SubscriptionRequest_testSkippedReservationFree(contract):
# Reservation is Free
price = 0
tax = 0
else:
tmp_invoice = portal.accounting_module.newContent(
temp_object=True,
portal_type='Sale Invoice Transaction',
price_currency_value=trade_condition.getPriceCurrencyValue(),
specialise=portal.portal_preferences.getPreferredAggregatedSubscriptionSaleTradeCondition(),
)
tmp_invoice_line = tmp_invoice.newContent(
temp_object=True,
portal_type='Invoice Line',
resource_value=service,
quantity=context.getQuantity(),
quantity_unit=service.getQuantityUnit(),
base_contribution_list=service.getBaseContributionList(),
use=service.getUse(),
# Dates are required to correctly select the correct trade condition version (based on effective date)
start_date=now,
stop_date=now,
)
predicate_list = []
inherited_trade_condition = trade_condition
while inherited_trade_condition is not None:
predicate_list.extend([
x for x in inherited_trade_condition.contentValues(portal_type='Sale Supply Line')
if x.getResource() == service.getRelativeUrl()
])
inherited_trade_condition = inherited_trade_condition.getSpecialiseValue(portal_type=inherited_trade_condition.getPortalType())
price = service.getPrice(
context=tmp_invoice_line,
predicate_list=predicate_list,
default=None
)
if price is None:
raise NotImplementedError('Price must be defined')
# XXX calculate Tax
# We need to provide Price to pay right the way, so we need to include
# taxation at this point it is most liketly to quickly forecast price
# with taxes, but for now it is hardcoded.
tax = None
if 'base_amount/invoicing/taxable' in tmp_invoice_line.getBaseContributionList():
for trade_model_line in tmp_invoice_line.getAggregatedAmountList():
tax = trade_model_line.getPrice()
# For simplification consider tax is a single value.
break
if tax is None:
raise NotImplementedError('No tax trade model line found')
amount = context.getQuantity()
total = round((int(amount) * price)+(int(amount) * price*tax), 2)
current_payment.newContent(
portal_type="Accounting Transaction Line",
quantity=total,
destination="account_module/payable",
source="account_module/receivable",
)
current_payment.newContent(
portal_type="Accounting Transaction Line",
quantity=-total,
# XXX why source/destination are identical?
destination="account_module/payment_to_encash",
source="account_module/payment_to_encash",
)
# Accelarate job of alarms before proceed to payment.
comment = "Validation payment for subscription request %s" % context.getRelativeUrl()
current_payment.confirm(comment=comment)
current_payment.start(comment=comment)
if not price:
current_payment.stop(comment="%s (Free)" % comment)
elif current_payment.getPaymentMode() == "payzen":
# Payzen require update like this.
current_payment.PaymentTransaction_updateStatus()
current_payment.reindexObject(activate_kw={'tag': tag})
context.reindexObject(activate_kw={'tag': tag})
context.activate(tag=tag).SubscriptionRequest_createRelatedSaleInvoiceTransaction(
price, tag, current_payment.getRelativeUrl(), portal.portal_preferences.getPreferredDefaultPrePaymentSubscriptionInvoiceTemplate(),
service_variation)
return current_payment
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>tag, contract=None, variation_reference=None, 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_requestPaymentTransaction</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject()
sender = context.getSourceSectionValue(portal_type="Person")
recipient = context.getDestinationSectionValue(portal_type="Person")
#Define the type of notification
notification_type = "without-password"
if password:
notification_type = "with-password"
language = context.getLanguage(recipient.getLanguage())
#Get message from catalog
notification_reference = 'subscription_request-confirmation-%s' % notification_type
notification_message = portal.portal_notifications.getDocumentValue(reference=notification_reference,
language=language)
if notification_message is None:
raise ValueError, 'Unable to found Notification Message with reference "%s".' % notification_reference
if reference is None:
login_list = recipient.searchFolder(portal_type="ERP5 Login")
if login_list:
reference = login_list[0].getReference()
#Set notification mapping
notification_mapping_dict = {
'login_name': reference,
'name': recipient.getTitle()}
if password:
notification_mapping_dict.update(
{'login_password' : password})
#Preserve HTML else convert to text
if notification_message.getContentType() == "text/html":
mail_text = notification_message.asEntireHTML(
substitution_method_parameter_dict={'mapping_dict':notification_mapping_dict})
else:
mail_text = notification_message.asText(
substitution_method_parameter_dict={'mapping_dict':notification_mapping_dict})
# Send email
portal.portal_notifications.sendMessage(
sender=sender,
recipient=recipient,
subject=notification_message.getTitle(),
message=mail_text,
message_text_format=notification_message.getContentType(),
notifier_list=(portal.portal_preferences.getPreferredLoginAndPasswordNotifier(),),
store_as_event= portal.portal_preferences.isPreferredStoreEvents(),
event_keyword_argument_dict={'follow_up':context.getRelativeUrl()},
)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>reference, password</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SubscriptionRequest_sendAcceptedNotification</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
# It is mandatory use pass a contract to skip reservation
# as annonymous can request via website knowning the user's
# email
if contract is None:
return
if context.SubscriptionRequest_getTransactionalUser() is not None:
if contract.getMaximumInvoiceDelay() > 0:
return True
else:
person = context.getDestinationSectionValue()
if person.Entity_statSlapOSOutstandingAmount() > 0:
return
if contract.getMaximumInvoiceDelay() > 0:
return True
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>contract=None, 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_testSkippedReservationFree</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
# -*- coding:utf-8 -*-
##############################################################################
#
# Copyright (c) 2019 Nexedi SA and Contributors. All Rights Reserved.
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################
import six
import six.moves.urllib.parse
from erp5.component.test.SlapOSTestCaseMixin import \
SlapOSTestCaseMixinWithAbort, simulate
from zExceptions import Unauthorized
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from DateTime import DateTime
AGGREGATE_SALE_TRADE_CONDITION_RELATIVE_URL = 'sale_trade_condition_module/slapos_aggregated_trade_condition_v3'
MARKER = ()
class TestSubscriptionSkinsMixin(SlapOSTestCaseMixinWithAbort):
def createNotificationMessage(self, reference,
content_type='text/html', text_content='${name} ${login_name} ${login_password}'):
notification_message = self.portal.notification_message_module.newContent(
portal_type="Notification Message",
text_content_substitution_mapping_method_id='NotificationMessage_getSubstitutionMappingDictFromArgument',
title='TestSubscriptionSkins Notification Message %s' % reference,
text_content=text_content,
content_type=content_type,
reference=reference,
version=999,
language="en"
)
notification_message.validate()
return notification_message
def newSaleTradeCondition(self, payment_mode='payzen',
price_currency='currency_module/EUR', **kw):
sale_trade_condition = self.portal.sale_trade_condition_module.newContent(
portal_type='Sale Trade Condition',
title="Test Sale Trade Condition %s" % self.new_id,
reference="TESTSALETRADECONDITION-%s" % self.new_id,
payment_mode=payment_mode,
price_currency=price_currency,
source_value=self.slapos_organisation,
source_section_value=self.slapos_organisation,
specialise=AGGREGATE_SALE_TRADE_CONDITION_RELATIVE_URL,
**kw
)
sale_trade_condition.newContent(
portal_type="Sale Supply Line",
base_price=321,
resource='service_module/slapos_instance_subscription',
)
sale_trade_condition.newContent(
portal_type="Sale Supply Line",
base_price=123,
resource='service_module/slapos_reservation_fee_2',
)
sale_trade_condition.validate()
self.tic()
return sale_trade_condition
def newSubscriptionCondition(self, specialise_value=MARKER, **kw):
if specialise_value is MARKER:
specialise_value = self.newSaleTradeCondition()
subscription_condition = self.portal.subscription_condition_module.newContent(
portal_type='Subscription Condition',
title="Test Subscription Condition %s" % self.new_id,
reference="TESTSUBSCRIPTIONCONDITION-%s" % self.new_id,
specialise_value=specialise_value,
**kw
)
subscription_condition.validate()
self.tic()
return subscription_condition
def newSubscriptionRequest(self, specialise_value=MARKER, **kw):
if specialise_value is MARKER:
specialise_value = self.newSubscriptionCondition()
subscription_request = self.portal.subscription_request_module.newContent(
portal_type='Subscription Request',
title="Test Subscription Request %s" % self.new_id,
reference="TESTSUBSCRIPTIONREQUEST-%s" % self.new_id,
specialise_value=specialise_value,
**kw
)
self.tic()
return subscription_request
class TestSubscriptionRequest_init(TestSubscriptionSkinsMixin):
def test_SubscriptionRequest_init(self):
subscription_request = self.portal.subscription_request_module.newContent()
self.assertTrue(subscription_request.getReference().startswith("SUBREQ"))
class TestSubscriptionRequest_saveTransactionalUser(TestSubscriptionSkinsMixin):
def test_not_a_person(self):
self.tic()
self.assertEqual(self.portal.subscription_request_module,
self.portal.SubscriptionRequest_saveTransactionalUser(self.portal.subscription_request_module))
try:
self.assertEqual(None, getTransactionalVariable()["transactional_user"])
except KeyError:
pass
self.tic()
def test_a_person(self):
self.tic()
person = self.portal.person_module.newContent()
self.assertEqual(person,
self.portal.SubscriptionRequest_saveTransactionalUser(person))
self.assertEqual(person, getTransactionalVariable()["transactional_user"])
self.tic()
try:
self.assertEqual(None, getTransactionalVariable()["transactional_user"])
except KeyError:
pass
class TestSubscriptionRequest_createUser(TestSubscriptionSkinsMixin):
def test_SubscriptionRequest_createUser_raises_unauthorized(self):
self.assertRaises(Unauthorized, self.portal.SubscriptionRequest_createUser, name="a", email="b", REQUEST=self.portal.REQUEST)
def test_SubscriptionRequest_createUser_already_logged_in(self):
person = self.makePerson()
self.login(person.getUserId())
self.assertEqual((person, False), self.portal.SubscriptionRequest_createUser(name="a", email="b"))
def test_SubscriptionRequest_createUser_existing_person(self):
email = "abc%s@nexedi.com" % self.new_id
person = self.makePerson()
person.setDefaultEmailText(email)
self.tic()
self.assertEqual((person, False), self.portal.SubscriptionRequest_createUser(name="a", email=email))
def test_SubscriptionRequest_createUser_existing_login(self):
email = "abc%s@nexedi.com" % self.new_id
person = self.makePerson()
erp5_login = [i for i in person.searchFolder(portal_type="ERP5 Login")][0]
erp5_login.setReference(email)
self.tic()
self.assertEqual((person, False), self.portal.SubscriptionRequest_createUser(name="a", email=email))
def test_SubscriptionRequest_createUser_new_user(self):
email = "abc%s@nexedi.com" % self.new_id
name = "Cous Cous %s" % self.new_id
person, flag = self.portal.SubscriptionRequest_createUser(name=name, email=email)
self.assertEqual(person, getTransactionalVariable()["transactional_user"])
self.tic()
self.assertNotEqual(person, None)
self.assertEqual(flag, True)
self.assertEqual(person.getFirstName(), name)
erp5_login = [i for i in person.searchFolder(portal_type="ERP5 Login")][0]
self.assertEqual(person.getValidationState(), "draft")
self.assertEqual(erp5_login.getValidationState(), "validated")
self.assertEqual(erp5_login.getReference(), person.getUserId())
class Test0SubscriptionRequestModule_requestSubscriptionProxy(TestSubscriptionSkinsMixin):
def test0SubscriptionRequestModule_requestSubscriptionProxy_raises_unauthorized(self):
self.assertRaises(Unauthorized,
self.portal.subscription_request_module.SubscriptionRequestModule_requestSubscriptionProxy,
REQUEST="XXXXXXXXXXX", email="bb", subscription_reference="aa")
def test0SubscriptionRequestModule_requestSubscriptionProxy_redirect_to_confirmation(self):
email = "abc%s@nexedi.com" % self.new_id
subscription_reference = "test_subscription_reference"
user_input_dict = {'name': "Cous Cous %s" % self.new_id,
'amount': 1 }
person = self.makePerson()
person.setDefaultEmailText(email)
self.tic()
module = self.portal.web_site_module.hostingjs.subscription_request_module
redirect_url = module.SubscriptionRequestModule_requestSubscriptionProxy(
email=email, subscription_reference=subscription_reference,
confirmation_required=True, user_input_dict=user_input_dict)
parsed_url = six.moves.urllib.parse.urlparse(redirect_url)
self.assertEqual(parsed_url.path.split('/')[-1], 'order_confirmation')
self.assertEqual(
sorted(six.iteritems(dict(six.moves.urllib.parse.parse_qsl(parsed_url.query)))), [
('field_your_reservation_email', email),
('field_your_reservation_name', 'Member Template'),
('field_your_reservation_network', 'test_subscription_reference'),
('field_your_reservation_number_of_machines', '1'),
])
# Missing tests XXXX
class TestSubscriptionRequest_applyCondition(TestSubscriptionSkinsMixin):
def test_SubscriptionRequest_applyCondition_raises_unauthorized(self):
self.assertRaises(Unauthorized, self.portal.SubscriptionRequest_applyCondition, REQUEST=self.portal.REQUEST)
def test_SubscriptionRequest_applyCondition_raises_if_no_subscription_condition(self):
subscription_request = self.newSubscriptionRequest(specialise_value=None)
self.assertRaises(ValueError, subscription_request.SubscriptionRequest_applyCondition)
def test_SubscriptionRequest_applyCondition(self):
person = self.makePerson()
subscription_condition = self.newSubscriptionCondition(
url_string="https://%s/software.cfg" % self.new_id,
sla_xml="""<?xml version="1.0" encoding="utf-8"?>
<instance>
<parameter id="oi">couscous</parameter>
<parameter id="zz">yy</parameter>
</instance>""",
text_content="""<?xml version="1.0" encoding="utf-8"?>
<instance>
<parameter id="xx">couscous</parameter>
<parameter id="zz">yy</parameter>
</instance>""",
root_slave=False,
price=99.9,
price_currency="currency_module/EUR",
source_reference="test_for_test_123")
subscription_request = self.newSubscriptionRequest(
quantity=1, destination_section_value=person,
specialise_value=subscription_condition)
self.tic()
subscription_request.SubscriptionRequest_applyCondition()
self.assertEqual("Subscription %s for %s" % (subscription_condition.getTitle(), person.getDefaultEmailText()),
subscription_request.getTitle())
self.assertEqual(None, subscription_request.getUrlString())
#self.assertRaises(AttributeError, subscription_request.getSlaXml)
#self.assertRaises(AttributeError, subscription_request.getTextContent)
self.assertNotEqual(subscription_request.getStartDate(), None)
self.assertEqual(subscription_request.getSpecialiseValue(), subscription_condition)
self.assertEqual(subscription_request.getRootSlave(), None)
self.assertEqual(subscription_request.getPrice(), None)
self.assertEqual(subscription_request.getPriceCurrency(), None)
self.assertEqual(subscription_request.getSourceReference(), "test_for_test_123")
class SubscriptionRequest_boostrapUserAccount(TestSubscriptionSkinsMixin):
@simulate('SubscriptionRequest_sendAcceptedNotification', 'reference, password',"""assert reference == context.getDefaultEmailText()
assert password""")
def test_bootstrap_user(self):
email = "abc%s@nexedi.com" % self.new_id
name = "Cous Cous %s" % self.new_id
person, _ = self.portal.SubscriptionRequest_createUser(name=name, email=email)
self.tic()
subscription_request = self.newSubscriptionRequest(
quantity=1, destination_section_value=person,
price=195.5,
price_currency="currency_module/EUR",
default_email_text="abc%s@nexedi.com" % self.new_id)
subscription_request.plan()
self.assertEqual(len(person.searchFolder(portal_type="Assignment",
validation_state="open")), 0)
subscription_request.SubscriptionRequest_boostrapUserAccount()
self.tic()
open_assignment_list = person.searchFolder(portal_type="Assignment",
validation_state="open")
self.assertEqual(len(open_assignment_list), 2)
self.assertEqual(["subscriber", "member"], [i.getRole() for i in open_assignment_list])
subscriber_role = [i for i in open_assignment_list if i.getRole() == 'subscriber'][0]
member_role = [i for i in open_assignment_list if i.getRole() == 'member'][0]
self.assertEqual(subscriber_role.getStartDate(), None)
self.assertEqual(member_role.getStopDate(), None)
self.assertEqual(subscriber_role.getStartDate(), None)
self.assertEqual(member_role.getStopDate(), None)
login_list = person.searchFolder(portal_type='ERP5 Login', validation_state="validated")
self.assertEqual(len(login_list), 1)
erp5_login = login_list[0]
self.assertEqual(erp5_login.getReference(), email)
self.assertNotEqual(erp5_login.getPassword(), None)
self.assertNotEqual(erp5_login.getPassword(), "")
self.assertEqual(erp5_login.getValidationState(), "validated")
self.assertEqual(person.getValidationState(), "validated")
self.assertEqual(subscription_request.getSimulationState(), "ordered")
self.assertEqual(person.getDefaultCareerRoleList(), ["member", "subscriber"])
self.assertEqual(person.default_career.getValidationState(), "open")
self.assertTrue(person.default_career.getStartDate() < DateTime())
class TestSubscriptionRequest_requestPaymentTransaction(TestSubscriptionSkinsMixin):
def test_invoice_already_created(self):
email = "abc%s@nexedi.com" % self.new_id
name = "Cous Cous %s" % self.new_id
person, _ = self.portal.SubscriptionRequest_createUser(name=name, email=email)
self.tic()
subscription_request = self.newSubscriptionRequest(
quantity=1, destination_section_value=person,
default_email_text="abc%s@nexedi.com" % self.new_id)
invoice_template_path = "accounting_module/template_pre_payment_subscription_sale_invoice_transaction"
invoice_template = self.portal.restrictedTraverse(invoice_template_path)
current_invoice = invoice_template.Base_createCloneDocument(batch_mode=1)
subscription_request.edit(causality_value=current_invoice,
quantity=1)
self.assertEqual(None,
subscription_request.SubscriptionRequest_requestPaymentTransaction("xx"))
def _test_request_payment_transaction(self, quantity):
email = "abc%s@nexedi.com" % self.new_id
name = "Cous Cous %s" % self.new_id
person, _ = self.portal.SubscriptionRequest_createUser(name=name, email=email)
self.tic()
subscription_request = self.newSubscriptionRequest(
quantity=quantity, destination_section_value=person,
default_email_text="abc%s@nexedi.com" % self.new_id)
subscription_request.setQuantity(quantity)
current_payment = subscription_request.SubscriptionRequest_requestPaymentTransaction("TAG")
self.tic()
self.assertNotEqual(None, current_payment)
self.assertEqual(current_payment.getTitle(), "Payment for Reservation Fee")
self.assertEqual(current_payment.getSourceValue(), self.slapos_organisation)
self.assertEqual(current_payment.getSourceSectionValue(), self.slapos_organisation)
self.assertEqual(current_payment.getDestinationValue(), person)
self.assertEqual(current_payment.getDestinationSectionValue(), person)
self.assertEqual(current_payment.getDestinationDecisionValue(), person)
self.assertEqual(current_payment.getDestinationDecisionValue(), person)
self.assertNotEqual(current_payment.getStartDate(), None)
self.assertNotEqual(current_payment.getStopDate(), None)
self.assertEqual(current_payment.getSimulationState(), "started")
for line in current_payment.contentValues():
if line.getSource() == "account_module/payment_to_encash":
self.assertEqual(line.getQuantity(), -(123 * 1.2)*quantity)
if line.getSource() == "account_module/receivable":
self.assertEqual(line.getQuantity(), (123 * 1.2)*quantity)
def _test_request_payment_transaction_chinese(self, quantity):
email = "abc%s@nexedi.com" % self.new_id
name = "Cous Cous %s" % self.new_id
person, _ = self.portal.SubscriptionRequest_createUser(name=name, email=email)
self.tic()
subscription_request = self.newSubscriptionRequest(
quantity=quantity, destination_section_value=person,
default_email_text="abc%s@nexedi.com" % self.new_id,
specialise_value=self.newSubscriptionCondition(
specialise_value=self.newSaleTradeCondition(
payment_mode='wechat',
price_currency='currency_module/CNY'
)
)
)
current_payment = subscription_request.SubscriptionRequest_requestPaymentTransaction("TAG")
self.tic()
self.assertNotEqual(None, current_payment)
self.assertEqual(current_payment.getTitle(), "Payment for Reservation Fee")
self.assertEqual(current_payment.getSource(), self.expected_zh_slapos_organisation)
self.assertEqual(current_payment.getSourceSection(), self.expected_zh_slapos_organisation)
self.assertEqual(current_payment.getDestinationValue(), person)
self.assertEqual(current_payment.getDestinationSectionValue(), person)
self.assertEqual(current_payment.getDestinationDecisionValue(), person)
self.assertNotEqual(current_payment.getStartDate(), None)
self.assertNotEqual(current_payment.getStopDate(), None)
self.assertEqual(current_payment.getSimulationState(), "started")
for line in current_payment.contentValues():
if line.getSource() == "account_module/payment_to_encash":
self.assertEqual(line.getQuantity(), -(123 * 1.01)*quantity)
if line.getSource() == "account_module/receivable":
self.assertEqual(line.getQuantity(), (123 * 1.01)*quantity)
@simulate('SubscriptionRequest_createRelatedSaleInvoiceTransaction', 'price, tag, payment, template, REQUEST=None',"""assert REQUEST == None
assert payment
assert price == 123
assert tag == 'TAG'
assert template == context.portal_preferences.getPreferredDefaultPrePaymentSubscriptionInvoiceTemplate()""")
def test_request_payment_transaction_q1(self):
self._test_request_payment_transaction(quantity=1)
@simulate('SubscriptionRequest_createRelatedSaleInvoiceTransaction', 'price, tag, payment, template, REQUEST=None',"""assert REQUEST == None
assert payment
assert price == 123
assert tag == 'TAG'
assert template == context.portal_preferences.getPreferredDefaultPrePaymentSubscriptionInvoiceTemplate()""")
def test_request_payment_transaction_q2(self):
self._test_request_payment_transaction(quantity=2)
@simulate('SubscriptionRequest_createRelatedSaleInvoiceTransaction', 'price, tag, payment, template, REQUEST=None',"""assert REQUEST == None
assert payment
assert price == 123
assert tag == 'TAG'
assert template == context.portal_preferences.getPreferredDefaultPrePaymentSubscriptionInvoiceTemplate()""")
def test_request_payment_transaction_q10(self):
self._test_request_payment_transaction(quantity=10)
@simulate('SubscriptionRequest_createRelatedSaleInvoiceTransaction', 'price, tag, payment, template, REQUEST=None',"""assert REQUEST == None
assert payment
assert price == 123
assert tag == 'TAG'
assert template == context.portal_preferences.getPreferredDefaultPrePaymentSubscriptionInvoiceTemplate()""")
def test_request_payment_transaction_chinese_q1(self):
self._test_request_payment_transaction_chinese(quantity=1)
@simulate('SubscriptionRequest_createRelatedSaleInvoiceTransaction', 'price, tag, payment, template, REQUEST=None',"""assert REQUEST == None
assert payment
assert price == 123
assert tag == 'TAG'
assert template == context.portal_preferences.getPreferredDefaultPrePaymentSubscriptionInvoiceTemplate()""")
def test_request_payment_transaction_chinese_q10(self):
self._test_request_payment_transaction_chinese(quantity=10)
class TestSubscriptionRequest_createRelatedSaleInvoiceTransaction(TestSubscriptionSkinsMixin):
def test_invoice_already_created(self):
email = "abc%s@nexedi.com" % self.new_id
name = "Cous Cous %s" % self.new_id
person, _ = self.portal.SubscriptionRequest_createUser(name=name, email=email)
self.tic()
subscription_request = self.newSubscriptionRequest(
quantity=1, destination_section_value=person,
default_email_text="abc%s@nexedi.com" % self.new_id)
invoice_template_path = "accounting_module/template_pre_payment_subscription_sale_invoice_transaction"
invoice_template = self.portal.restrictedTraverse(invoice_template_path)
current_invoice = invoice_template.Base_createCloneDocument(batch_mode=1)
subscription_request.edit(causality_value=current_invoice)
self.assertEqual(current_invoice,
subscription_request.SubscriptionRequest_createRelatedSaleInvoiceTransaction(
1, "xx", "___payment__", invoice_template_path, None))
def _test_creation_of_related_sale_invoice_transaction(self, quantity):
email = "abc%s@nexedi.com" % self.new_id
name = "Cous Cous %s" % self.new_id
person, _ = self.portal.SubscriptionRequest_createUser(name=name, email=email)
subscription_condition = self.newSubscriptionCondition()
subscription_request = self.newSubscriptionRequest(
quantity=quantity, destination_section_value=person,
default_email_text="abc%s@nexedi.com" % self.new_id,
specialise_value=subscription_condition
)
# The SubscriptionRequest_createRelatedSaleInvoiceTransaction is invoked up, as it proven on
# test TestSubscriptionRequest_requestPaymentTransaction, so let's keep it simple, and just reinvoke
current_payment = subscription_request.SubscriptionRequest_requestPaymentTransaction("TAG")
self.tic()
current_invoice = subscription_request.getCausalityValue()
subscription_invoice = subscription_request.getCausalityValue()
self.assertNotEqual(current_invoice, None)
self.assertEqual(current_invoice, subscription_invoice)
self.assertEqual(current_invoice.getTitle(), "Reservation Fee")
self.assertEqual(current_invoice.getSourceValue(), self.slapos_organisation)
self.assertEqual(current_invoice.getSourceSectionValue(), self.slapos_organisation)
self.assertEqual(current_invoice.getDestinationValue(), person)
self.assertEqual(current_invoice.getDestinationSectionValue(), person)
self.assertEqual(current_invoice.getDestinationDecisionValue(), person)
self.assertEqual(current_invoice.getStartDate(), current_payment.getStartDate())
self.assertEqual(current_invoice.getStopDate(), current_payment.getStopDate())
self.assertEqual(current_invoice.getSimulationState(), "confirmed")
self.assertEqual(current_invoice["1"].getTotalQuantity(), quantity)
def test_creation_of_related_sale_invoice_transaction_q1(self):
self._test_creation_of_related_sale_invoice_transaction(1)
def test_creation_of_related_sale_invoice_transaction_q2(self):
self._test_creation_of_related_sale_invoice_transaction(2)
def test_creation_of_related_sale_invoice_transaction_q10(self):
self._test_creation_of_related_sale_invoice_transaction(10)
class TestSubscriptionRequest_sendAcceptedNotification(TestSubscriptionSkinsMixin):
def _makeNotificationMessage(self, reference,
content_type='text/html', text_content='${name} ${login_name} ${login_password}'):
notification_message = self.portal.notification_message_module.newContent(
portal_type="Notification Message",
text_content_substitution_mapping_method_id='NotificationMessage_getSubstitutionMappingDictFromArgument',
title='TestSubscriptionSkins Notification Message %s' % reference,
text_content=text_content,
content_type=content_type,
reference=reference,
version=999,
language="en"
)
notification_message.validate()
return notification_message
def test_no_notification_message(self):
email = "abc%s@nexedi.com" % self.new_id
name = "Cous Cous %s" % self.new_id
person, _ = self.portal.SubscriptionRequest_createUser(name=name, email=email)
self.tic()
subscription_request = self.newSubscriptionRequest(
quantity=1, destination_section_value=person,
price=195.5,
price_currency="currency_module/EUR",
default_email_text="abc%s@nexedi.com" % self.new_id)
self.assertRaises(ValueError, subscription_request.SubscriptionRequest_sendAcceptedNotification,
email, None)
def test_send_notification_without_password(self):
email = "abc%s@nexedi.com" % self.new_id
name = "Cous Cous %s" % self.new_id
self._makeNotificationMessage(reference='subscription_request-confirmation-without-password',
text_content="${name} ${login_name}")
person, _ = self.portal.SubscriptionRequest_createUser(name=name, email=email)
person.setDefaultEmailText(email)
subscription_request = self.newSubscriptionRequest(
quantity=1,
source_section_value=person,
destination_section_value=person,
price=195.5,
price_currency="currency_module/EUR",
default_email_text="abc%s@nexedi.com" % self.new_id)
self.tic()
subscription_request.SubscriptionRequest_sendAcceptedNotification("zz", None)
self.tic()
event = subscription_request.getFollowUpRelatedValue(portal_type="Mail Message")
self.assertEqual(event.getTitle(),
'TestSubscriptionSkins Notification Message subscription_request-confirmation-without-password')
self.assertEqual(event.getContentType(),'text/html')
self.assertEqual(event.getContentType(),'text/html')
self.assertEqual(event.getSourceValue(), person)
self.assertEqual(event.getDestinationValue(), person)
self.assertEqual(
event.getTextContent(),'%s %s' % (person.getTitle(), "zz"))
def test_send_notification_without_login(self):
email = "abc%s@nexedi.com" % self.new_id
name = "Cous Cous %s" % self.new_id
self._makeNotificationMessage(reference='subscription_request-confirmation-without-password',
text_content="${name} ${login_name}")
person, _ = self.portal.SubscriptionRequest_createUser(name=name, email=email)
person.setDefaultEmailText(email)
subscription_request = self.newSubscriptionRequest(
quantity=1, destination_section_value=person,
price=195.5,
price_currency="currency_module/EUR",
default_email_text="abc%s@nexedi.com" % self.new_id)
self.tic()
subscription_request.SubscriptionRequest_sendAcceptedNotification(None, None)
self.tic()
event = subscription_request.getFollowUpRelatedValue(portal_type="Mail Message")
self.assertEqual(event.getTitle(),
'TestSubscriptionSkins Notification Message subscription_request-confirmation-without-password')
self.assertEqual(event.getContentType(),'text/html')
self.assertEqual(
event.getTextContent(),'%s %s' % (person.getTitle(), person.getUserId()))
def test_send_notification_with_password(self):
email = "abc%s@nexedi.com" % self.new_id
name = "Cous Cous %s" % self.new_id
self._makeNotificationMessage(reference='subscription_request-confirmation-with-password',
text_content="${name} ${login_name} ${login_password}")
person, _ = self.portal.SubscriptionRequest_createUser(name=name, email=email)
person.setDefaultEmailText(email)
subscription_request = self.newSubscriptionRequest(
quantity=1, destination_section_value=person,
price=195.5,
price_currency="currency_module/EUR",
default_email_text="abc%s@nexedi.com" % self.new_id)
self.tic()
subscription_request.SubscriptionRequest_sendAcceptedNotification(None, "password")
self.tic()
event = subscription_request.getFollowUpRelatedValue(portal_type="Mail Message")
self.assertEqual(event.getTitle(),
'TestSubscriptionSkins Notification Message subscription_request-confirmation-with-password')
self.assertEqual(event.getContentType(),'text/html')
self.assertEqual(
event.getTextContent(),'%s %s password' % (person.getTitle(), person.getUserId()))
class TestSubscriptionRequest_notifyInstanceIsReady(TestSubscriptionSkinsMixin):
def _makeNotificationMessage(self, reference,
content_type='text/html', text_content="${name} ${subscription_title} ${instance_tree_relative_url}"):
notification_message = self.portal.notification_message_module.newContent(
portal_type="Notification Message",
text_content_substitution_mapping_method_id='NotificationMessage_getSubstitutionMappingDictFromArgument',
title='TestSubscriptionSkins Notification Message %s' % reference,
text_content=text_content,
content_type=content_type,
reference=reference,
version=999,
language="en"
)
notification_message.validate()
return notification_message
@simulate('SoftwareInstance_hasReportedError', '*args, **kwargs','return')
def test_send_notification_instance_is_ready(self):
email = "abc%s@nexedi.com" % self.new_id
name = "Cous Cous %s" % self.new_id
self._makeNotificationMessage(reference='subscription_request-instance-is-ready',
text_content="${name} ${subscription_title} ${instance_tree_relative_url}")
person, _ = self.portal.SubscriptionRequest_createUser(name=name, email=email)
person.setDefaultEmailText(email)
subscription_request = self.newSubscriptionRequest(
quantity=1, destination_section_value=person,
price=195.5,
price_currency="currency_module/EUR",
default_email_text="abc%s@nexedi.com" % self.new_id)
self._makeTree()
_, p1 = self._makeComputeNode()
_, p2 = self._makeComputeNode()
self.person_user = person
self.instance_tree.setDestinationSection(self.person_user.getRelativeUrl())
subscription_request.setAggregateValue(self.instance_tree)
self.software_instance.setAggregateValue(p1)
self.requested_software_instance.setAggregateValue(p2)
self.tic()
subscription_request.plan()
subscription_request.order()
subscription_request.confirm()
self.tic()
subscription_request.SubscriptionRequest_notifyInstanceIsReady()
self.tic()
event = subscription_request.getFollowUpRelatedValue(portal_type="Mail Message")
self.assertEqual(event.getTitle(),
'TestSubscriptionSkins Notification Message subscription_request-instance-is-ready')
self.assertEqual(event.getContentType(),'text/html')
self.assertEqual(
event.getTextContent(),'%s %s %s' % (person.getTitle(), subscription_request.getTitle(),
self.instance_tree.getRelativeUrl()))
class TestSlapOSSubscriptionRequestModule_getTicketFeedUrl(TestSubscriptionSkinsMixin):
def test_getTicketFeedUrl(self):
module = self.portal.subscription_request_module
self.assertRaises(ValueError, module.SubscriptionRequestModule_getTicketFeedUrl)
person = self.makePerson(user=1)
self.tic()
self.login(person.getUserId())
url = module.SubscriptionRequestModule_getTicketFeedUrl()
self.assertIn('SubscriptionRequestModule_viewSubscriptionRequestListAsRSS', url)
self.assertIn(module.absolute_url(), url)
self.assertIn('access_token_secret', url)
self.assertIn('access_token=', url)
self.assertIn('portal_skin=RSS', url)
self.tic()
# it gives the same URL as before
self.assertEqual(url, module.SubscriptionRequestModule_getTicketFeedUrl())
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testSlapOSSubscriptionSkins</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testSlapOSSubscriptionSkins</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
Instance Tree | jump_to_related_subscription_request
Person | jump_to_subscription_request
Sale Invoice Transaction | jump_to_related_subscription_request
Subscription Request Module | notify_active_subscriber_list
Subscription Request Module | rss_view
Subscription Request Module | view
Subscription Request | view
\ No newline at end of file
test.erp5.testSlapOSSubscriptionAlarm
test.erp5.testSlapOSSubscriptionSkins
\ No newline at end of file
test.erp5.testSlapOSSubscriptionAlarm
\ No newline at end of file
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