Commit e438bfa1 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_accounting: Add action to generate a cloud contract for a Person

parent af58cb49
<?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>create_new_cloud_contract</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>50.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Create Cloud Contract</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}/Person_generateCloudContract</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject()
if context.getPortalType() != "Person":
raise ValueError("This script can only be called under person context")
payment_portal_type = "Payment Transaction"
contract_portal_type = "Cloud Contract"
tag = "%s_requestValidationPayment_inProgress" % context.getUid()
if (portal.portal_activities.countMessageWithTag(tag) > 0):
# The cloud contract is already under creation but can not be fetched from catalog
# As it is not possible to fetch informations, it is better to raise an error
return None
contract = portal.portal_catalog.getResultValue(
portal_type=contract_portal_type,
default_destination_section_uid=context.getUid(),
validation_state=['invalidated', 'validated'],
)
msg = context.Base_translateString("Cloud Contract related to %s" % context.getTitle())
if (contract is None):
# Prevent concurrent transaction to create 2 contracts for the same person
context.serialize()
# Time to create the contract
contract = portal.cloud_contract_module.newContent(
portal_type=contract_portal_type,
title='Contract for "%s"' % context.getTitle(),
destination_section_value=context
)
contract.validate(comment='New automatic contract for %s' % context.getTitle())
contract.invalidate(comment='New automatic contract for %s' % context.getTitle())
contract.reindexObject(activate_kw={'tag': tag})
msg = context.Base_translateString("Cloud Contract created.")
if (contract.getValidationState() == "invalidated"):
# search if the user already paid anything
payment = portal.portal_catalog.getResultValue(
portal_type=payment_portal_type,
default_destination_section_uid=context.getUid(),
simulation_state=['stopped'],
)
if (payment is not None):
# Found one payment, the contract can be validated
comment = "Contract validated as paid payment %s found" % payment.getRelativeUrl()
contract.validate(comment=comment)
contract.reindexObject(activate_kw={'tag': tag})
if batch:
return contract
return contract.Base_redirect(
keep_items={"portal_status_message": msg})
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>batch=False</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Person_generateCloudContract</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -2,7 +2,6 @@ from zExceptions import Unauthorized ...@@ -2,7 +2,6 @@ from zExceptions import Unauthorized
if REQUEST is not None: if REQUEST is not None:
raise Unauthorized raise Unauthorized
portal = context.getPortalObject()
software_instance = context software_instance = context
hosting_subscription = software_instance.getSpecialiseValue() hosting_subscription = software_instance.getSpecialiseValue()
if hosting_subscription is None: if hosting_subscription is None:
...@@ -11,49 +10,4 @@ person = hosting_subscription.getDestinationSectionValue(portal_type='Person') ...@@ -11,49 +10,4 @@ person = hosting_subscription.getDestinationSectionValue(portal_type='Person')
if person is None: if person is None:
return return
payment_portal_type = "Payment Transaction" return person.Person_generateCloudContract(batch=True)
contract_portal_type = "Cloud Contract"
tag = "%s_requestValidationPayment_inProgress" % person.getUid()
if (portal.portal_activities.countMessageWithTag(tag) > 0):
# The cloud contract is already under creation but can not be fetched from catalog
# As it is not possible to fetch informations, it is better to raise an error
return None
contract = portal.portal_catalog.getResultValue(
portal_type=contract_portal_type,
default_destination_section_uid=person.getUid(),
validation_state=['invalidated', 'validated'],
)
if (contract is None):
# Prevent concurrent transaction to create 2 contracts for the same person
person.serialize()
# Time to create the contract
contract = portal.cloud_contract_module.newContent(
portal_type=contract_portal_type,
title='Contract for "%s"' % person.getTitle(),
destination_section_value=person
)
contract.validate(comment='New automatic contract for %s' % context.getTitle())
contract.invalidate(comment='New automatic contract for %s' % context.getTitle())
contract.reindexObject(activate_kw={'tag': tag})
if (contract.getValidationState() == "invalidated"):
# search if the user already paid anything
payment = portal.portal_catalog.getResultValue(
portal_type=payment_portal_type,
default_destination_section_uid=person.getUid(),
simulation_state=['stopped'],
)
if (payment is not None):
# Found one payment, the contract can be validated
comment = "Contract validated as paid payment %s found" % payment.getRelativeUrl()
contract.validate(comment=comment)
contract.reindexObject(activate_kw={'tag': tag})
return contract
...@@ -8,6 +8,7 @@ Consumption Document Module | view ...@@ -8,6 +8,7 @@ Consumption Document Module | view
Hosting Subscription | jump_to_related_open_order_line Hosting Subscription | jump_to_related_open_order_line
Hosting Subscription | periodicity Hosting Subscription | periodicity
Payment Transaction | related_payzen_event Payment Transaction | related_payzen_event
Person | create_new_cloud_contract
Person | jump_to_cloud_contract Person | jump_to_cloud_contract
Root Applied Rule Causality Causality Movement Group | view Root Applied Rule Causality Causality Movement Group | view
Sale Invoice Transaction | create_slapos_reversal Sale Invoice Transaction | create_slapos_reversal
......
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