Commit d25a4a9f authored by Łukasz Nowak's avatar Łukasz Nowak

Move to extension.

Access to low level methods will be required.
parent 38c62494
......@@ -70,3 +70,143 @@ def VifibSaleInvoiceBuilder_buildAndPlan(self, movement_list):
for delivery in delivery_list:
if delivery.getSimulationState() == 'draft':
wf._changeStateOf(delivery, plan_tdef, dict(comment="Generated by the upgrade"))
def SlapDocument_migrateSlapState(self):
from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery
def setUpPeriodicity(hosting_subscription):
from Products.ERP5Type.DateUtils import addToDate, getClosestDate
start_date = hosting_subscription.getCreationDate()
start_date = getClosestDate(target_date=start_date, precision='day')
while start_date.day() >= 29:
start_date = addToDate(start_date, to_add={'day': -1})
periodicity_month_day_list = [start_date.day()]
periodicity_hour_list=[0]
periodicity_minute_list=[0]
hosting_subscription.edit(
periodicity_month_day_list=periodicity_month_day_list,
periodicity_hour_list=periodicity_hour_list,
periodicity_minute_list=periodicity_minute_list
)
slap_document = self
portal = self.getPortalObject()
portal_type_list = ('Hosting Subscription', 'Software Instance', 'Slave Instance')
portal_type = slap_document.getPortalType()
if portal_type not in portal_type_list:
raise TypeError('%s is not %s' % (slap_document.getPath(), portal_type_list))
explanation_delivery_line = portal.portal_catalog.getResultValue(
portal_type='Sale Packing List Line',
query=ComplexQuery(
Query(default_aggregate_uid=slap_document.getUid()),
Query(default_resource_uid=[
portal.restrictedTraverse(portal.portal_preferences.getPreferredInstanceSetupResource()).getUid(),
portal.restrictedTraverse(portal.portal_preferences.getPreferredInstanceHostingResource()).getUid(),
portal.restrictedTraverse(portal.portal_preferences.getPreferredInstanceCleanupResource()).getUid(),
]),
operator='AND',
),
sort_on=(('movement.start_date', 'DESC'),)
)
if explanation_delivery_line is None:
explanation_delivery_line = slap_document.getAggregateRelatedValue(portal_type='Sale Order Line')
if portal_type == 'Hosting Subscription':
current_periodicity = slap_document.getPeriodicityMonthDayList()
if current_periodicity is None or len(current_periodicity) == 0:
setUpPeriodicity(slap_document)
# Person is now directly associated on the HS
slap_document.edit(
destination_section_value=explanation_delivery_line.getDestinationSectionValue(portal_type="Person"),
)
assert(slap_document.getDestinationSection() == explanation_delivery_line.getDestinationSectionValue().getRelativeUrl())
else:
hosting_subscription = explanation_delivery_line.getAggregateValue(portal_type='Hosting Subscription')
slap_document.edit(
specialise_value=hosting_subscription
)
assert(slap_document.getSpecialise() == hosting_subscription.getRelativeUrl())
# Migrate slap state
if portal_type == 'Hosting Subscription':
state = slap_document.getRootState()
promise_kw = {
'instance_xml': slap_document.getTextContent(),
'software_type': slap_document.getSourceReference(),
'sla_xml': slap_document.getSlaXml(),
'software_release': slap_document.getRootSoftwareReleaseUrl(),
'shared': slap_document.isRootSlave()
}
else:
if explanation_delivery_line.getPortalType() == 'Sale Packing List Line':
resource = explanation_delivery_line.getResource()
if resource == portal.portal_preferences.getPreferredInstanceSetupResource():
state = 'stopped'
elif resource == portal.portal_preferences.getPreferredInstanceCleanupResource():
state = 'destroyed'
elif resource == portal.portal_preferences.getPreferredInstanceHostingResource():
if explanation_delivery_line.getSimulationState() in ('confirmed', 'started'):
state = 'started'
else:
state = 'stopped'
pass
else:
raise TypeError('Bad resource %s' % resource)
pass
else:
if explanation_delivery_line.getSimulationState() == 'cancelled':
state = 'destoyed'
else:
raise NotImplementedError
promise_kw = {
'instance_xml': slap_document.getTextContent(),
'software_type': slap_document.getSourceReference(),
'sla_xml': slap_document.getSlaXml(),
'software_release': slap_document.getRootSoftwareReleaseUrl(),
'shared': slap_document.getPortalType() == 'Slave Instance'
}
slap_document.setCausalityValue(explanation_delivery_line.getParentValue())
if state != 'destroyed' or explanation_delivery_line.getSimulationState() != 'delivered':
slap_document.setAggregateValue(explanation_delivery_line.getAggregateValue(portal_type='Computer Partition'))
assert(slap_document.getAggregate() == explanation_delivery_line.getAggregate(portal_type='Computer Partition'))
state_map = {
'started': 'start_requested',
'stopped': 'stop_requested',
'destroyed': 'destroy_requested'
}
if slap_document.getSlapState() == 'draft':
if state == "started":
slap_document.requestStart(comment='Migration.', **promise_kw)
elif state == "stopped":
slap_document.requestStop(comment='Migration.', **promise_kw)
elif state == "destroyed":
raise NotImplementedError
slap_document.requestDestroy(comment='Migration.', **promise_kw)
else:
raise ValueError("Unknown state %s for %s" % (state, slap_document.getRelativeUrl()))
if not(slap_document.getSlapState() == state_map[state]):
raise ValueError('%s: %s != %s' % (state, slap_document.getSlapState(), state_map[state]))
# Migrate validation state
if portal_type == 'Hosting Subscription':
if state == 'destroyed':
slap_document.validate()
slap_document.archive()
assert(slap_document.getValidationState() == 'archived')
else:
assert(slap_document.getValidationState() == 'validated')
else:
if state == 'destroyed' and \
(explanation_delivery_line.getPortalType() == 'Sale Order Line' or \
explanation_delivery_line.getSimulationState() == 'delivered'):
slap_document.invalidate()
else:
if not(slap_document.getValidationState() == 'validated'):
raise ValueError('%s != %s' % (slap_document.getValidationState(), 'validated'))
......@@ -2,205 +2,26 @@
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
<key> <string>_function</string> </key>
<value> <string>SlapDocument_migrateSlapState</string> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
<key> <string>_module</string> </key>
<value> <string>VifibUpgrader</string> </value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery\n
\n
def setUpPeriodicity(hosting_subscription):\n
from Products.ERP5Type.DateUtils import addToDate, getClosestDate\n
start_date = hosting_subscription.getCreationDate()\n
start_date = getClosestDate(target_date=start_date, precision=\'day\')\n
while start_date.day() >= 29:\n
start_date = addToDate(start_date, to_add={\'day\': -1})\n
periodicity_month_day_list = [start_date.day()]\n
periodicity_hour_list=[0]\n
periodicity_minute_list=[0]\n
hosting_subscription.edit(\n
periodicity_month_day_list=periodicity_month_day_list,\n
periodicity_hour_list=periodicity_hour_list,\n
periodicity_minute_list=periodicity_minute_list\n
)\n
\n
slap_document = context\n
portal = context.getPortalObject()\n
\n
portal_type_list = (\'Hosting Subscription\', \'Software Instance\', \'Slave Instance\')\n
portal_type = slap_document.getPortalType()\n
if portal_type not in portal_type_list:\n
raise TypeError(\'%s is not %s\' % (slap_document.getPath(), portal_type_list))\n
\n
explanation_delivery_line = portal.portal_catalog.getResultValue(\n
portal_type=\'Sale Packing List Line\',\n
query=ComplexQuery(\n
Query(default_aggregate_uid=slap_document.getUid()),\n
Query(default_resource_uid=[\n
portal.restrictedTraverse(portal.portal_preferences.getPreferredInstanceSetupResource()).getUid(),\n
portal.restrictedTraverse(portal.portal_preferences.getPreferredInstanceHostingResource()).getUid(),\n
portal.restrictedTraverse(portal.portal_preferences.getPreferredInstanceCleanupResource()).getUid(),\n
]),\n
operator=\'AND\',\n
),\n
sort_on=((\'movement.start_date\', \'DESC\'),)\n
)\n
if explanation_delivery_line is None:\n
explanation_delivery_line = slap_document.getAggregateRelatedValue(portal_type=\'Sale Order Line\')\n
\n
\n
if portal_type == \'Hosting Subscription\':\n
current_periodicity = slap_document.getPeriodicityMonthDayList()\n
if current_periodicity is None or len(current_periodicity) == 0:\n
setUpPeriodicity(slap_document)\n
# Person is now directly associated on the HS\n
slap_document.edit(\n
destination_section_value=explanation_delivery_line.getDestinationSectionValue(portal_type="Person"),\n
)\n
assert(slap_document.getDestinationSection() == explanation_delivery_line.getDestinationSectionValue().getRelativeUrl())\n
else:\n
hosting_subscription = explanation_delivery_line.getAggregateValue(portal_type=\'Hosting Subscription\')\n
slap_document.edit(\n
specialise_value=hosting_subscription\n
)\n
assert(slap_document.getSpecialise() == hosting_subscription.getRelativeUrl())\n
\n
\n
# Migrate slap state\n
if portal_type == \'Hosting Subscription\':\n
state = slap_document.getRootState()\n
promise_kw = {\n
\'instance_xml\': context.getTextContent(),\n
\'software_type\': context.getSourceReference(),\n
\'sla_xml\': context.getSlaXml(),\n
\'software_release\': context.getRootSoftwareReleaseUrl(),\n
\'shared\': slap_document.isRootSlave()\n
}\n
else:\n
if explanation_delivery_line.getPortalType() == \'Sale Packing List Line\':\n
resource = explanation_delivery_line.getResource()\n
if resource == portal.portal_preferences.getPreferredInstanceSetupResource():\n
state = \'stopped\'\n
elif resource == portal.portal_preferences.getPreferredInstanceCleanupResource():\n
state = \'destroyed\'\n
elif resource == portal.portal_preferences.getPreferredInstanceHostingResource():\n
if explanation_delivery_line.getSimulationState() in (\'confirmed\', \'started\'):\n
state = \'started\'\n
else:\n
state = \'stopped\'\n
pass\n
else:\n
raise TypeError(\'Bad resource %s\' % resource)\n
pass\n
else:\n
if explanation_delivery_line.getSimulationState() == \'cancelled\':\n
state = \'destoyed\'\n
else:\n
raise NotImplementedError\n
promise_kw = {\n
\'instance_xml\': context.getTextContent(),\n
\'software_type\': context.getSourceReference(),\n
\'sla_xml\': context.getSlaXml(),\n
\'software_release\': context.getRootSoftwareReleaseUrl(),\n
\'shared\': slap_document.getPortalType() == \'Slave Instance\'\n
}\n
\n
slap_document.setCausalityValue(explanation_delivery_line.getParentValue())\n
if state != \'destroyed\' or explanation_delivery_line.getSimulationState() != \'delivered\':\n
slap_document.setAggregateValue(explanation_delivery_line.getAggregateValue(portal_type=\'Computer Partition\'))\n
assert(slap_document.getAggregate() == explanation_delivery_line.getAggregate(portal_type=\'Computer Partition\'))\n
state_map = {\n
\'started\': \'start_requested\',\n
\'stopped\': \'stop_requested\',\n
\'destroyed\': \'destroy_requested\'\n
}\n
\n
if slap_document.getSlapState() == \'draft\':\n
if state == "started":\n
slap_document.requestStart(comment=\'Migration.\', **promise_kw)\n
elif state == "stopped":\n
slap_document.requestStop(comment=\'Migration.\', **promise_kw)\n
elif state == "destroyed":\n
raise NotImplementedError\n
slap_document.requestDestroy(comment=\'Migration.\', **promise_kw)\n
else:\n
raise ValueError("Unknown state %s for %s" % (state, slap_document.getRelativeUrl()))\n
if not(slap_document.getSlapState() == state_map[state]):\n
raise ValueError(\'%s: %s != %s\' % (state, slap_document.getSlapState(), state_map[state]))\n
\n
# Migrate validation state\n
if portal_type == \'Hosting Subscription\':\n
if state == \'destroyed\':\n
slap_document.validate()\n
slap_document.archive()\n
assert(slap_document.getValidationState() == \'archived\')\n
else:\n
assert(slap_document.getValidationState() == \'validated\')\n
else:\n
if state == \'destroyed\' and \\\n
(explanation_delivery_line.getPortalType() == \'Sale Order Line\' or \\\n
explanation_delivery_line.getSimulationState() == \'delivered\'):\n
slap_document.invalidate()\n
else:\n
if not(slap_document.getValidationState() == \'validated\'):\n
raise ValueError(\'%s != %s\' % (slap_document.getValidationState(), \'validated\'))\n
]]></string> </value>
<key> <string>id</string> </key>
<value> <string>SlapDocument_migrateSlapState</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SlapDocument_migrateSlapState</string> </value>
</item>
</dictionary>
</pickle>
</record>
......
94
\ No newline at end of file
95
\ No newline at end of file
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