<?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>simulation_state = context.getSimulationState() \n
\n
if simulation_state in ("cancelled", "deleted", "draft"):\n
  result = "Cancelled"\n
\n
elif simulation_state in ("planned", "confirmed", "ordered", "started"):\n
  result = "Ongoing"\n
\n
else:\n
  portal = context.getPortalObject()\n
\n
  paid = True\n
  for line in context.getMovementList(portal.getPortalAccountingMovementTypeList()):\n
    node_value = line.getSourceValue(portal_type=\'Account\')\n
    if node_value.getAccountType() == \'asset/receivable\':\n
      if not line.hasGroupingReference():\n
        paid = False\n
        break\n
\n
  reversal = portal.portal_catalog.getResultValue(\n
      portal_type="Sale Invoice Transaction",\n
      simulation_state="stopped",\n
      default_causality_uid=context.getUid()\n
    )\n
  if reversal is not None and (context.getTotalPrice() + reversal.getTotalPrice()) == 0:\n
    result = "Cancelled"\n
  elif paid:\n
    result = "Paid"\n
  elif context.getTotalPrice() == 0:\n
    result = "Free!"\n
  else:\n
    # Check if there is an ongoing payzen payment\n
    payment = portal.portal_catalog.getResultValue(\n
      portal_type="Payment Transaction",\n
      simulation_state="started",\n
      default_causality_uid=context.getUid(),\n
      default_payment_mode_uid=portal.portal_categories.payment_mode.payzen.getUid(),\n
    )\n
    if payment is None:\n
      result = "Unpaid"\n
    else:\n
      # Check if mapping exists\n
      person = portal.ERP5Site_getAuthenticatedMemberPersonValue()\n
      payzen_id = person.Person_restrictMethodAsShadowUser(\n
        shadow_document=person,\n
        callable_object=payment.PaymentTransaction_getPayzenId,\n
        argument_list=[])[0]\n
      if payzen_id is None:\n
        result = "Pay now"\n
      else:\n
        result = "Waiting for payment confirmation"\n
\n
return result\n
</string> </value>
        </item>
        <item>
            <key> <string>_params</string> </key>
            <value> <string></string> </value>
        </item>
        <item>
            <key> <string>id</string> </key>
            <value> <string>AccountingTransaction_getPaymentState</string> </value>
        </item>
      </dictionary>
    </pickle>
  </record>
</ZopeData>
