<?xml version="1.0"?>
<ZopeData>
  <record id="1" aka="AAAAAAAAAAE=">
    <pickle>
      <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
    </pickle>
    <pickle>
      <dictionary>
        <item>
            <key> <string>Script_magic</string> </key>
            <value> <int>3</int> </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>
        </item>
        <item>
            <key> <string>_body</string> </key>
            <value> <string encoding="cdata"><![CDATA[

from DateTime import DateTime\n
\n
person = context\n
portal = person.getPortalObject()\n
tag = \'%s_updateOpenSaleOrder\' % person.getUid()\n
activate_kw = {\'tag\': tag}\n
if portal.portal_activities.countMessageWithTag(tag) > 0:\n
  # nothing to do\n
  return\n
\n
def storeWorkflowComment(document, comment):\n
  portal.portal_workflow.doActionFor(document, \'edit_action\', comment=comment)\n
\n
add_kw_kw, modify_kw_kw, remove_id_list = context.Person_getOpenSaleOrderDifference(\n
  remove_hosting_list=remove_hosting_list, add_kw_list=add_kw_list,\n
  stop_date=stop_date, start_date_tuple_list=start_date_tuple_list)\n
\n
if src__== 1:\n
  return add_kw_kw, modify_kw_kw, remove_id_list\n
\n
now = DateTime()\n
previous_open_sale_order = portal.portal_catalog.getResultValue(\n
      default_destination_uid=person.getUid(),\n
      portal_type="Open Sale Order",\n
      validation_state="validated")\n
\n
if previous_open_sale_order is None:\n
  open_sale_order_template = portal.restrictedTraverse(\n
      portal.portal_preferences.getPreferredOpenSaleOrderTemplate())\n
  open_sale_order = open_sale_order_template.Base_createCloneDocument(batch_mode=1)\n
  open_sale_order.edit(\n
        destination=person.getRelativeUrl(),\n
        destination_decision=person.getRelativeUrl(),\n
        title="SlapOS Subscription Open Sale Order",\n
        effective_date=now,\n
        activate_kw=activate_kw)\n
  open_sale_order.order(activate_kw=activate_kw)\n
  open_sale_order.validate(activate_kw=activate_kw)\n
\n
if not(add_kw_kw or modify_kw_kw or remove_id_list):\n
  return # nothing to do\n
\n
if previous_open_sale_order is not None:\n
  open_sale_order = previous_open_sale_order.Base_createCloneDocument(batch_mode=1)\n
  open_sale_order.edit(effective_date=now, activate_kw=activate_kw)\n
  open_sale_order.order(activate_kw=activate_kw)\n
  open_sale_order.validate(activate_kw=activate_kw)\n
\n
open_sale_order_line_template = portal.restrictedTraverse(\n
    portal.portal_preferences.getPreferredOpenSaleOrderLineTemplate())\n
for kw in add_kw_kw.itervalues():\n
  explanation_list = kw.pop(\'explanation\', [])\n
  line = open_sale_order_line_template.Base_createCloneDocument(batch_mode=1,\n
      destination=open_sale_order)\n
  line.edit(activate_kw=activate_kw, **kw)\n
  for explanation in explanation_list:\n
    storeWorkflowComment(line, explanation)\n
\n
for hs, kw in modify_kw_kw.iteritems():\n
  line = [q for q in open_sale_order.contentValues() if q.getAggregate(portal_type=\'Hosting Subscription\') == hs][0]\n
  explanation_list = kw.pop(\'explanation\', [])\n
  line.edit(activate_kw=activate_kw, **kw)\n
  for explanation in explanation_list:\n
    storeWorkflowComment(line, explanation)\n
\n
open_sale_order.deleteContent([q[0] for q in remove_id_list])\n
for explanation in remove_id_list:\n
  storeWorkflowComment(open_sale_order, explanation[1])\n
\n
if previous_open_sale_order is not None:\n
  previous_open_sale_order.setExpirationDate(now, activate_kw=activate_kw)\n
\n
return add_kw_kw, modify_kw_kw, remove_id_list\n


]]></string> </value>
        </item>
        <item>
            <key> <string>_params</string> </key>
            <value> <string>src__=0, remove_hosting_list=None, add_kw_list=None, stop_date=None, start_date_tuple_list=None</string> </value>
        </item>
        <item>
            <key> <string>id</string> </key>
            <value> <string>Person_updateOpenSaleOrder</string> </value>
        </item>
      </dictionary>
    </pickle>
  </record>
</ZopeData>
