Commit c680213c authored by Romain Courteaud's avatar Romain Courteaud

slapos_subscription_request:

* try to close the Subscription Request as soon as user paid an invoice
* block subscription process if there is no deposit
* do not accept new services if the virtual master subscription state is not expected
parent ff877187
......@@ -11,6 +11,10 @@
<type>Instance Tree</type>
<workflow>slapos_subscription_request_interaction_workflow</workflow>
</chain>
<chain>
<type>Sale Invoice Transaction Line</type>
<workflow>slapos_subscription_request_interaction_workflow</workflow>
</chain>
<chain>
<type>Subscription Condition</type>
<workflow>commerce_validation_workflow, edit_workflow</workflow>
......
......@@ -8,6 +8,55 @@ if item is None:
# Use list setter, to ensure it crashes if item is still None
# subscription_request.setAggregateValueList([item])
# If the virtual master is not in the expected subscription status,
# do not accept any new service (compute node, instance) for it
if (((subscription_request.getSourceProjectValue() is not None) and
(subscription_request.getSourceProjectValue().Item_getSubscriptionStatus() != 'subscribed')) or
((subscription_request.getDestinationProjectValue() is not None) and
(subscription_request.getDestinationProjectValue().Item_getSubscriptionStatus() != 'subscribed'))):
return
# Accept the subscription only if user paid the security payment
if (subscription_request.getSourceValue() is None) or \
(subscription_request.getSource() != subscription_request.getDestination()):
# Check that user has enough guarantee deposit to request a new service
portal = context.getPortalObject()
assert_price_kw = {
'resource_uid': subscription_request.getPriceCurrencyUid(),
'portal_type': portal.getPortalAccountingMovementTypeList(),
}
deposit_amount = portal.portal_simulation.getInventoryAssetPrice(
section_uid= subscription_request.getSourceSectionUid(),
mirror_section_uid= subscription_request.getDestinationSectionUid(),
mirror_node_uid=portal.restrictedTraverse('account_module/deposit').getUid(),
#node_category_strict_membership=['account_type/income'],
simulation_state= ('stopped', 'delivered'),
#src__=1,
**assert_price_kw
)
#return deposit_amount
payable_amount = portal.portal_simulation.getInventoryAssetPrice(
mirror_section_uid= subscription_request.getSourceSectionUid(),
section_uid= subscription_request.getDestinationSectionUid(),
node_category_strict_membership=['account_type/asset/receivable',
'account_type/liability/payable'],
grouping_reference=None,
**assert_price_kw
)
total_price = subscription_request.getTotalPrice()
# XXX what is the guarantee deposit account_type?
if deposit_amount < payable_amount + total_price:
# if not enough, user will have to pay a deposit for the subscription
# XXX probably create an event asking for a deposit
#pass
return 'NO deposit_amount %s\npayable_amount %s\ntotal_price %s' % (deposit_amount, payable_amount, total_price)
#return 'YES deposit_amount %s\npayable_amount %s\ntotal_price %s' % (deposit_amount, payable_amount, total_price)
subscription_request.SubscriptionRequest_createOpenSaleOrder()
subscription_request.validate()
subscription_request.invalidate()
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Interaction Workflow Interaction" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>after_script/portal_workflow/slapos_subscription_request_interaction_workflow/script_Base_triggerValidationAlarm</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>interaction_SaleInvoiceTransactionLine_setGroupingReference</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Interaction Workflow Interaction</string> </value>
</item>
<item>
<key> <string>portal_type_filter</string> </key>
<value>
<tuple>
<string>Sale Invoice Transaction Line</string>
</tuple>
</value>
</item>
<item>
<key> <string>portal_type_group_filter</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>temporary_document_disallowed</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>trigger_method_id</string> </key>
<value>
<tuple>
<string>_setGroupingReference</string>
<string>_baseSetGroupingReference</string>
</tuple>
</value>
</item>
<item>
<key> <string>trigger_once_per_transaction</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
Compute Node | slapos_subscription_request_interaction_workflow
Email | -coordinate_interaction_workflow
Instance Tree | slapos_subscription_request_interaction_workflow
Sale Invoice Transaction Line | slapos_subscription_request_interaction_workflow
Subscription Condition | commerce_validation_workflow
Subscription Condition | edit_workflow
Subscription Request | edit_workflow
......
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