<?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>""" Create a reversal transaction from current payzen transaction. """\n
from zExceptions import Unauthorized\n
if REQUEST is not None:\n
  raise Unauthorized\n
\n
portal = context.getPortalObject()\n
\n
# Check that we are in state that we are waiting for user manual payment\n
assert context.getPortalType() == \'Sale Invoice Transaction\'\n
assert context.getPaymentMode() == \'payzen\'\n
assert context.getSimulationState() == \'stopped\'\n
assert context.getTotalPrice() != 0\n
assert context.getSpecialise() == "sale_trade_condition_module/slapos_aggregated_trade_condition"\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
assert not paid\n
\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
assert payment is not None\n
assert payment.getSimulationState() == \'started\'\n
assert payment.getPaymentMode() == \'payzen\'\n
assert payment.PaymentTransaction_getPayzenId()[1] is None\n
\n
# Should be safe now to fix everything\n
context.edit(payment_mode=None)\n
payment.edit(payment_mode=None)\n
reversal_transaction = context.Base_createCloneDocument(batch_mode=1)\n
payment.cancel(\n
  comment="Reversal sale invoice transaction created %s" % reversal_transaction.getRelativeUrl())\n
\n
reversal_transaction.edit(\n
  title="Reversal Transaction for %s" % context.getTitle(),\n
  causality_value=context,\n
  description="Reversal Transaction for %s" % context.getTitle(),\n
  specialise_value=portal.sale_trade_condition_module.slapos_manual_accounting_trade_condition,\n
)\n
\n
for line in reversal_transaction.getMovementList():\n
  line.edit(quantity=(-line.getQuantity()))\n
\n
reversal_transaction.confirm(comment="Automatic because of reversal creation")\n
reversal_transaction.stop(comment="Automatic because of reversal creation")\n
\n
return reversal_transaction\n
</string> </value>
        </item>
        <item>
            <key> <string>_params</string> </key>
            <value> <string>REQUEST=None</string> </value>
        </item>
        <item>
            <key> <string>id</string> </key>
            <value> <string>SaleInvoiceTransaction_createReversalPayzenTransaction</string> </value>
        </item>
      </dictionary>
    </pickle>
  </record>
</ZopeData>
