Example #1
0
def get_storage_objects(context, storage_uids):
    """Take a list of UIDs from the form, and resolve to a list of Storages.
    Accepts ManagedStorage, UnmanagedStorage, or StoragePosition UIDs.
    """
    uc = getToolByName(context, 'uid_catalog')
    bio_storages = []
    for uid in storage_uids:
        brain = uc(UID=uid)[0]
        instance = brain.getObject()
        if IUnmanagedStorage.providedBy(instance) \
                or len(instance.get_free_positions()) > 0:
            bio_storages.append(instance)

    return bio_storages
Example #2
0
    def filter_stockitems_by_storage_location(self, items):
        """Return stockitems in the selected storages
        """
        si_storages = self.get_si_storages()
        stockitems = []
        for storage in si_storages:
            if IUnmanagedStorage.providedBy(storage):
                sis = storage.getBackReferences('ItemStorageLocation')
                stockitems += [si for si in sis if si in items]
            elif IManagedStorage.providedBy(storage):
                sis = storage.only_items_of_portal_type('StockItem')
                stockitems += [si for si in sis if si in items]

        return stockitems
Example #3
0
def get_storage_objects(context, storage_uids):
    """Take a list of UIDs from the form, and resolve to a list of Storages.
    Accepts ManagedStorage, UnmanagedStorage, or StoragePosition UIDs.
    """
    uc = getToolByName(context, 'uid_catalog')
    bio_storages = []
    for uid in storage_uids:
        brain = uc(UID=uid)[0]
        instance = brain.getObject()
        if IUnmanagedStorage.providedBy(instance) \
                or len(instance.get_free_positions()) > 0:
            bio_storages.append(instance)

    return bio_storages
Example #4
0
    def get_kit_storages(self):
        """Take a list of UIDs from the form, and resolve to a list of Storages.
        Accepts ManagedStorage, UnmanagedStorage, or StoragePosition UIDs.
        """
        kit_storages = []
        form_uids = self.form['kit_storage_uids'].split(',')
        for uid in form_uids:
            brain = self.bsc(UID=uid)[0]
            instance = brain.getObject()
            # last-minute check if this storage is available
            if IUnmanagedStorage.providedBy(instance) \
                    or len(instance.get_free_positions()) > 0:
                kit_storages.append(instance)

        return kit_storages
    def get_biospecimen_storages(self):
        """Take a list of UIDs from the form, and resolve to a list of Storages.
        Accepts ManagedStorage, UnmanagedStorage, or StoragePosition UIDs.
        """
        uc = getToolByName(self.context, 'uid_catalog')
        bio_storages = []
        form_uids = self.form['biospecimen_storage_uids'].split(',')
        for uid in form_uids:
            brain = uc(UID=uid)[0]
            instance = brain.getObject()
            if IUnmanagedStorage.providedBy(instance) \
                    or len(instance.get_free_positions()) > 0:
                bio_storages.append(instance)

        return bio_storages
Example #6
0
    def get_kit_storages(self):
        """Take a list of UIDs from the form, and resolve to a list of Storages.
        Accepts ManagedStorage, UnmanagedStorage, or StoragePosition UIDs.
        """
        uc = getToolByName(self.context, 'uid_catalog')
        wf = self.portal_workflow
        kit_storages = []
        form_uids = self.form['kit_storage_uids'].split(',')
        for uid in form_uids:
            brain = uc(UID=uid)[0]
            instance = brain.getObject()
            # last-minute check if this storage is available
            if IUnmanagedStorage.providedBy(instance) \
                    or len(instance.get_free_positions()) > 0:
                kit_storages.append(instance)

        return kit_storages
Example #7
0
    def filter_stockitems_by_storage_location(self, items):
        """Return stockitems in the selected storages
        """
        si_storages = self.get_si_storages()
        stockitems = []
        for storage in si_storages:
            if IUnmanagedStorage.providedBy(storage):
                sis = storage.getBackReferences('ItemStorageLocation')
                stockitems += [si for si in sis if si in items]
            elif IManagedStorage.providedBy(storage):
                sis = storage.only_items_of_portal_type('StockItem')
                stockitems += [si for si in sis if si in items]

        # if si_storages:
        #     return [item for item in items
        #             if item.getStorageLocation() in si_storages]
        # else:
        #     return items
        return stockitems
Example #8
0
 def assign_kit_to_storage(self, kits, storages):
     """ assign position to created kits.
     """
     for storage in storages:
         if IManagedStorage.providedBy(storage):
             free_positions = storage.get_free_positions()
             if len(kits) <= len(free_positions):
                 for i, kit in enumerate(kits):
                     kit.setStorageLocation(free_positions[i])
                     self.wf.doActionFor(free_positions[i], 'occupy')
             else:
                 for i, position in enumerate(free_positions):
                     kits[i].setStorageLocation(position)
                     self.wf.doActionFor(position, 'occupy')
                 kits = kits[len(free_positions):]
         elif IUnmanagedStorage.providedBy(storage):
             # Case of unmanaged storage there is no limit in storage until
             # user manually set the storage as full.
             for kit in kits:
                 kit.setStorageLocation(storage)
