Commit c1b7e30f authored by Romain Courteaud's avatar Romain Courteaud

slapos_subscription_request: use Subscription Change Request to move a Subscription to b2b

parent 129d3d5d
......@@ -178,8 +178,8 @@ class TestSlapOSSubscriptionChangeRequestScenario(TestSlapOSSubscriptionChangeRe
# 1 software instance
# 1 software product
# 1 subscription change request
# 2 subscription request
self.assertRelatedObjectCount(project, 32)
# 3 subscription request
self.assertRelatedObjectCount(project, 33)
with PinnedDateTime(self, DateTime('2024/02/15')):
self.checkERP5StateBeforeExit()
......@@ -280,8 +280,9 @@ class TestSlapOSSubscriptionChangeRequestScenario(TestSlapOSSubscriptionChangeRe
# Ensure no unexpected object has been created
# 2 assignment
# 2 sale trade condition
# 1 subscription change request
# 2 subscription request
self.assertRelatedObjectCount(project, 6)
self.assertRelatedObjectCount(project, 7)
with PinnedDateTime(self, DateTime('2024/02/15')):
self.checkERP5StateBeforeExit()
......@@ -404,8 +405,9 @@ class TestSlapOSSubscriptionChangeRequestScenario(TestSlapOSSubscriptionChangeRe
# 2 sale trade condition
# 2 sale supply*
# 3 sale trade conditions
# 1 subscription change request
# 3 subscription request
self.assertRelatedObjectCount(project, 12)
self.assertRelatedObjectCount(project, 13)
with PinnedDateTime(self, DateTime('2024/02/15')):
self.checkERP5StateBeforeExit()
\ No newline at end of file
......@@ -7,6 +7,10 @@ if REQUEST is not None:
raise Unauthorized
batch = (dialog_id is None)
if activate_kw is None:
activate_kw = {}
tag = activate_kw.get('tag', script.id)
activate_kw['tag'] = tag
# Search for the matching item
sql_subscription_request_list = portal.portal_catalog(
......@@ -51,11 +55,11 @@ subscription_change_request = subscription_request.getResourceValue().Resource_c
subscription_request.getVariationCategoryList(),
project,
currency_value=subscription_request.getPriceCurrencyValue(),
temp_object=True,
item_value=item,
causality_value=subscription_request.getCausalityValue()
causality_value=subscription_request.getCausalityValue(),
temp_object=True,
portal_type='Subscription Change Request'
)
current_trade_condition = subscription_change_request.getSpecialiseValue()
if (current_trade_condition.getDestination() is None):
......@@ -71,8 +75,10 @@ if (current_trade_condition.getDestination() is None):
source_project=current_trade_condition.getSourceProject(),
price_currency=current_trade_condition.getPriceCurrency(),
trade_condition_type=current_trade_condition.getTradeConditionType(),
activate_kw=activate_kw
)
new_sale_trade_condition.validate()
context.activate(activity='SQLQueue', after_tag=tag).Organisation_claimSlaposSubscriptionRequest(reference, None, activate_kw)
keep_items = {
'portal_status_message': Base_translateString('Creating a dedicated Trade Condition for the customer')
}
......@@ -81,11 +87,21 @@ if (current_trade_condition.getDestination() is None):
return new_sale_trade_condition.Base_redirect(keep_items=keep_items)
else:
subscription_change_request = subscription_request.getResourceValue().Resource_createSubscriptionRequest(
subscription_request.getDestinationValue(),
# [software_type, software_release],
subscription_request.getVariationCategoryList(),
project,
currency_value=subscription_request.getPriceCurrencyValue(),
item_value=item,
causality_value=subscription_request,
portal_type='Subscription Change Request'
)
keep_items = {
'your_reference': reference,
'portal_status_level': 'error',
'portal_status_message': Base_translateString('This customer already has a dedicated Trade Condition')
}
if batch:
raise ValueError(keep_items['portal_status_message'])
return current_trade_condition.Base_redirect(keep_items=keep_items)
return subscription_change_request
return subscription_change_request.Base_redirect(keep_items=keep_items)
......@@ -53,43 +53,6 @@ if 0 < total_price:
if balance < total_price:
markHistory(subscription_request,
'Your user does not have enough deposit.')
# Check if a new trade condition has been created to
# replace the existing one
# (customer's service paid by an organisation)
if item.getPortalType() == 'Project':
project = item
else:
project = subscription_request.getSourceProjectValue()
try:
subscription_change_request = subscription_request.getResourceValue().Resource_createSubscriptionRequest(
subscription_request.getDestinationValue(),
# [software_type, software_release],
subscription_request.getVariationCategoryList(),
project,
currency_value=subscription_request.getPriceCurrencyValue(),
temp_object=True,
item_value=item,
causality_value=subscription_request.getCausalityValue()
)
except AssertionError:
pass
else:
if subscription_change_request.getSpecialise() != subscription_request.getSpecialise():
# We have a matching Trade Condition.
# We can recreate the Subscription Request
subscription_change_request = subscription_request.getResourceValue().Resource_createSubscriptionRequest(
subscription_request.getDestinationValue(),
# [software_type, software_release],
subscription_request.getVariationCategoryList(),
project,
currency_value=subscription_request.getPriceCurrencyValue(),
item_value=item,
causality_value=subscription_request.getCausalityValue()
)
subscription_request.cancel(comment='Replaced by %s' % subscription_change_request.getReference())
return
if subscription_request.checkConsistency():
......
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