<?xml version="1.0"?>
<ZopeData>
  <record id="1" aka="AAAAAAAAAAE=">
    <pickle>
      <tuple>
        <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
        <tuple/>
      </tuple>
    </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>def sourceSectionSortMethod(a, b):\n
  if a.getSourceSection():\n
    return -1 # a defines a source section and wins\n
  return 1 # a defines no source section and loses\n
\n
\n
def destinationSectionSortMethod(a, b):\n
  if a.getDestinationSection():\n
    return -1 # a defines a destination section and wins\n
  return 1 # a defines no destination section and loses\n
\n
\n
def getResourceInternalPriceSortMethod(high_priority_supply_line_list):\n
  def resourceInternalPriceSortMethod(a, b):\n
    if a in high_priority_supply_line_list:\n
      return -1\n
    elif b in high_priority_supply_line_list:\n
      return 1\n
\n
    if "Internal" in a.getPortalType():\n
      if "Internal" in b.getPortalType():\n
        return destinationSectionSortMethod(a, b)\n
      else:\n
        return -1\n
    else:\n
      if "Internal" in b.getPortalType():\n
        return 1\n
      else:\n
        return sourceSectionSortMethod(a, b)\n
  return resourceInternalPriceSortMethod\n
\n
\n
def getResourcePurchasePriceSortMethod(high_priority_supply_line_list):\n
  def resourcePurchasePriceSortMethod(a, b):\n
    if a in high_priority_supply_line_list:\n
      return -1\n
    elif b in high_priority_supply_line_list:\n
      return 1\n
\n
    if "Purchase" in a.getPortalType():\n
      if "Purchase" in b.getPortalType():\n
        return sourceSectionSortMethod(a, b)\n
      else:\n
        return -1\n
    else:\n
      if "Purchase" in b.getPortalType():\n
        return 1\n
      else:\n
        return destinationSectionSortMethod(a, b)\n
  return resourcePurchasePriceSortMethod\n
\n
\n
def getResourceSalePriceSortMethod(high_priority_supply_line_list):\n
  def resourceSalePriceSortMethod(a, b):\n
    if a in high_priority_supply_line_list:\n
      return -1\n
    elif b in high_priority_supply_line_list:\n
      return 1\n
\n
    if "Sale" in a.getPortalType():\n
      if "Sale" in b.getPortalType():\n
        return destinationSectionSortMethod(a, b)\n
      else:\n
        return -1\n
    else:\n
      if "Sale" in b.getPortalType():\n
        return 1\n
      else:\n
        return sourceSectionSortMethod(a, b)\n
  return resourceSalePriceSortMethod\n
\n
\n
def getRelatedTradeConditionList(trade_condition):\n
  """Get all trade conditions related to an order.\n
  trade_condition parameter can be a trade condition or an order/invoice\n
  """\n
  related_trade_condition_list = trade_condition.getSpecialiseValueList(\n
        portal_type=(\'Sale Trade Condition\', \'Purchase Trade Condition\'))\n
  for related_trade_condition in trade_condition.getSpecialiseValueList(\n
        portal_type=(\'Sale Trade Condition\', \'Purchase Trade Condition\')):\n
    related_trade_condition_list.extend(\n
          getRelatedTradeConditionList(related_trade_condition))\n
  return related_trade_condition_list\n
\n
try:\n
  explanation = context.getExplanationValue()\n
except AttributeError:\n
  # Sometime, movements doesn\'t have an explanation.\n
  explanation = None\n
\n
if explanation is not None:\n
  explanation_type = explanation.getPortalType()\n
  high_priority_supply_line_list = []\n
  if explanation_type in context.getPortalInvoiceTypeList() +\\\n
                              context.getPortalOrderTypeList() + context.getPortalDeliveryTypeList():\n
    # if there are trade conditions containing supply lines related to that\n
    # order/invoice, we give high priority to those supply lines\n
    for trade_condition in getRelatedTradeConditionList(explanation):\n
      high_priority_supply_line_list.extend(\n
          list(trade_condition.contentValues(\n
                  portal_type=context.getPortalSupplyPathTypeList(),\n
                  checked_permission=\'View\')))\n
\n
  # XXX FIXME: Hardcoded values\n
  if "Internal" in explanation_type:\n
    kw[\'sort_method\'] = getResourceInternalPriceSortMethod(\n
                                  high_priority_supply_line_list)\n
  elif "Purchase" in explanation_type:\n
    kw[\'sort_method\'] = getResourcePurchasePriceSortMethod(\n
                                  high_priority_supply_line_list)\n
  elif "Sale" in explanation_type:\n
    kw[\'sort_method\'] = getResourceSalePriceSortMethod(\n
                                  high_priority_supply_line_list)\n
\n
resource = context.getResourceValue()\n
if resource is not None:\n
  r = resource.getPriceCalculationOperandDict(\n
                default=default, context=context, **kw)\n
  return r\n
\n
return default\n
</string> </value>
        </item>
        <item>
            <key> <string>_code</string> </key>
            <value>
              <none/>
            </value>
        </item>
        <item>
            <key> <string>_params</string> </key>
            <value> <string>default=None, **kw</string> </value>
        </item>
        <item>
            <key> <string>errors</string> </key>
            <value>
              <tuple/>
            </value>
        </item>
        <item>
            <key> <string>func_code</string> </key>
            <value>
              <object>
                <klass>
                  <global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
                </klass>
                <tuple/>
                <state>
                  <dictionary>
                    <item>
                        <key> <string>co_argcount</string> </key>
                        <value> <int>1</int> </value>
                    </item>
                    <item>
                        <key> <string>co_varnames</string> </key>
                        <value>
                          <tuple>
                            <string>default</string>
                            <string>kw</string>
                            <string>sourceSectionSortMethod</string>
                            <string>destinationSectionSortMethod</string>
                            <string>getResourceInternalPriceSortMethod</string>
                            <string>getResourcePurchasePriceSortMethod</string>
                            <string>getResourceSalePriceSortMethod</string>
                            <string>getRelatedTradeConditionList</string>
                            <string>_getattr_</string>
                            <string>context</string>
                            <string>explanation</string>
                            <string>AttributeError</string>
                            <string>None</string>
                            <string>explanation_type</string>
                            <string>high_priority_supply_line_list</string>
                            <string>_getiter_</string>
                            <string>trade_condition</string>
                            <string>list</string>
                            <string>_write_</string>
                            <string>resource</string>
                            <string>_apply_</string>
                            <string>r</string>
                          </tuple>
                        </value>
                    </item>
                  </dictionary>
                </state>
              </object>
            </value>
        </item>
        <item>
            <key> <string>func_defaults</string> </key>
            <value>
              <tuple>
                <none/>
              </tuple>
            </value>
        </item>
        <item>
            <key> <string>id</string> </key>
            <value> <string>Movement_getPriceCalculationOperandDict</string> </value>
        </item>
        <item>
            <key> <string>title</string> </key>
            <value> <string></string> </value>
        </item>
        <item>
            <key> <string>warnings</string> </key>
            <value>
              <tuple/>
            </value>
        </item>
      </dictionary>
    </pickle>
  </record>
</ZopeData>
