<?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>Python_magic</string> </key>
            <value>
              <none/>
            </value>
        </item>
        <item>
            <key> <string>Script_magic</string> </key>
            <value> <int>3</int> </value>
        </item>
        <item>
            <key> <string>__ac_local_roles__</string> </key>
            <value>
              <none/>
            </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[

"""Get the report sections for general ledger\n
"""\n
from Products.ERP5Form.Report import ReportSection\n
request  = context.REQUEST\n
portal   = context.portal_url.getPortalObject()\n
cat_tool = portal.portal_categories\n
sim_tool = portal.portal_simulation\n
N_ = context.Base_translateString\n
\n
at_date             = request[\'at_date\']\n
section_category    = request[\'section_category\']\n
section_uid = context.Base_getSectionUidListForSectionCategory(\n
                                                section_category)\n
simulation_state    = request[\'simulation_state\']\n
from_date           = request.get(\'from_date\', None)\n
gap                 = request.get(\'gap\', None)\n
omit_empty_accounts = request.get(\'omit_empty_accounts\', True)\n
display_categories  = request.get(\'display_categories\', False)\n
period_start_date = context\\\n
    .Base_getAccountingPeriodStartDateForSectionCategory(\n
          section_category=section_category, date=from_date or at_date)\n
\n
# currency precision\n
currency = portal.Base_getCurrencyForSection(request[\'section_category\'])\n
precision = portal.account_module.getQuantityPrecisionFromResource(currency)\n
request.set(\'precision\', precision)\n
\n
request.other[\'is_accounting_report\'] = True\n
\n
params = dict(at_date=at_date,\n
              precision=precision,\n
              section_uid=section_uid,\n
              simulation_state=simulation_state,\n
              period_start_date=period_start_date,\n
              movement_portal_type=portal.getPortalAccountingMovementTypeList(),\n
              no_mirror_section_uid_cache=1)\n
\n
if request.get(\'omit_grouping_reference\', False):\n
  params[\'hide_grouping\'] = True\n
\n
if from_date:\n
  params[\'from_date\'] = from_date\n
\n
result = []\n
\n
if len(simulation_state) > 1:\n
  account_columns = (\n
      (\'Movement_getSpecificReference\', \'Reference\'),\n
      (\'Movement_getExplanationTitle\', \'Title\'),\n
      (\'date\', \'Date\'),\n
      (\'Movement_getExplanationTranslatedPortalType\', \'Type\'),\n
      (\'Movement_getExplanationReference\', \'Invoice Number\'),\n
      (\'Movement_getMirrorSectionTitle\', \'Third Party\'),\n
      (\'getTranslatedSimulationStateTitle\', \'State\'),\n
      (\'debit\', \'Debit\'),\n
      (\'credit\', \'Credit\'),\n
      (\'running_total_price\', \'Net\'), )\n
else:\n
  account_columns = (\n
      (\'Movement_getSpecificReference\', \'Reference\'),\n
      (\'Movement_getExplanationTitle\', \'Title\'),\n
      (\'date\', \'Date\'),\n
      (\'Movement_getExplanationTranslatedPortalType\', \'Type\'),\n
      (\'Movement_getExplanationReference\', \'Invoice Number\'),\n
      (\'Movement_getMirrorSectionTitle\', \'Third Party\'),\n
      (\'debit\', \'Debit\'),\n
      (\'credit\', \'Credit\'),\n
      (\'running_total_price\', \'Net\'), )\n
\n
if gap:\n
  gap_value_list = cat_tool.gap.restrictedTraverse(gap)\\\n
                       .getCategoryChildValueList(is_self_excluded=0)\n
else:\n
  cat = \'gap/%s\' % (\n
    context.portal_preferences.getPreferredAccountingTransactionGap()\n
       or context.getPortalDefaultGapRoot())\n
\n
  gap_value_list = cat_tool.resolveCategory(cat).getCategoryChildValueList()\n
\n
# we don\'t want to display accounts that don\'t have any transactions\n
# associated, so we use a cache to see if the account contains transaction or\n
# not ( regardless of from_date )\n
account_inventory_list_cache = {}\n
account_inventory_list_cache_params = params.copy()\n
if account_inventory_list_cache_params.has_key(\'from_date\'):\n
  del account_inventory_list_cache_params[\'from_date\']\n
\n
for c in gap_value_list:\n
  # FIXME: this part is not working !\n
  account_list = c.getGapRelatedValueList(portal_type="Account")\n
  strict_account_list = c.getGapRelatedValueList(portal_type="Account",\n
                                                 strict_membership=1)\n
\n
  skip_branch = 1\n
  for account in account_list:\n
    if account.getUid() not in account_inventory_list_cache:\n
      account_inventory_list_cache[account.getUid()] = len(\n
                      sim_tool.getMovementHistoryList(\n
                          omit_simulation=1,\n
                          node_uid=account.getUid(),\n
                          **account_inventory_list_cache_params))\n
    if account_inventory_list_cache[account.getUid()] != 0:\n
      skip_branch = 0\n
\n
  if skip_branch:\n
    continue\n
\n
  if display_categories and \\\n
     len(account_list)  and \\\n
     len(strict_account_list) != 1:\n
    result.append(ReportSection( path    = c.getPhysicalPath()\n
                               , title   = "%s: %s" % (c.getId(), c.getTitle())\n
                               , level   = len(c.getPhysicalPath()) - 4\n
                               , form_id = None\n
                               ))\n
\n
  if len(strict_account_list):\n
    for account in strict_account_list:\n
      if account.getAccountTypeId() in (\'payable\', \'receivable\'):\n
        for third_party_brain in context.Account_zDistinctSectionList(\n
                                      at_date=at_date,\n
                                      simulation_state=simulation_state):\n
          third_party_params = params.copy()\n
          third_party_uid = third_party_brain.uid or " = NULL"\n
          third_party_params[\'mirror_section_uid\'] = third_party_uid\n
          title = "%s: %s (%s)" % ( c.getId()\n
                                  , account.getTitle()\n
                                  , third_party_brain.title\n
                                  )\n
          if len(sim_tool.getMovementHistoryList(\n
                        mirror_section_uid=third_party_uid,\n
                        node_uid=account.getUid(),\n
                        **account_inventory_list_cache_params)):\n
            result.append(ReportSection(\n
                      path=account.getPhysicalPath(),\n
                      title=title,\n
                      form_id=\'Account_viewAccountingTransactionList\',\n
                      selection_name=\'acount_preference_selection\',\n
                      selection_params=third_party_params.copy(),\n
                      selection_columns=account_columns,\n
                      listbox_display_mode=\'FlatListMode\',\n
                      selection_sort_order=[(\'stock.date\',\n
                                             \'ascending\')]))\n
\n
      elif account.isMemberOf(\'account_type/asset/cash/bank\'):\n
        # Bank Account\n
        for bank_account_brain in account.Account_zGetDistinctPaymentList(\n
                                      at_date=at_date,\n
                                      simulation_state=simulation_state):\n
          bank_params = params.copy()\n
          if bank_account_brain.path is not None:\n
            bank_account_uid = bank_account_brain.uid or " = NULL"\n
            bank_params[\'payment_uid\'] = bank_account_uid\n
            title = "%s: %s (%s)" % ( c.getId()\n
                                    , account.getTitle()\n
                                    , bank_account_brain.title\n
                                    )\n
          else :\n
            bank_params[\'no_payment_uid\'] = 1\n
            title = "%s: %s" % ( c.getId(), account.getTitle())\n
          if len(sim_tool.getMovementHistoryList(\n
                          payment_uid=bank_account_uid,\n
                          node_uid=account.getUid(),\n
                          **account_inventory_list_cache_params)):\n
            result.append(ReportSection(\n
                      path=account.getPhysicalPath(),\n
                      title=title,\n
                      form_id=\'Account_viewAccountingTransactionList\',\n
                      selection_name=\'accounting_report_selection\',\n
                      selection_params=bank_params.copy(),\n
                      selection_columns=account_columns,\n
                      listbox_display_mode=\'FlatListMode\',\n
                      selection_sort_order=[(\'stock.date\',\n
                                             \'ascending\')]))\n
      elif len(sim_tool.getMovementHistoryList(\n
                                node_uid=account.getUid(),\n
                                **account_inventory_list_cache_params)):\n
          result.append(ReportSection(\n
                        path=account.getPhysicalPath(),\n
                        title="%s: %s" % (c.getId(), account.getTitle()),\n
                        form_id=\'Account_viewAccountingTransactionList\',\n
                        selection_name=\'accounting_report_selection\',\n
                        selection_params=params,\n
                        selection_columns=account_columns,\n
                        listbox_display_mode=\'FlatListMode\',\n
                        selection_sort_order=[(\'stock.date\',\n
                                               \'ascending\')]))\n
total_params = params.copy()\n
if gap:\n
  total_params[\'node_category\'] = \'gap/%s\' % gap\n
result.append(ReportSection(\n
              path=context.getPhysicalPath(),\n
              title=N_("Total"),\n
              form_id=\'AccountModule_viewGeneralLedgerSummary\',\n
              selection_name=\'accounting_report_selection\',\n
              selection_params=total_params))\n
\n
return result\n


]]></string> </value>
        </item>
        <item>
            <key> <string>_code</string> </key>
            <value>
              <none/>
            </value>
        </item>
        <item>
            <key> <string>_filepath</string> </key>
            <value>
              <none/>
            </value>
        </item>
        <item>
            <key> <string>_params</string> </key>
            <value> <string></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>0</int> </value>
                    </item>
                    <item>
                        <key> <string>co_varnames</string> </key>
                        <value>
                          <tuple>
                            <string>Products.ERP5Form.Report</string>
                            <string>ReportSection</string>
                            <string>_getattr_</string>
                            <string>context</string>
                            <string>request</string>
                            <string>portal</string>
                            <string>cat_tool</string>
                            <string>sim_tool</string>
                            <string>N_</string>
                            <string>_getitem_</string>
                            <string>at_date</string>
                            <string>section_category</string>
                            <string>section_uid</string>
                            <string>simulation_state</string>
                            <string>None</string>
                            <string>from_date</string>
                            <string>gap</string>
                            <string>True</string>
                            <string>omit_empty_accounts</string>
                            <string>False</string>
                            <string>display_categories</string>
                            <string>period_start_date</string>
                            <string>currency</string>
                            <string>precision</string>
                            <string>_write_</string>
                            <string>dict</string>
                            <string>params</string>
                            <string>result</string>
                            <string>len</string>
                            <string>account_columns</string>
                            <string>gap_value_list</string>
                            <string>cat</string>
                            <string>account_inventory_list_cache</string>
                            <string>account_inventory_list_cache_params</string>
                            <string>_getiter_</string>
                            <string>c</string>
                            <string>account_list</string>
                            <string>strict_account_list</string>
                            <string>skip_branch</string>
                            <string>account</string>
                            <string>_apply_</string>
                            <string>third_party_brain</string>
                            <string>third_party_params</string>
                            <string>third_party_uid</string>
                            <string>title</string>
                            <string>bank_account_brain</string>
                            <string>bank_params</string>
                            <string>bank_account_uid</string>
                            <string>total_params</string>
                          </tuple>
                        </value>
                    </item>
                  </dictionary>
                </state>
              </object>
            </value>
        </item>
        <item>
            <key> <string>func_defaults</string> </key>
            <value>
              <none/>
            </value>
        </item>
        <item>
            <key> <string>id</string> </key>
            <value> <string>AccountModule_getGeneralLedgerReportSectionList</string> </value>
        </item>
        <item>
            <key> <string>warnings</string> </key>
            <value>
              <tuple/>
            </value>
        </item>
      </dictionary>
    </pickle>
  </record>
</ZopeData>
