created method to return the thinnest full tree which contains a list of org IDs
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 1 Feb 2008 22:27:19 +0000 (22:27 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 1 Feb 2008 22:27:19 +0000 (22:27 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@8581 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/python/oils/org.py

index d5f45b6..431fc6d 100644 (file)
@@ -41,6 +41,8 @@ class OrgUtil(object):
     @staticmethod
     def get_org_unit(org_id):
         OrgUtil._verify_tree()
+        if isinstance(org_id, osrf.net_obj.NetworkObject):
+            return org_id
         return OrgUtil._flat_org_tree[org_id]
         
 
@@ -95,6 +97,23 @@ class OrgUtil(object):
         return root
 
     @staticmethod
+    def get_union_tree(org_list):
+        ''' Returns the smallest org tree which encompases all of the orgs in org_list '''
+        main_tree = OrgUtil.get_related_tree(OrgUtil.get_org_unit(org_list.pop(0)))
+        for org in org_list:
+            node = OrgUtil.get_related_tree(OrgUtil.get_org_unit(org))
+            main_node = main_tree
+
+            while node.id() == main_node.id():
+                node = node.children()[0]
+                main_node = main_node.children()[0]
+
+            print main_node.id()
+            OrgUtil.get_org_unit(main_node.parent_ou()).children().append(node)
+
+        return main_tree
+
+    @staticmethod
     def get_related_list(org_unit):
         ''' Returns a flat list of related org_units '''
         OrgUtil._verify_tree()