<?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>#\n
#  this script is called in an activity on the Sale Invoice Transaction\n
# after the invoice_builder delivery builder has created\n
# the new Sale Invoice Transaction\n
#\n
from ZODB.POSException import ConflictError \n
\n
invoice = context\n
\n
LOG = lambda msg:context.log(\n
          "InvoiceTransaction_postGenerationActivity on %s" % (invoice.getPath()), msg)\n
\n
# set the causality relation \n
invoice.Delivery_setCausalityFromSimulation()\n
\n
related_packing_list = invoice.getDefaultCausalityValue()\n
#LOG(\'causality %s \' %invoice.getCausalityValueList())\n
\n
# get a price_currency from the packing list\n
related_order  = related_packing_list.getDefaultCausalityValue()\n
if related_order is not None :\n
  price_currency = related_order.getPriceCurrency()\n
  invoice.edit(\n
    resource = price_currency,\n
    price_currency = price_currency,\n
  )\n
  \n
# copy title, if not updating a new delivery\n
if invoice.getTitle() is None :\n
  invoice.setTitle(related_packing_list.getTitle())\n
\n
# initialize accounting_workflow to planned state\n
if invoice.getSimulationState() == \'draft\' : \n
  try :\n
    context.getPortalObject().portal_workflow.doActionFor(\n
      invoice, \'plan_action\', wf_id=\'accounting_workflow\',\n
      comment = \'Initialized by Delivery Builder\',\n
      skip_period_validation = 1 )\n
  except (ConflictError, RuntimeError), e : raise\n
  except Exception, e :\n
    LOG(\'Exception in plan_action %s\' % e)\n
  if invoice.getSimulationState() == \'draft\' : \n
    # call the workflow method, if the user cannot perform this operation.\n
    invoice.plan()\n
\n
# First set the invoice in the building state on the causality workflow\n
invoice.startBuilding()\n
\n
# Then an activity should put the causality state in diverged or solved\n
# XXX after_method_id is not good, it should be after_group_id, but not yet implemented\n
invoice.activate(\n
        after_method_id = ( \'immediateReindexObject\',\n
                            \'recursiveImmediateReindexObject\',\n
                          )).updateCausalityState()\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>**kw</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>kw</string>
                            <string>ZODB.POSException</string>
                            <string>ConflictError</string>
                            <string>context</string>
                            <string>invoice</string>
                            <string>LOG</string>
                            <string>_getattr_</string>
                            <string>related_packing_list</string>
                            <string>related_order</string>
                            <string>None</string>
                            <string>price_currency</string>
                            <string>RuntimeError</string>
                            <string>e</string>
                            <string>Exception</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>InvoiceTransaction_postGenerationActivity</string> </value>
        </item>
        <item>
            <key> <string>warnings</string> </key>
            <value>
              <tuple/>
            </value>
        </item>
      </dictionary>
    </pickle>
  </record>
</ZopeData>
