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 ...@@ -178,8 +178,8 @@ class TestSlapOSSubscriptionChangeRequestScenario(TestSlapOSSubscriptionChangeRe
# 1 software instance # 1 software instance
# 1 software product # 1 software product
# 1 subscription change request # 1 subscription change request
# 2 subscription request # 3 subscription request
self.assertRelatedObjectCount(project, 32) self.assertRelatedObjectCount(project, 33)
with PinnedDateTime(self, DateTime('2024/02/15')): with PinnedDateTime(self, DateTime('2024/02/15')):
self.checkERP5StateBeforeExit() self.checkERP5StateBeforeExit()
...@@ -280,8 +280,9 @@ class TestSlapOSSubscriptionChangeRequestScenario(TestSlapOSSubscriptionChangeRe ...@@ -280,8 +280,9 @@ class TestSlapOSSubscriptionChangeRequestScenario(TestSlapOSSubscriptionChangeRe
# Ensure no unexpected object has been created # Ensure no unexpected object has been created
# 2 assignment # 2 assignment
# 2 sale trade condition # 2 sale trade condition
# 1 subscription change request
# 2 subscription request # 2 subscription request
self.assertRelatedObjectCount(project, 6) self.assertRelatedObjectCount(project, 7)
with PinnedDateTime(self, DateTime('2024/02/15')): with PinnedDateTime(self, DateTime('2024/02/15')):
self.checkERP5StateBeforeExit() self.checkERP5StateBeforeExit()
...@@ -404,8 +405,9 @@ class TestSlapOSSubscriptionChangeRequestScenario(TestSlapOSSubscriptionChangeRe ...@@ -404,8 +405,9 @@ class TestSlapOSSubscriptionChangeRequestScenario(TestSlapOSSubscriptionChangeRe
# 2 sale trade condition # 2 sale trade condition
# 2 sale supply* # 2 sale supply*
# 3 sale trade conditions # 3 sale trade conditions
# 1 subscription change request
# 3 subscription request # 3 subscription request
self.assertRelatedObjectCount(project, 12) self.assertRelatedObjectCount(project, 13)
with PinnedDateTime(self, DateTime('2024/02/15')): with PinnedDateTime(self, DateTime('2024/02/15')):
self.checkERP5StateBeforeExit() self.checkERP5StateBeforeExit()
\ No newline at end of file
...@@ -7,6 +7,10 @@ if REQUEST is not None: ...@@ -7,6 +7,10 @@ if REQUEST is not None:
raise Unauthorized raise Unauthorized
batch = (dialog_id is None) 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 # Search for the matching item
sql_subscription_request_list = portal.portal_catalog( sql_subscription_request_list = portal.portal_catalog(
...@@ -51,11 +55,11 @@ subscription_change_request = subscription_request.getResourceValue().Resource_c ...@@ -51,11 +55,11 @@ subscription_change_request = subscription_request.getResourceValue().Resource_c
subscription_request.getVariationCategoryList(), subscription_request.getVariationCategoryList(),
project, project,
currency_value=subscription_request.getPriceCurrencyValue(), currency_value=subscription_request.getPriceCurrencyValue(),
temp_object=True,
item_value=item, 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() current_trade_condition = subscription_change_request.getSpecialiseValue()
if (current_trade_condition.getDestination() is None): if (current_trade_condition.getDestination() is None):
...@@ -71,8 +75,10 @@ if (current_trade_condition.getDestination() is None): ...@@ -71,8 +75,10 @@ if (current_trade_condition.getDestination() is None):
source_project=current_trade_condition.getSourceProject(), source_project=current_trade_condition.getSourceProject(),
price_currency=current_trade_condition.getPriceCurrency(), price_currency=current_trade_condition.getPriceCurrency(),
trade_condition_type=current_trade_condition.getTradeConditionType(), trade_condition_type=current_trade_condition.getTradeConditionType(),
activate_kw=activate_kw
) )
new_sale_trade_condition.validate() new_sale_trade_condition.validate()
context.activate(activity='SQLQueue', after_tag=tag).Organisation_claimSlaposSubscriptionRequest(reference, None, activate_kw)
keep_items = { keep_items = {
'portal_status_message': Base_translateString('Creating a dedicated Trade Condition for the customer') 'portal_status_message': Base_translateString('Creating a dedicated Trade Condition for the customer')
} }
...@@ -81,11 +87,21 @@ if (current_trade_condition.getDestination() is None): ...@@ -81,11 +87,21 @@ if (current_trade_condition.getDestination() is None):
return new_sale_trade_condition.Base_redirect(keep_items=keep_items) return new_sale_trade_condition.Base_redirect(keep_items=keep_items)
else: 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 = { keep_items = {
'your_reference': reference, 'your_reference': reference,
'portal_status_level': 'error', 'portal_status_level': 'error',
'portal_status_message': Base_translateString('This customer already has a dedicated Trade Condition') 'portal_status_message': Base_translateString('This customer already has a dedicated Trade Condition')
} }
if batch: if batch:
raise ValueError(keep_items['portal_status_message']) return subscription_change_request
return current_trade_condition.Base_redirect(keep_items=keep_items) return subscription_change_request.Base_redirect(keep_items=keep_items)
...@@ -53,43 +53,6 @@ if 0 < total_price: ...@@ -53,43 +53,6 @@ if 0 < total_price:
if balance < total_price: if balance < total_price:
markHistory(subscription_request, markHistory(subscription_request,
'Your user does not have enough deposit.') '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 return
if subscription_request.checkConsistency(): 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