<?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.PythonScripts.standard import Object\n
from Products.ERP5Type.Document import newTempBase\n
from Products.ERP5Type.Message import Message\n
portal = context.getPortalObject()\n
getObject = portal.portal_catalog.getObject\n
params = portal.ERP5Accounting_getParams(selection_name)\n
N_ = lambda msg: Message(\'erp5_ui\', msg)\n
\n
# this also prevents to be called directly\n
assert \'node_uid\' in kw\n
\n
mirror_section_relative_url = None\n
if kw.get(\'mirror_section_uid\'):\n
  mirror_section_relative_url =\\\n
        getObject(kw[\'mirror_section_uid\']).getRelativeUrl()\n
\n
payment_uid = kw.get(\'payment_uid\', None)\n
\n
portal_type_filter = 0\n
if \'parent_portal_type\' in params:\n
  portal_type_filter = 1\n
  portal_type_list = params[\'parent_portal_type\']\n
\n
total_debit = 0\n
total_credit = 0\n
total_debit_price = 0\n
total_credit_price = 0\n
\n
line_list = []\n
for brain in portal.Base_zGetNotGroupedMovementList(\n
                                at_date=(from_date - 1).latestTime(), # this is not to_date\n
                                simulation_state=params[\'simulation_state\'],\n
                                node_uid=[kw[\'node_uid\']],\n
                                portal_type=portal.getPortalAccountingMovementTypeList(),\n
                                section_uid=params[\'section_uid\']):\n
    \n
    # manually filter out not interesting lines\n
    # XXX this is because Base_zGetNotGroupedMovementList is really\n
    # minimalistic\n
    if mirror_section_relative_url and \\\n
        brain.mirror_section_relative_url != mirror_section_relative_url:\n
      continue\n
\n
    mvt = brain.getObject()\n
    transaction = mvt.getParentValue()\n
    \n
    if portal_type_filter and \\\n
          transaction.getPortalType() not in portal_type_list:\n
      continue\n
\n
    is_source = (brain.mirror_section_relative_url == mvt.getDestinationSection())\n
    if is_source:\n
      if payment_uid and mvt.getSourcePaymentUid() != payment_uid:\n
        continue\n
      if project_uid and mvt.getSourceProjectUid() != project_uid:\n
        continue\n
      if function and not (mvt.getSourceFunction() or \'\').startswith(function):\n
        continue\n
      specific_reference = transaction.getSourceReference()\n
      mirror_section_title = transaction.getDestinationSectionTitle()\n
      section_title = transaction.getSourceSectionTitle()\n
    else:\n
      if payment_uid and mvt.getDestinationPaymentUid() != payment_uid:\n
        continue\n
      if project_uid and mvt.getDestinationProjectUid() != project_uid:\n
        continue\n
      if function and not (mvt.getDestinationFunction() or \'\').startswith(function):\n
        continue\n
      specific_reference = transaction.getDestinationReference()\n
      mirror_section_title = transaction.getSourceSectionTitle()\n
      section_title = transaction.getDestinationSectionTitle()\n
    \n
\n
    debit = max(brain.total_quantity, 0)\n
    total_debit += debit\n
    credit = max(-brain.total_quantity, 0)\n
    total_credit += credit\n
\n
    debit_price = max(brain.total_price, 0)\n
    total_debit_price += debit_price\n
    credit_price = max(-brain.total_price, 0)\n
    total_credit_price += credit_price\n
\n
    brain_date = brain.date\n
    if mvt.getStartDate():\n
      brain_date = brain_date.toZone(mvt.getStartDate().timezone())\n
    \n
    line = Object(uid=\'new_000\',\n
                  total_price=brain.total_price,\n
                  date=brain.date,\n
                  Movement_getSpecificReference=specific_reference,\n
                  Movement_getMirrorSectionTitle=mirror_section_title,\n
                  section_title=section_title,\n
                  debit=debit,\n
                  credit=credit,\n
                  debit_price=debit_price,\n
                  credit_price=credit_price,\n
                  Movement_getExplanationTitle=\n
                    mvt.hasTitle() and mvt.getTitle() or transaction.getTitle())\n
\n
    analytic_info = dict()\n
    for analytic_column, analytic_column_title in analytic_column_list:\n
      if analytic_column == \'project\':\n
        if is_source:\n
          analytic_info[\'project\'] = mvt.asContext(project_uid=mvt.getSourceProjectUid()).Movement_getProjectTitle()\n
        else:\n
          analytic_info[\'project\'] = mvt.asContext(project_uid=mvt.getDestinationProjectUid()).Movement_getProjectTitle()\n
      elif analytic_column == \'function\':\n
        if is_source:\n
          analytic_info[\'function\'] = mvt.asContext(function_uid=mvt.getDestinationFunctionUid()).Movement_getFunctionTitle()\n
        else:\n
          analytic_info[\'function\'] = mvt.asContext(function_uid=mvt.getDestinationFunctionUid()).Movement_getFunctionTitle()\n
      else:\n
        analytic_info[analytic_column] = mvt.getProperty(analytic_column)\n
\n
    line.update(analytic_info)\n
    line_list.append(line)\n
\n
\n
context.REQUEST.set(\n
  \'Account_statNotGroupedAccountingTransactionList.total_debit\', total_debit)\n
context.REQUEST.set(\n
  \'Account_statNotGroupedAccountingTransactionList.total_credit\', total_credit)\n
context.REQUEST.set(\n
  \'Account_statNotGroupedAccountingTransactionList.total_debit_price\',\n
  total_debit_price)\n
context.REQUEST.set(\n
  \'Account_statNotGroupedAccountingTransactionList.total_credit_price\',\n
  total_credit_price)\n
return line_list\n
</string> </value>
        </item>
        <item>
            <key> <string>_params</string> </key>
            <value> <string>selection=None, sort_on=[], node_category=None, node_category_strict_membership=None, from_date=None, selection_name=None, function=None, project_uid=None, analytic_column_list=(), **kw</string> </value>
        </item>
        <item>
            <key> <string>_proxy_roles</string> </key>
            <value>
              <tuple>
                <string>Manager</string>
              </tuple>
            </value>
        </item>
        <item>
            <key> <string>id</string> </key>
            <value> <string>Account_getNotGroupedAccountingTransactionList</string> </value>
        </item>
      </dictionary>
    </pickle>
  </record>
</ZopeData>
