Commit d756f2fa authored by Romain Courteaud's avatar Romain Courteaud

slapos_subscription_request: block subscription process if there is no deposit

parent f916f09e
......@@ -8,6 +8,46 @@ if item is None:
# Use list setter, to ensure it crashes if item is still None
# subscription_request.setAggregateValueList([item])
# 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()
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