From 4edb0d7e09eb968d05a814bd45bcba008f7ade40 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Nowak?= <luke@nexedi.com>
Date: Mon, 6 Feb 2012 11:19:28 +0100
Subject: [PATCH] Disallow to allocate partition for Person with negative
 balance.

---
 ...y_isDestinationSectionAllowedToRequest.xml | 87 +++++++++++++++++++
 .../Delivery_assignComputerPartition.xml      |  2 +
 master/bt5/vifib_open_trade/bt/revision       |  2 +-
 3 files changed, 90 insertions(+), 1 deletion(-)
 create mode 100644 master/bt5/vifib_open_trade/SkinTemplateItem/portal_skins/vifib_open_trade/Delivery_isDestinationSectionAllowedToRequest.xml

diff --git a/master/bt5/vifib_open_trade/SkinTemplateItem/portal_skins/vifib_open_trade/Delivery_isDestinationSectionAllowedToRequest.xml b/master/bt5/vifib_open_trade/SkinTemplateItem/portal_skins/vifib_open_trade/Delivery_isDestinationSectionAllowedToRequest.xml
new file mode 100644
index 000000000..a5eda374e
--- /dev/null
+++ b/master/bt5/vifib_open_trade/SkinTemplateItem/portal_skins/vifib_open_trade/Delivery_isDestinationSectionAllowedToRequest.xml
@@ -0,0 +1,87 @@
+<?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 encoding="cdata"><![CDATA[
+
+section_uid = context.getSourceSectionUid()\n
+customer_uid = context.getDestinationSectionUid()\n
+simulation_state = context.getPortalCurrentInventoryStateList() + context.getPortalTransitInventoryStateList()\n
+balance = context.portal_simulation.getInventoryAssetPrice(\n
+  node_category=\'account_type/asset/receivable\',\n
+  simulation_state=simulation_state,\n
+  section_uid=section_uid,\n
+  mirror_section_uid=customer_uid)\n
+return balance >= 0.\n
+
+
+]]></string> </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>_proxy_roles</string> </key>
+            <value>
+              <tuple>
+                <string>Manager</string>
+              </tuple>
+            </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>Delivery_isDestinationSectionAllowedToRequest</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/master/bt5/vifib_open_trade/WorkflowTemplateItem/portal_workflow/vifib_open_order_interaction_workflow/scripts/Delivery_assignComputerPartition.xml b/master/bt5/vifib_open_trade/WorkflowTemplateItem/portal_workflow/vifib_open_order_interaction_workflow/scripts/Delivery_assignComputerPartition.xml
index b31632275..3de8af8e8 100644
--- a/master/bt5/vifib_open_trade/WorkflowTemplateItem/portal_workflow/vifib_open_order_interaction_workflow/scripts/Delivery_assignComputerPartition.xml
+++ b/master/bt5/vifib_open_trade/WorkflowTemplateItem/portal_workflow/vifib_open_order_interaction_workflow/scripts/Delivery_assignComputerPartition.xml
@@ -62,6 +62,8 @@ for order_line in order.getMovementList():\n
   if order_line.getResource() == setup_service_relative_url:\n
     computer_partition = order_line.getAggregateValue(portal_type="Computer Partition")\n
     if computer_partition is None:\n
+      if not order.Delivery_isDestinationSectionAllowedToRequest():\n
+        raise ValueError(\'Request disallowed\')\n
       software_release = order_line.getAggregateValue(portal_type="Software Release")\n
       software_instance = order_line.getAggregateValue(portal_type=instance_portal_type_list)\n
 \n
diff --git a/master/bt5/vifib_open_trade/bt/revision b/master/bt5/vifib_open_trade/bt/revision
index f79f5e337..dc9414b21 100644
--- a/master/bt5/vifib_open_trade/bt/revision
+++ b/master/bt5/vifib_open_trade/bt/revision
@@ -1 +1 @@
-153
\ No newline at end of file
+154
\ No newline at end of file
-- 
2.30.9