Example #9
0
def assign_items_to_storages(context, items, storages):
    """ store items inside selected storages
    """
    wf = getToolByName(context, 'portal_workflow')
    for storage in storages:
        if IManagedStorage.providedBy(storage):
            free_positions = storage.get_free_positions()
            if len(items) <= len(free_positions):
                for i, item in enumerate(items):
                    item.setStorageLocation(free_positions[i])
                    wf.doActionFor(free_positions[i], 'occupy')
            else:
                for i, position in enumerate(free_positions):
                    items[i].setStorageLocation(position)
                    wf.doActionFor(position, 'occupy')
                items = items[len(free_positions):]
        elif IUnmanagedStorage.providedBy(storage):
            # Case of unmanaged storage there is no limit in storage until
            # user manually set the storage as full.
            for item in items:
                item.setStorageLocation(storage)
Example #10
0
 def assign_kit_to_storage(self, kits, storages):
     """ assign position to created kits.
     """
     wf = getToolByName(self.context, 'portal_workflow')
     for storage in storages:
         if IManagedStorage.providedBy(storage):
             free_positions = storage.get_free_positions()
             if len(kits) <= len(free_positions):
                 for i, kit in enumerate(kits):
                     kit.setStorageLocation(free_positions[i])
                     wf.doActionFor(free_positions[i], 'occupy')
             else:
                 for i, position in enumerate(free_positions):
                     kits[i].setStorageLocation(position)
                     wf.doActionFor(position)
                 kits = kits[len(free_positions):]
         elif IUnmanagedStorage.providedBy(storage):
             # Case of unmanaged storage there is no limit in storage until
             # user manually set the storage as full.
             for kit in kits:
                 kit.setStorageLocation(storage)
Example #11
0
def assign_items_to_storages(context, items, storages):
    """ store items inside selected storages
    """
    wf = getToolByName(context, 'portal_workflow')
    for storage in storages:
        if IManagedStorage.providedBy(storage):
            free_positions = storage.get_free_positions()
            if len(items) <= len(free_positions):
                for i, item in enumerate(items):
                    item.setStorageLocation(free_positions[i])
                    wf.doActionFor(free_positions[i], 'occupy')
            else:
                for i, position in enumerate(free_positions):
                    items[i].setStorageLocation(position)
                    wf.doActionFor(position, 'occupy')
                items = items[len(free_positions):]
        elif IUnmanagedStorage.providedBy(storage):
            # Case of unmanaged storage there is no limit in storage until
            # user manually set the storage as full.
            for item in items:
                item.setStorageLocation(storage)
 def assign_biospecimens_to_storages(self, biospecimens, storages):
     """ Assign positions to biospecimens inside storages
     """
     wf = getToolByName(self.context, 'portal_workflow')
     for storage in storages:
         if IManagedStorage.providedBy(storage):
             free_positions = storage.get_free_positions()
             if len(biospecimens) <= len(free_positions):
                 for i, biospecimen in enumerate(biospecimens):
                     biospecimen.setStorageLocation(free_positions[i])
                     wf.doActionFor(free_positions[i], 'occupy')
             else:
                 for i, position in enumerate(free_positions):
                     biospecimens[i].setStorageLocation(position)
                     wf.doActionFor(position, 'occupy')
                 biospecimens = biospecimens[len(free_positions):]
         elif IUnmanagedStorage.providedBy(storage):
             # Case of unmanaged storage there is no limit in storage until
             # user manually set the storage as full.
             for biospecimen in biospecimens:
                 biospecimen.setStorageLocation(storage)
Example #13
0
    def count_storage_positions(storages):
        """Return the number of items that can be stored in storages.

        If any of these storages are "UnmanagedStorage" objects, then the
        result will be -1 as we cannot know how many items can be stored here.
        """
        count = 0
        for storage in storages:
            # If storage is an unmanaged storage, we no longer care about
            # "number of positions".
            if IUnmanagedStorage.providedBy(storage):
                return -1
            # If storage is a StoragePosition, simply increment the count.
            elif IStoragePosition.providedBy(storage):
                count += 1
            # If storage is a ManagedStorage, increment count for each
            # available StoragePosition
            elif IManagedStorage.providedBy(storage):
                count += storage.getFreePositions()
            else:
                raise ValidationError("Storage %s is not a valid storage type" %
                                      storage)
        return count
Example #14
0
    def count_storage_positions(self, storages):
        """Return the number of items that can be stored in storages.

        If any of these storages are "UnmanagedStorage" objects, then the
        result will be -1 as we cannot know how many items can be stored here.
        """
        count = 0
        for storage in storages:
            # If storage is an unmanaged storage, we no longer care about
            # "number of positions".
            if IUnmanagedStorage.providedBy(storage):
                return -1
            # If storage is a StoragePosition, simply increment the count.
            elif IStoragePosition.providedBy(storage):
                count += 1
            # If storage is a ManagedStorage, increment count for each
            # available StoragePosition
            elif IManagedStorage.providedBy(storage):
                count += storage.get_free_positions()
            else:
                raise ValidationError(
                    "Storage %s is not a valid storage type" % storage)
        return count