Commit 10901d12 authored by Romain Courteaud's avatar Romain Courteaud

slapos_upgrader: allow to run the migration multiple time

parent 5b6886a6
...@@ -4,40 +4,45 @@ tag = script.id ...@@ -4,40 +4,45 @@ tag = script.id
### Create the bootstrap Trade Condition ### Create the bootstrap Trade Condition
currency = portal.restrictedTraverse('currency_module/EUR') currency = portal.restrictedTraverse('currency_module/EUR')
seller_organisation = portal.restrictedTraverse('organisation_module/rapidspace') seller_organisation = portal.restrictedTraverse('organisation_module/rapidspace')
business_process = portal.restrictedTraverse('business_process_module/slapos_ultimate_business_process')
# Sale Trade Condition for Tax if portal.portal_catalog.getResultValue(
sale_trade_condition = portal.sale_trade_condition_module.newContent( portal_type='Sale Trade Condition',
portal_type="Sale Trade Condition", specialise__uid=business_process.getUid()
reference="Tax/payment for: %s" % currency.getRelativeUrl(), ) is None:
trade_condition_type="default", # Sale Trade Condition for Tax
# XXX hardcoded sale_trade_condition = portal.sale_trade_condition_module.newContent(
specialise="business_process_module/slapos_ultimate_business_process", portal_type="Sale Trade Condition",
price_currency_value=currency reference="Tax/payment for: %s" % currency.getRelativeUrl(),
) trade_condition_type="default",
sale_trade_condition.newContent( # XXX hardcoded
portal_type="Trade Model Line", specialise_value=business_process,
reference="VAT", price_currency_value=currency
resource="service_module/slapos_tax", )
base_application="base_amount/invoicing/taxable", sale_trade_condition.newContent(
trade_phase="slapos/tax", portal_type="Trade Model Line",
price=0.2, reference="VAT",
quantity=1.0, resource="service_module/slapos_tax",
membership_criterion_base_category=('price_currency', 'base_contribution'), base_application="base_amount/invoicing/taxable",
membership_criterion_category=('price_currency/%s' % currency.getRelativeUrl(), 'base_contribution/base_amount/invoicing/taxable') trade_phase="slapos/tax",
) price=0.2,
sale_trade_condition.validate() quantity=1.0,
sale_trade_condition.reindexObject(activate_kw={'tag': tag}) membership_criterion_base_category=('price_currency', 'base_contribution'),
membership_criterion_category=('price_currency/%s' % currency.getRelativeUrl(), 'base_contribution/base_amount/invoicing/taxable')
)
sale_trade_condition.validate()
sale_trade_condition.reindexObject(activate_kw={'tag': tag})
# Create Trade Condition to create Project # Create Trade Condition to create Project
sale_trade_condition = portal.sale_trade_condition_module.newContent( sale_trade_condition = portal.sale_trade_condition_module.newContent(
portal_type="Sale Trade Condition", portal_type="Sale Trade Condition",
reference="Free Virtual Master (%s)" % seller_organisation.getTitle(), reference="Free Virtual Master (%s)" % seller_organisation.getTitle(),
trade_condition_type="virtual_master", trade_condition_type="virtual_master",
specialise_value=sale_trade_condition, specialise_value=sale_trade_condition,
source_value=seller_organisation, source_value=seller_organisation,
price_currency_value=currency, price_currency_value=currency,
) )
sale_trade_condition.validate() sale_trade_condition.validate()
sale_trade_condition.reindexObject(activate_kw={'tag': tag}) sale_trade_condition.reindexObject(activate_kw={'tag': tag})
return context.activate(after_tag=tag).Base_triggerFullSiteMigrationToVirtualMasterStep2() return context.activate(after_tag=tag).Base_triggerFullSiteMigrationToVirtualMasterStep2()
...@@ -17,14 +17,15 @@ for sql_result in portal.portal_catalog( ...@@ -17,14 +17,15 @@ for sql_result in portal.portal_catalog(
portal_type="Subscription Request", portal_type="Subscription Request",
): ):
subscription_request = sql_result.getObject() subscription_request = sql_result.getObject()
instance_tree = subscription_request.getAggregateValue(portal_type="Instance Tree")
if subscription_request.getSpecialise('').startswith('subscription_condition'):
if (instance_tree is not None): instance_tree = subscription_request.getAggregateValue(portal_type="Instance Tree")
context.log('COUSCOUS %s' % subscription_request.getRelativeUrl()) if (instance_tree is not None):
# Build the list of prices per project/software release context.log('COUSCOUS %s' % subscription_request.getRelativeUrl())
project_guid = instance_tree.getSuccessorValue().getSlaXmlAsDict().get('project_guid', None) # Build the list of prices per project/software release
if project_guid is not None: project_guid = instance_tree.getSuccessorValue().getSlaXmlAsDict().get('project_guid', None)
payable_project_guid_dict[project_guid] = subscription_request.getPriceCurrency() if project_guid is not None:
payable_project_guid_dict[project_guid] = subscription_request.getPriceCurrency()
# Delete existing subscription request, which must be recreated later # Delete existing subscription request, which must be recreated later
subscription_request.getParentValue().manage_delObjects(ids=[subscription_request.getId()]) subscription_request.getParentValue().manage_delObjects(ids=[subscription_request.getId()])
......
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