<?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>from Products.ERP5Type.Log import log\n
order = state_change[\'object\']\n
portal = order.getPortalObject()\n
\n
### STEP 1: does this order have a client-specific Trade Condition\n
trade_condition = order.getSpecialiseValue(portal_type="Sale Trade Condition")\n
custom_trade_condition = None\n
if trade_condition is not None:\n
  if trade_condition.getDestinationSection() == order.getDestinationSection():\n
    # The client in this trade condition is the client of the order\n
    custom_trade_condition = trade_condition\n
\n
if custom_trade_condition is None:\n
  # If no trade condition or generic trade condition\n
  # try to find existing trade condition\n
  trade_condition_list = portal.sale_trade_condition_module.searchFolder(destination_section_uid=order.getDestinationSectionUid(),\n
                                                                         validation_state="validated")\n
  if len(trade_condition_list):\n
    custom_trade_condition = trade_condition_list[0].getObject()\n
\n
if custom_trade_condition is None:\n
  # nothing found then create a new custom trade condition\n
  if trade_condition is None:\n
    trade_condition = \'sale_trade_condition_module/vifib_trade_condition\'\n
  custom_trade_condition = portal.sale_trade_condition_module.newContent(specialise_value=trade_condition,\n
                                                                    destination_section_uid=order.getDestinationSectionUid(),\n
                                                                    title="ViFiB Custom Conditions")\n
\n
if order.getSpecialise() != custom_trade_condition.getRelativeUrl():\n
  order.setSpecialiseValue(custom_trade_condition, portal_type="Sale Trade Condition")\n
if portal.portal_workflow.isTransitionPossible(custom_trade_condition, \'validate\'):\n
  custom_trade_condition.validate()\n
</string> </value>
        </item>
        <item>
            <key> <string>_params</string> </key>
            <value> <string>state_change, **kw</string> </value>
        </item>
        <item>
            <key> <string>id</string> </key>
            <value> <string>Delivery_assertCustomTradeConditionAndOpenOrder</string> </value>
        </item>
      </dictionary>
    </pickle>
  </record>
</ZopeData>
