Commit 254a0599 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_erp5: Add script to apply Contract Invitation into Cloud Contract

parent 12185420
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
if cloud_invitation is None:
return None
portal = context.getPortalObject()
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'],
)
if (contract is None):
# Prevent concurrent transaction to create 2 contracts for the same context
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 (token: %s)' %
(context.getTitle(), cloud_invitation.getTitle()))
contract.reindexObject(activate_kw={'tag': tag})
if (contract.getValidationState() == "invalidated"):
contract.validate(comment='Validation by usaged of the token %s' % (cloud_invitation.getTitle()))
contract.reindexObject(activate_kw={'tag': tag})
# Cloud invitation maximizes contract, so we keep the maximum value between the 2, we never
# decrease.
if cloud_invitation.getMaximumInvoiceDelay(0) > contract.getMaximumInvoiceDelay(0):
contract.edit(
maximum_invoice_delay=cloud_invitation.getMaximumInvoiceDelay())
# Hardcoded Values
for invitation_line in cloud_invitation.objectValues():
has_line = False
for line in contract.objectValues():
if line.getPriceCurrency() == invitation_line.getPriceCurrency() and \
invitation_line.getMaximumInvoiceCredit(0) > line.getMaximumInvoiceCredit(0):
line.edit(
maximum_invoice_credit=invitation_line.getMaximumInvoiceCredit())
has_line = True
break
if not has_line:
contract.newContent(
portal_type="Cloud Contract Line",
maximum_invoice_credit=invitation_line.getMaximumInvoiceCredit(),
price_currency=invitation_line.getPriceCurrency()
)
cloud_invitation.invalidate()
return contract
<?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>cloud_invitation, 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>Person_applyContractInvitation</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment