<?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>"""\n
  Builds the delivery.\n
"""\n
from Products.ERP5Type.Log import log\n
delivery = sci[\'object\']\n
delivery_portal_type = delivery.getPortalType()\n
portal_deliveries = sci.getPortal().portal_deliveries\n
\n
builder_by_ptype = {\n
  \'Sale Invoice Transaction\' : \'sale_invoice_transaction_builder\',\n
  \'Purchase Invoice Transaction\' : \'purchase_invoice_transaction_builder\',\n
  \'Pay Sheet Transaction\' :  \'pay_sheet_transaction_builder\',\n
}\n
\n
if builder_by_ptype.has_key(delivery_portal_type) :\n
  builder = getattr(portal_deliveries, builder_by_ptype[delivery_portal_type], None)\n
  if builder is None :\n
    log(\'erp5_accounting\',\n
        \'unable to build : no builder in %s\' % builder_by_ptype[delivery_portal_type])\n
    return\n
\n
  ### Kev patch: Generate pay sheet accounting lines (inspired by order_workflow)\n
  # (It could be great to make this Delivery_build script more generic)\n
  if delivery_portal_type == \'Pay Sheet Transaction\':\n
    PRIORITY     = 3\n
    pay_sheet    = delivery\n
    previous_tag = pay_sheet.getPath() + \'_firstUpdateAppliedRule\'\n
    expand_tag   = pay_sheet.getPath() + \'_expand\'\n
    activate_kw  = { \'tag\'     : expand_tag\n
                   , \'priority\': PRIORITY\n
                   }\n
\n
    pay_sheet.activate( tag       = expand_tag\n
                      , after_tag = previous_tag\n
                      , priority  = PRIORITY\n
                      ).updateAppliedRule( rule_reference = \'default_invoice_rule\'\n
                                         , activate_kw = activate_kw\n
                                         )\n
\n
    builder = pay_sheet.portal_deliveries.pay_sheet_transaction_builder\n
    builder.activate( activity  = \'SQLQueue\'\n
                    , after_tag = expand_tag\n
                    , priority  = PRIORITY\n
                    ).build( explanation_uid = pay_sheet.getUid()\n
                           , activate_kw     = activate_kw\n
                           )\n
    return\n
  ### End of kev patch\n
\n
\n
  # build accounting lines\n
  explanation_uid_list = [delivery.getUid(), ]\n
  packing_list = delivery.getCausalityValue(\n
                             portal_type=(\'Sale Packing List\',\n
                                          \'Purchase Packing List\'))\n
  if packing_list is not None:\n
    explanation_uid_list.append(packing_list.getUid())\n
    order = packing_list.getCausalityValue(\n
                             portal_type=(\'Sale Order\',\n
                                          \'Purchase Order\'))\n
    if order is not None:\n
      explanation_uid_list.append(order.getUid())\n
\n
  build_trade_model_tag = \'invoice_transaction_build_trade_model_%s\' % \\\n
                                 delivery.getRelativeUrl()\n
  build_accounting_tag = \'invoice_transaction_build_accounting_%s\' % delivery.getRelativeUrl()\n
  update_applied_rule_tag = \'%s_updateAppliedRule\' % delivery.getPath()\n
  builder.activate(\n
      activity=\'SQLQueue\',\n
      after_tag=(update_applied_rule_tag,\n
                 build_trade_model_tag,),\n
      tag=build_accounting_tag,\n
      activate_kw=dict(tag=build_accounting_tag)).build(\n
                      activate_kw=dict(tag=build_accounting_tag),\n
                      explanation_uid=explanation_uid_list)\n
\n
  # build related payment transactions\n
  portal_deliveries.payment_transaction_builder.activate(\n
                      activity=\'SQLQueue\',\n
                      after_tag=( build_trade_model_tag,\n
                                  update_applied_rule_tag,\n
                                  build_accounting_tag, ),\n
                      ).build(\n
                          explanation_uid=explanation_uid_list)\n
\n
  # set the object in building state.\n
  delivery.startBuilding()\n
  delivery.activate(after_tag=(\n
                      build_trade_model_tag,\n
                      build_accounting_tag,)\n
                      ).updateCausalityState()\n
</string> </value>
        </item>
        <item>
            <key> <string>_code</string> </key>
            <value>
              <none/>
            </value>
        </item>
        <item>
            <key> <string>_params</string> </key>
            <value> <string>sci</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>sci</string>
                            <string>Products.ERP5Type.Log</string>
                            <string>log</string>
                            <string>_getitem_</string>
                            <string>delivery</string>
                            <string>_getattr_</string>
                            <string>delivery_portal_type</string>
                            <string>portal_deliveries</string>
                            <string>builder_by_ptype</string>
                            <string>getattr</string>
                            <string>None</string>
                            <string>builder</string>
                            <string>PRIORITY</string>
                            <string>pay_sheet</string>
                            <string>previous_tag</string>
                            <string>expand_tag</string>
                            <string>activate_kw</string>
                            <string>explanation_uid_list</string>
                            <string>packing_list</string>
                            <string>order</string>
                            <string>build_trade_model_tag</string>
                            <string>build_accounting_tag</string>
                            <string>update_applied_rule_tag</string>
                            <string>dict</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>Delivery_Build</string> </value>
        </item>
        <item>
            <key> <string>warnings</string> </key>
            <value>
              <tuple/>
            </value>
        </item>
      </dictionary>
    </pickle>
  </record>
</ZopeData>
