Commit 2f28b071 authored by Ayush Tiwari's avatar Ayush Tiwari Committed by Ayush Tiwari

bt5_config: Update install function for Business Item

parent 12a08e34
......@@ -376,15 +376,15 @@ class BusinessManager(XMLObject):
"""
if self.status == 'uninstalled':
self.reduceBusinessManager()
elif self.status == 'reduced':
self.flattenBusinessManager()
#elif self.status == 'reduced':
# self.flattenBusinessManager()
self._install()
def _install(self):
"""
Run installation
"""
if self.status != 'flattened':
if self.status != 'reduced':
self.install()
else:
# Invoke install on every BusinessItem object
......@@ -434,8 +434,8 @@ class BusinessManager(XMLObject):
A Business Manager BT is said to be reduced if and only if:
reduce(BT) = BT
"""
path_list = [path_item.getBusinessPath() for path_item
in self._path_item_list]
path_list = list(set([path_item.getBusinessPath() for path_item
in self._path_item_list]))
reduced_path_item_list = []
......@@ -463,10 +463,10 @@ class BusinessManager(XMLObject):
for path, path_item_list in seen_path_dict.items():
# Create separate list of list items with highest priority
higest_priority_layer = max(path_item_list, key=attrgetter('_layer'))
higest_priority_layer = max(path_item_list, key=attrgetter('_layer'))._layer
prioritized_path_item = [path_item for path_item
in path_item_list
if path_item._layer == higest_priority_layer._layer]
if path_item._layer == higest_priority_layer]
# Separate the positive and negative sign path_item
if len(prioritized_path_item) > 1:
......@@ -483,7 +483,7 @@ class BusinessManager(XMLObject):
combined_subtracted_path_item = reduce(lambda x, y: x+y, path_item_list_subtract)
added_value = combined_added_path_item._value
subtraced_value = combined_subtracted_path_item._value
subtracted_value = combined_subtracted_path_item._value
if added_value != subtracted_value:
# Append the arithmetically combined path_item objects in the final
......@@ -495,9 +495,11 @@ class BusinessManager(XMLObject):
combined_subtracted_path_item._value = subtracted_value
# Append the path_item to the final reduced path_item_list after
# doing required arithmetic on it
reduced_path_item_list.append(combined_added_path_item)
# doing required arithmetic on it. Make sure to first append
# subtracted item because while installation, we need to first
# uninstall the old object and then install new object at same path
reduced_path_item_list.append(combined_subtracted_path_item)
reduced_path_item_list.append(combined_added_path_item)
else:
reduced_path_item_list.append(prioritized_path_item[0])
......@@ -516,6 +518,12 @@ class BusinessManager(XMLObject):
"""
built_in_number_type = (int, long, float, complex)
built_in_container_type = (tuple, list, dict, set)
built_in_type_list = built_in_number_type + built_in_container_type
# For ERP5 objects, we should return the added and subtracted values as it is
if type(added_value).__name__ not in built_in_type_list and \
type(subtracted_value).__name__ not in built_in_type_list:
return added_value, subtracted_value
# For all the values of container type, we remove the intersection
added_value = [x for x in added_value if x not in subtracted_value]
......@@ -669,6 +677,7 @@ class BusinessItem(Implicit, Persistent):
"""
# In case the path denotes property, we create separate object for
# ObjectTemplateItem and handle the installation there.
import pdb; pdb.set_trace()
portal = context.getPortalObject()
if self.isProperty:
realtive_url, property_id = self._path.split('#')
......@@ -687,10 +696,11 @@ class BusinessItem(Implicit, Persistent):
# delete the old object before installing a new object
if old_obj:
container._delOb(object_id)
if self._sign == 1:
# install object
obj = self._value
obj = obj._getCopy(container)
container._setObject(object_id, obj)
container._setOb(object_id, obj)
obj = container._getOb(object_id)
obj.isIndexable = ConstantGetter('isIndexable', value=False)
aq_base(obj).uid = portal.portal_catalog.newUid()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment