<?xml version="1.0"?>
<ZopeData>
  <record id="1" aka="AAAAAAAAAAE=">
    <pickle>
      <tuple>
        <tuple>
          <string>Products.PythonScripts.PythonScript</string>
          <string>PythonScript</string>
        </tuple>
        <none/>
      </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[

"""\n
  Returns journal entries, for use with AccountingTransactionModule_viewJournal\n
\n
  return a list of dictionnaries like that :\n
\n
  { \'date\'       : Date\n
  , \'description\': String\n
  , \'currency\'   : String\n
  , \'lines\'      : { \'debtor\'        : Bool\n
                   , \'account_gap_id\': String\n
                   , \'account_name\'  : String  # with extra-description (ie. bank name if a bank, organisation name if an other party)\n
                   , \'amount\'        : Float\n
                   }\n
  }\n
"""\n
\n
request = context.REQUEST\n
selection_name = "accounting_selection"\n
N_ = context.Base_translateString\n
result = []\n
journal_total_debit  = 0\n
journal_total_credit = 0\n
\n
# this report can be used in two ways:\n
#   * with a report dialog to specify parameters\n
if request.has_key(\'at_date\'):\n
  at_date = request[\'at_date\'].latestTime()\n
  section_category = request[\'transaction_section_category\']\n
  transaction_simulation_state = request[\'transaction_simulation_state\']\n
  transaction_portal_type = request[\'transaction_portal_type\']\n
  from_date = request.get(\'from_date\', None)\n
  params = { \'sort_on\'         : \'delivery.start_date\',\n
             \'at_date\'         : at_date,\n
             \'simulation_state\': transaction_simulation_state,\n
             \'search_result_keys\': [],\n
             \'section_category\': section_category,\n
             \'portal_type\'     : transaction_portal_type, }\n
\n
  if from_date:\n
    params[\'from_date\'] = from_date\n
\n
  zGetList = context.AccountingTransactionModule_zGetAccountingTransactionList\n
  transaction_list = zGetList( selection_params = params\n
                             , **params\n
                             )\n
else:\n
  stool = context.getPortalObject().portal_selections\n
  transaction_list = [x.getObject() for x in \n
                      stool.callSelectionFor(selection_name)]\n
  section_category = stool.getSelectionParamsFor(selection_name\n
                    ).get(\'section_category\', \'unset\')\n
\n
for transaction in transaction_list:\n
  transaction         = transaction.getObject()\n
  destination_section = transaction.getDestinationSectionValue()\n
  source_section      = transaction.getSourceSectionValue()\n
\n
  # add a test on portal type to bypass bad acquisition of group category from\n
  # person to Orignisation This help us filter employee of the source_section:\n
  # because of acquisition via subordination they are seen as part of the group\n
  # but in this accounting context group define a business unit composed of\n
  # organisation\n
  we_are_destination = (destination_section is not None) and \\\n
      (\'group/%s\' % destination_section.getGroup(\'\')\n
            ).startswith(section_category) and \\\n
            destination_section.getPortalType() == "Organisation"\n
  we_are_source = (source_section is not None) and \\\n
      (\'group/%s\' % source_section.getGroup(\'\')\n
            ).startswith(section_category) and \\\n
            source_section.getPortalType() == "Organisation"\n
\n
  if we_are_source:\n
    specific_reference = transaction.getSourceReference()\n
    date = transaction.getStartDate()\n
  else:\n
    specific_reference = transaction.getDestinationReference()\n
    date = transaction.getStopDate()\n
\n
  lines = []\n
  transaction_dict = { \\\n
      \'date\'       : context.Base_FormatDate( date ),\n
      \'lines\'      : lines,\n
      \'description\': N_( "${transaction_title} (Transaction Reference "   +\n
                         "= ${transaction_reference},\\n Creation Date = " +\n
                         "${creation_date} \\n Currency = ${currency_title})"\n
                       , mapping = {\n
          "transaction_title": unicode(transaction.getTitle() or \'\', \'utf8\'),\n
          "transaction_reference": unicode(specific_reference or \'\', \'utf8\'),\n
          "creation_date": context.Base_FormatDate(\n
                                        transaction.getCreationDate()),\n
          "currency_title": transaction.getResourceTitle() or \'\' })}\n
\n
  result.append(transaction_dict)\n
  transaction_lines = transaction.contentValues(\n
    filter = {\'portal_type\' : context.getPortalAccountingMovementTypeList()})\n
\n
  if we_are_source :\n
    transaction_lines.sort(lambda x,y: cmp(\n
                y.getObject().getSourceInventoriatedTotalAssetPrice(),\n
                x.getObject().getSourceInventoriatedTotalAssetPrice()))\n
  else :\n
    transaction_lines.sort(lambda x,y: cmp(\n
                y.getObject().getDestinationInventoriatedTotalAssetPrice(),\n
                x.getObject().getDestinationInventoriatedTotalAssetPrice()))\n
\n
  for line in transaction_lines:\n
    line = line.getObject()\n
\n
    if we_are_source :\n
      debit   = line.getSourceInventoriatedTotalAssetDebit()  or 0.0\n
      credit  = line.getSourceInventoriatedTotalAssetCredit() or 0.0\n
      debtor  = (line.getSourceInventoriatedTotalAssetPrice() > 0)\n
      account = line.getSourceValue()\n
      if account is None: continue\n
      if account.isMemberOf(\'account_type/asset/cash\'):\n
        account_description = "%s (%s)" % ( line.getSourceTitle()\n
                                          , line.getSourcePaymentTitle()\n
                                          )\n
      elif account.getAccountType() in (\'asset/receivable\',\n
                                        \'liability/payable\'):\n
        account_description = "%s (%s)" % ( line.getSourceTitle()\n
                                          , line.getDestinationSectionTitle()\n
                                          )\n
      else:\n
        account_description = line.getSourceTitle()\n
      lines.append({ \'debtor\'        : debtor\n
                   , \'account_gap_id\': account.Account_getGapId()\n
                   , \'account_name\'  : account_description\n
                   , \'amount\'        : debtor and (debit) or (credit)\n
                   })\n
      if debtor:\n
        journal_total_debit  += debit\n
      else:\n
        journal_total_credit += credit\n
\n
    if we_are_destination:\n
      debit   = line.getDestinationInventoriatedTotalAssetDebit()  or 0.0\n
      credit  = line.getDestinationInventoriatedTotalAssetCredit() or 0.0\n
      debtor  = (debit > credit)\n
      account = line.getDestinationValue()\n
      if account is None: continue\n
      if account.isMemberOf(\'account_type/asset/cash\'):\n
        account_description = "%s (%s)" % ( line.getDestinationTitle()\n
                                          , line.getDestinationPaymentTitle()\n
                                          )\n
      elif account.getAccountType() in (\'asset/receivable\',\n
                                        \'liability/payable\'):\n
        account_description = "%s (%s)" % ( line.getDestinationTitle()\n
                                          , line.getSourceSectionTitle()\n
                                          )\n
      else:\n
        account_description = line.getDestinationTitle()\n
      lines.append({ \'debtor\'        : debtor\n
                   , \'account_gap_id\': account.Account_getGapId()\n
                   , \'account_name\'  : account_description\n
                   , \'amount\'        : debtor and (debit) or (credit)\n
                   })\n
      if debtor:\n
        journal_total_debit  += debit\n
      else:\n
        journal_total_credit += credit\n
\n
\n
return result + [{ "journal_total_debit" : journal_total_debit\n
                 , "journal_total_credit": journal_total_credit\n
                 }]\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>_getattr_</string>
                            <string>context</string>
                            <string>request</string>
                            <string>selection_name</string>
                            <string>N_</string>
                            <string>result</string>
                            <string>journal_total_debit</string>
                            <string>journal_total_credit</string>
                            <string>_getitem_</string>
                            <string>at_date</string>
                            <string>section_category</string>
                            <string>transaction_simulation_state</string>
                            <string>transaction_portal_type</string>
                            <string>None</string>
                            <string>from_date</string>
                            <string>params</string>
                            <string>_write_</string>
                            <string>zGetList</string>
                            <string>_apply_</string>
                            <string>transaction_list</string>
                            <string>stool</string>
                            <string>append</string>
                            <string>$append0</string>
                            <string>_getiter_</string>
                            <string>x</string>
                            <string>transaction</string>
                            <string>destination_section</string>
                            <string>source_section</string>
                            <string>we_are_destination</string>
                            <string>we_are_source</string>
                            <string>specific_reference</string>
                            <string>date</string>
                            <string>lines</string>
                            <string>unicode</string>
                            <string>transaction_dict</string>
                            <string>transaction_lines</string>
                            <string>line</string>
                            <string>debit</string>
                            <string>credit</string>
                            <string>debtor</string>
                            <string>account</string>
                            <string>account_description</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>AccountingTransactionModule_getJournalAccountingTransactionList</string> </value>
        </item>
        <item>
            <key> <string>warnings</string> </key>
            <value>
              <tuple/>
            </value>
        </item>
      </dictionary>
    </pickle>
  </record>
</ZopeData>
