<?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 encoding="cdata"><![CDATA[

"""\n
  Check that catalog tables contain data which is coherent with actual objects.\n
  Due to the number of objects to check, this function creates activites working\n
  on, at maximum, bundle_object_count objects.\n
\n
  bundle_object_count\n
    Maximum number of objects to deal with in one transaction. \n
    An activity is started after each successfull execution which\n
    found bundle_object_count to work on.\n
  bundle_offset\n
    Offset the bundle, to allow walking along the catalog with\n
    bundle_object_count increment.\n
  property_override_method_id\n
    Id of a method generating a property_override_dict as described below and\n
    returning it.\n
  property_override_dict (key: catalog column id, value: method id)\n
    Defines custom methods to calculate reference column value.\n
    None means that the column is not checked at all.\n
    Otherwise, the function will be called on the object with no parameter\n
    and must return the reference value for the column.\n
"""\n
MARKER = tuple()\n
bundle_object_count=int(bundle_object_count)\n
bundle_offset=int(bundle_offset)\n
null_value_list = (\'\', None, 0.0, 0) # Values which are all considered equal.\n
portal_catalog = context.getPortalObject().portal_catalog\n
\n
if property_override_method_id is None:\n
  property_override_dict = {}\n
else:\n
  property_override_dict = getattr(context, property_override_method_id)()\n
\n
if active_process is not None:\n
  from Products.CMFActivity.ActiveResult import ActiveResult\n
  result_list = []\n
\n
stock_line_list = context.Base_zGetAllFromStock(limit=(bundle_offset, bundle_object_count))\n
attribute_id_list = stock_line_list.names()\n
for stock_line in stock_line_list:\n
  object_candidate_list = portal_catalog(uid=stock_line[\'uid\'])\n
  if len(object_candidate_list) != 1:\n
    raise Exception, \'There are %s object catalogged with uid %s, 1 was expected.\' % (len(object_candidate_list), repr(stock_line[\'uid\']))\n
  actual_object = object_candidate_list[0].getObject()\n
  if actual_object.getPortalType().endswith(\' Inventory\'):\n
    continue\n
  for attribute_id in attribute_id_list:\n
    override_method_id = property_override_dict.get(attribute_id, MARKER)\n
    if override_method_id is None:\n
      continue\n
    elif override_method_id is MARKER:\n
      reference_value = actual_object.getProperty(key=attribute_id)\n
    elif same_type(override_method_id, \'\'):\n
      reference_value = getattr(actual_object, override_method_id)()\n
    else:\n
      reference_value = override_method_id(instance=actual_object)\n
    catalog_value = stock_line[attribute_id]\n
    reference_can_be_null_value = False\n
    if same_type(reference_value, tuple()) or same_type(reference_value, list()):\n
      for reference_value_item in reference_value:\n
        if reference_value_item in null_value_list:\n
          reference_can_be_null_value = True\n
          break\n
    else:\n
      if reference_value in null_value_list:\n
        reference_can_be_null_value = True\n
    if reference_can_be_null_value and catalog_value in null_value_list:\n
      continue\n
    elif same_type(reference_value, ()):\n
      if catalog_value not in reference_value:\n
        message = \'%s.%s has candidate list %s, but catalog contains %s\' % (actual_object.getRelativeUrl(), attribute_id, repr(reference_value), repr(catalog_value))\n
        if active_process is None:\n
          print \'%s<br/>\' % (message, )\n
        else:\n
          result_list.append(message)\n
    elif reference_value != catalog_value:\n
      message = \'%s.%s = %s, but catalog contains %s\' % (actual_object.getRelativeUrl(), attribute_id, repr(reference_value), repr(catalog_value))\n
      if active_process is None:\n
        print \'%s<br/>\' % (message, )\n
      else:\n
        result_list.append(message)\n
\n
if len(stock_line_list) == bundle_object_count:\n
  if active_process is None:\n
    print \'<a href="%s?bundle_object_count=%s&amp;bundle_offset:int=%s&amp;property_override_method_id=%s">Next</a>\' % (context.REQUEST[\'URL\'], bundle_object_count, bundle_offset + bundle_object_count, property_override_method_id)\n
  else:\n
    context.getPortalObject().person_module.activate(active_process=active_process).ERP5Site_checkStockTable(bundle_object_count=bundle_object_count, bundle_offset=bundle_offset + bundle_object_count, property_override_method_id=property_override_method_id, active_process=active_process)\n
\n
if active_process is None:\n
  return printed\n
else:\n
  active_result = ActiveResult()\n
  summary_list = []\n
  summary_list.append(\'Entries %s..%s\' % (bundle_offset, bundle_offset + len(stock_line_list)))\n
  severity = len(result_list)\n
  if severity == 0:\n
    summary_list.append(\'Success\')\n
  else:\n
    summary_list.append(\'Failed\')\n
  active_result.edit(summary=\', \'.join(summary_list), severity=severity, detail=\'\\n\'.join(result_list))\n
  return active_result\n


]]></string> </value>
        </item>
        <item>
            <key> <string>_code</string> </key>
            <value>
              <none/>
            </value>
        </item>
        <item>
            <key> <string>_params</string> </key>
            <value> <string>bundle_object_count=100, bundle_offset=0, property_override_method_id=None, active_process=None</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>4</int> </value>
                    </item>
                    <item>
                        <key> <string>co_varnames</string> </key>
                        <value>
                          <tuple>
                            <string>bundle_object_count</string>
                            <string>bundle_offset</string>
                            <string>property_override_method_id</string>
                            <string>active_process</string>
                            <string>_print_</string>
                            <string>_print</string>
                            <string>tuple</string>
                            <string>MARKER</string>
                            <string>int</string>
                            <string>None</string>
                            <string>null_value_list</string>
                            <string>_getattr_</string>
                            <string>context</string>
                            <string>portal_catalog</string>
                            <string>property_override_dict</string>
                            <string>getattr</string>
                            <string>Products.CMFActivity.ActiveResult</string>
                            <string>ActiveResult</string>
                            <string>result_list</string>
                            <string>stock_line_list</string>
                            <string>attribute_id_list</string>
                            <string>_getiter_</string>
                            <string>stock_line</string>
                            <string>_getitem_</string>
                            <string>object_candidate_list</string>
                            <string>len</string>
                            <string>Exception</string>
                            <string>repr</string>
                            <string>actual_object</string>
                            <string>attribute_id</string>
                            <string>override_method_id</string>
                            <string>reference_value</string>
                            <string>same_type</string>
                            <string>catalog_value</string>
                            <string>False</string>
                            <string>reference_can_be_null_value</string>
                            <string>list</string>
                            <string>reference_value_item</string>
                            <string>True</string>
                            <string>message</string>
                            <string>active_result</string>
                            <string>summary_list</string>
                            <string>severity</string>
                          </tuple>
                        </value>
                    </item>
                  </dictionary>
                </state>
              </object>
            </value>
        </item>
        <item>
            <key> <string>func_defaults</string> </key>
            <value>
              <tuple>
                <int>100</int>
                <int>0</int>
                <none/>
                <none/>
              </tuple>
            </value>
        </item>
        <item>
            <key> <string>id</string> </key>
            <value> <string>ERP5Site_checkStockTable</string> </value>
        </item>
        <item>
            <key> <string>warnings</string> </key>
            <value>
              <tuple/>
            </value>
        </item>
      </dictionary>
    </pickle>
  </record>
</ZopeData>
