Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
0
def filter_stock_items_by_storage(items, portal_catalog, storage_uids):
    """Return stock-items in the selected storage
    """
    si_storage = get_si_storages(storage_uids, portal_catalog)
    stock_items = []
    for storage in si_storage:
        if IUnmanagedStorage.providedBy(storage):
            sis = storage.getBackReferences('ItemStorageLocation')
            stock_items += [si for si in sis if si in items]
        elif IManagedStorage.providedBy(storage):
            sis = storage.only_items_of_portal_type('StockItem')
            stock_items += [si for si in sis if si in items]

    return stock_items
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    def get_kit_storage(self):
        """Take a list of UIDs from the form, and resolve to a list of Storages.
        Accepts ManagedStorage, UnmanagedStorage, or StoragePosition UIDs. Not used!
        """
        kit_storages = []
        form_uids = self.form['kit-storage-uids'].split(',')
        for uid in form_uids:
            brain = self.bika_setup_catalog(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
Exemplo n.º 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
Exemplo n.º 7
0
 def assign_kit_to_storage(self, kits, storages):
     """ assign position to created kits. Not used anymore!
     """
     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)
Exemplo n.º 8
0
 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 11
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