コード例 #1
0
def update_childrens_full_path():

    store_location_id = request.args[0]
    mylogger.debug(message='store_location_id:%s' % store_location_id)

    store_location_mapper = STORE_LOCATION_MAPPER()

    _store_location = store_location_mapper.find(
        store_location_id=store_location_id)[0]

    # updating childrens full path
    for _children in _store_location.retrieve_children():

        mylogger.debug(message='_children:%s' % _children)
        _children.compute_and_set_full_path()
        store_location_mapper.update(_children)

    # and current store location full path
    #_store_location.compute_and_set_full_path()
    #store_location_mapper.update(_store_location)

    cc.clear_menu_cache()

    redirect(
        URL(request.application,
            request.controller,
            'list_reload',
            args=_store_location.entity.id))
コード例 #2
0
def list_entity():
    '''
    lists store locations of the given ENTITY
    '''
    mylogger.debug(message='request.vars:%s' % request.vars)

    store_location_mapper = STORE_LOCATION_MAPPER()

    _entity_id = request.args[0]

    _store_locations = store_location_mapper.find(
        entity_id=_entity_id, orderby=db.store_location.label_full_path)

    return dict(store_locations=_store_locations)
コード例 #3
0
ファイル: storage.py プロジェクト: tbellembois/chimitheque
def create_stock(form):

    _product = PRODUCT_MAPPER().find(form.vars['product'])[0]
    _store_location = STORE_LOCATION_MAPPER().find(
        form.vars['store_location'])[0]
    _entity_id = _store_location.entity.id
    if db((db.stock.product == _product.id)
          & (db.stock.entity == _entity_id)).count() == 0:
        db.stock.insert(product=_product.id, entity=_entity_id)
        db.commit()
コード例 #4
0
def delete():

    store_location_id = request.args[0]

    store_location_mapper = STORE_LOCATION_MAPPER()

    _store_location = store_location_mapper.find(
        store_location_id=store_location_id)[0]

    form = crud.delete(db.store_location,
                       store_location_id,
                       next=URL(request.application,
                                request.controller,
                                'list_reload',
                                args=_store_location.entity.id))

    cc.clear_menu_cache()

    return dict(form=form)
コード例 #5
0
def ajax_get_entity_store_location_options():
    '''
    returns store locations of the ENTITY given in parameters
    as HTML select options
    '''
    mylogger.debug(message='request.vars:%s' % request.vars)

    _entity_id = request.vars['entity']

    store_location_mapper = STORE_LOCATION_MAPPER()
    _store_locations = store_location_mapper.find(entity_id=_entity_id)
    mylogger.debug(message='_store_locations:%s' % _store_locations)

    # hum... not sure this is a very clean way to unblock the UI and set the style...
    _result = "<script>$('select#store_location_parent').css('border', '4px solid yellow');</script><option value=''></option>"
    if _store_locations is not None:
        for _store_location in _store_locations:
            # str(_store_location.full_path) if full_path is None (should never happen) to concatenate strings
            _result += "<option value='" + str(
                _store_location.id) + "'>" + str(
                    _store_location.full_path) + "</option>"

    return XML(_result)
コード例 #6
0
    def options(self, *args1, **args2):
        _store_location_id=current.request.args[0] if len(current.request.args) != 0 \
                                                   else None

        # retrieving the ENTITY id of the current store location
        if _store_location_id is not None:
            selected_entity = STORE_LOCATION_MAPPER().find(
                store_location_id=_store_location_id)[0].entity.id
        else:
            selected_entity = None

        if selected_entity is not None:
            # retrieving the store locations that belongs to the same ENTITY
            self.dbset = current.db(
                (current.db.store_location.entity == selected_entity)
                & (~(current.db.store_location.id == _store_location_id)))
        else:
            # while creating a new store location, request.args[0] does not exist
            self.dbset = current.db(current.db.store_location.id == -1)

        return super(IS_IN_DB_AND_SELECTED_ENTITY,
                     self).options(*args1, **args2)
コード例 #7
0
 def __init__(self):
     self.__product_mapper = PRODUCT_MAPPER()
     self.__person_mapper = PERSON_MAPPER()
     self.__store_location_mapper = STORE_LOCATION_MAPPER()
     self.__supplier_mapper = SUPPLIER_MAPPER()
     self.__unit_mapper = UNIT_MAPPER()
コード例 #8
0
class STORAGE_MAPPER(object):

    def __init__(self):
        self.__product_mapper = PRODUCT_MAPPER()
        self.__person_mapper = PERSON_MAPPER()
        self.__store_location_mapper = STORE_LOCATION_MAPPER()
        self.__supplier_mapper = SUPPLIER_MAPPER()
        self.__unit_mapper = UNIT_MAPPER()

    def __storage_from_row(self, storage_row):
        return STORAGE(id=storage_row['id'],
                       volume_weight=storage_row['volume_weight'],
                       unit=lambda: self.__unit_mapper.find(unit_id=storage_row['unit']) \
                                       if storage_row['unit'] is not None \
                                       else None,
                       nb_items=storage_row['nb_items'],
                       creation_datetime=storage_row['creation_datetime'],
                       entry_datetime=storage_row['entry_datetime'],
                       exit_datetime=storage_row['exit_datetime'],
                       expiration_datetime=storage_row['expiration_datetime'],
                       opening_datetime=storage_row['opening_datetime'],
                       comment=storage_row['comment'],
                       barecode=storage_row['barecode'],
                       reference=storage_row['reference'],
                       batch_number=storage_row['batch_number'],
                       archive=storage_row['archive'],
                       to_destroy=storage_row['to_destroy'],
                       product=lambda: self.__product_mapper.find(product_id=storage_row['product'])[0],
                       person=lambda: self.__person_mapper.find(person_id=storage_row['person'])[0],
                       store_location=lambda: self.__store_location_mapper.find(store_location_id=storage_row['store_location'])[0],
                       supplier=lambda: self.__supplier_mapper.find(supplier_id=storage_row['supplier'])[0],
                       # storage history
                       modification_datetime=storage_row['modification_datetime'] if 'modification_datetime' in storage_row else None,

                       has_borrowing=lambda: self.has_borrowing(storage_row['id']),
                       retrieve_borrower=lambda: self.retrieve_borrower(storage_row['id']),
                       retrieve_borrow_datetime=lambda: self.retrieve_borrow_datetime(storage_row['id']),
                       retrieve_borrow_comment=lambda: self.retrieve_borrow_comment(storage_row['id']),
                       has_history=lambda: self.has_history(storage_row['id']))

    def find(self, storage_id=None, storage_history_id=None, entity_id=None, negate_entity_search=False, store_location_id=None, product_id=None, unit_reference_id=None, archive=False, history=False, limitby=None, orderby=None):

        my_logger.debug(message='storage_id:%s' % storage_id)

        assert (storage_history_id is not None and history) or (storage_history_id is None), "history must be True with a storage_history_id!"

        if history:
            table = 'storage_history'
        else:
            table = 'storage'

        query_list = []
        if storage_id is not None or storage_history_id is not None:
            if history:
                if storage_history_id is not None:
                    query_list.append(current.db.storage_history.id == storage_history_id)
                else:
                    query_list.append(current.db.storage_history.current_record == storage_id)
            else:
                if type(storage_id) is ListType:
                    query_list.append(current.db[table]['id'].belongs(storage_id))
                else:
                    query_list.append(current.db[table]['id'] == storage_id)
        if entity_id is not None:
            if type(entity_id) is ListType:
                if negate_entity_search:
                    query_list.append((current.db[table]['store_location']==current.db.store_location.id) &
                                      (~current.db.store_location.entity.belongs(tuple(entity_id))))
                else:
                    query_list.append((current.db[table]['store_location']==current.db.store_location.id) &
                                      (current.db.store_location.entity.belongs(tuple(entity_id))))
            else:
                if negate_entity_search:
                    query_list.append((current.db[table]['store_location']==current.db.store_location.id) &
                                      (~current.db.store_location.entity==entity_id))
                else:
                    query_list.append((current.db[table]['store_location']==current.db.store_location.id) &
                                      (current.db.store_location.entity==entity_id))
        if store_location_id is not None:
            query_list.append(current.db[table]['store_location'] == store_location_id)
        if product_id is not None:
            if type(product_id) is ListType:
                query_list.append(current.db[table]['product'].belongs(product_id))
            else:
                query_list.append(current.db[table]['product'] == product_id)
        if unit_reference_id is not None:
            query_list.append((current.db.storage.unit == current.db.unit.id) &
                              (current.db.unit.reference == unit_reference_id))

        if archive is not None:
            final_query = (current.db[table]['archive']==archive)
        else:
            final_query = (current.db[table]['id']>0)

        # building the final query
        for query in query_list:
            my_logger.debug(message='query:%s' % str(query))
            final_query = final_query.__and__(query)
        my_logger.debug(message='final_query:%s' % str(final_query))

        _storage_rows = current.db(final_query).select(current.db[table]['ALL'],
                left=(current.db.borrow.on(current.db[table]['id'] == current.db.borrow.storage)),
                limitby=limitby,
                orderby=orderby)

        my_logger.debug(message='len(_storage_rows):%s' % str(len(_storage_rows)))
        my_logger.debug(message='_storage_rows:%s' % str(_storage_rows))
        if len(_storage_rows) == 0:
            return []
        else:
            return [self.__storage_from_row(_storage_row) for _storage_row in _storage_rows]

    def has_history(self, storage_id):
        return current.db(current.db.storage_history.current_record==storage_id).count() > 0

    def has_borrowing(self, storage_id):
        return current.db(current.db.borrow.storage==storage_id).count() > 0

    def retrieve_borrower(self, storage_id):

        borrower = current.db((current.db.borrow.storage==storage_id) &
                              (current.db.borrow.borrower==current.db.person.id)).select(current.db.person.id).first()

        if borrower is not None:
            return PERSON_MAPPER().find(person_id=borrower.id)[0]
        else:
            return None

    def retrieve_borrow_comment(self, storage_id):

        borrow = current.db((current.db.borrow.storage==storage_id)).select(current.db.borrow.comment).first()

        if borrow is not None:
            return borrow.comment
        else:
            return None

    def retrieve_borrow_datetime(self, storage_id):

        borrow = current.db((current.db.borrow.storage==storage_id)).select(current.db.borrow.creation_datetime).first()

        if borrow is not None:
            return borrow.creation_datetime
        else:
            return None

    def delete(self, storage): # STORAGE type

        current.db(current.db.storage.id==storage.id).delete()
        current.db.commit()

    def update(self, storage): # STORAGE type

        row = current.db(current.db.storage.id==storage.id).select().first()

        row.update_record(product=storage.product.id,
                          store_location=storage.store_location.id,
                          volume_weight=storage.volume_weight,
                          unit=storage.unit.id if storage.unit is not None else None,
                          nb_items=storage.nb_items,
                          entry_datetime=storage.entry_datetime,
                          exit_datetime=storage.exit_datetime,
                          expiration_datetime=storage.expiration_datetime,
                          opening_datetime=storage.opening_datetime,
                          comment=storage.comment,
                          barecode=storage.barecode,
                          reference=storage.reference,
                          batch_number=storage.batch_number,
                          supplier=storage.supplier.id,
                          archive=storage.archive,
                          to_destroy=storage.to_destroy)

        current.db.commit()

    @staticmethod
    def create_barecode(product_id):
        """Return the generated barecode from a product
        """
        mylogger.debug(message='create_barecode')
        product_cas_number = current.db(current.db.product.id == product_id).select(current.db.product.cas_number).first().cas_number

        mylogger.debug(message='product_id:%s' % product_id)
        mylogger.debug(message='product_cas_number:%s' % product_cas_number)

        last_storage_id = current.db(current.db.storage).count()
        mylogger.debug(message='last_storage_id:%s' % last_storage_id)

        today = datetime.date.today()
        today = today.strftime('%Y%m%d')

        barecode = '%s_%s_%s.1' % (product_cas_number, today, last_storage_id)
        mylogger.debug(message='barecode:%s' % barecode)

        return barecode
コード例 #9
0
 def __init__(self):
     self.__product_mapper = PRODUCT_MAPPER()
     self.__store_location_mapper = STORE_LOCATION_MAPPER()
     self.__storage_mapper = STORAGE_MAPPER()
     self.__unit_mapper = UNIT_MAPPER()
コード例 #10
0
class STOCK_STORE_LOCATION_MAPPER(object):
    def __init__(self):
        self.__product_mapper = PRODUCT_MAPPER()
        self.__store_location_mapper = STORE_LOCATION_MAPPER()
        self.__storage_mapper = STORAGE_MAPPER()
        self.__unit_mapper = UNIT_MAPPER()

    def __stock_store_location_from_row(self, stock_store_location_row):
        return STOCK_STORE_LOCATION(id=stock_store_location_row['id'],
                                    product=lambda: self.__product_mapper.find(stock_store_location_row['product'])[0],
                                    store_location=lambda: self.__store_location_mapper.find(stock_store_location_row['store_location'])[0],
                                    unit_reference=lambda: self.__unit_mapper.find(stock_store_location_row['unit_reference']) \
                                                           if stock_store_location_row['unit_reference'] is not None \
                                                           else None,
                                    volume_weight_actual=stock_store_location_row['volume_weight_actual'],
                                    volume_weight_total=stock_store_location_row['volume_weight_total'],
                                    storages=lambda: self.find(store_location_id=stock_store_location_row['store_location'],
                                                               product_id=stock_store_location_row['product'],
                                                               unit_reference_id=stock_store_location_row['unit_reference']))

    # development/test function - not to be used in the code
    def new_for_store_location_and_product_and_unit(self, store_location_id,
                                                    product_id,
                                                    unit_reference_id):
        _stock_store_location_row = {}
        _stock_store_location_row['id'] = -1  # not used
        _stock_store_location_row['store_location'] = store_location_id
        _stock_store_location_row['product'] = product_id
        _stock_store_location_row['unit_reference'] = unit_reference_id
        _stock_store_location_row['volume_weight_actual'] = 0
        _stock_store_location_row['volume_weight_total'] = 0

        return self.__stock_store_location_from_row(_stock_store_location_row)

    def find(self,
             store_location_id,
             product_id=None,
             unit_reference_id=None,
             no_unit_reference=False):
        assert (
            (no_unit_reference and (unit_reference_id is None))
            or ((not no_unit_reference) and (unit_reference_id is not None)),
            "unit_reference_id and no_unit_reference parameters incoherence!")

        query_list = []

        if product_id is not None:
            query_list.append(
                current.db.stock_store_location.product == product_id)
        if no_unit_reference:
            query_list.append(
                current.db.stock_store_location.unit_reference == None)
        elif unit_reference_id is not None:
            query_list.append(current.db.stock_store_location.unit_reference ==
                              unit_reference_id)
        else:
            query_list.append(current.db.stock_store_location.id > 0)

        #query_list.append(current.db.stock_store_location.unit_reference == unit_reference_id)

        final_query = (current.db.stock_store_location.store_location ==
                       store_location_id)

        # building the final query
        for query in query_list:
            my_logger.debug(message='query:%s' % str(query))
            final_query = final_query.__and__(query)

        _stock_store_location_rows = current.db(final_query).select()

        if len(_stock_store_location_rows) == 0:
            return []
        else:
            return [
                self.__stock_store_location_from_row(_stock_store_location_row)
                for _stock_store_location_row in _stock_store_location_rows
            ]

    def exists(self,
               store_location_id,
               product_id,
               unit_reference_id=None,
               no_unit_reference=False):
        assert (
            (no_unit_reference and (unit_reference_id is None))
            or ((not no_unit_reference) and (unit_reference_id is not None)),
            "unit_reference_id and no_unit_reference parameters incoherence!")

        query_list = []

        if no_unit_reference:
            query_list.append(
                current.db.stock_store_location.unit_reference == None)
        elif unit_reference_id is not None:
            query_list.append(current.db.stock_store_location.unit_reference ==
                              unit_reference_id)
        else:
            query_list.append(current.db.stock_store_location.id > 0)

        final_query = ((current.db.stock_store_location.store_location
                        == store_location_id) &
                       (current.db.stock_store_location.product == product_id))

        # building the final query
        for query in query_list:
            my_logger.debug(message='query:%s' % str(query))
            final_query = final_query.__and__(query)

        return current.db(final_query).count() > 0

    def save(self, stock_store_location):
        _unit_reference_id = stock_store_location.unit_reference.id \
                            if stock_store_location.unit_reference is not None \
                            else None
        current.db.stock_store_location.insert(
            volume_weight_total=stock_store_location.volume_weight_total,
            volume_weight_actual=stock_store_location.volume_weight_actual,
            unit_reference=_unit_reference_id,
            store_location=stock_store_location.store_location.id,
            product=stock_store_location.product.id)

        current.db.commit()

    def update(self, stock_store_location):
        _unit_reference_id = stock_store_location.unit_reference.id \
                            if stock_store_location.unit_reference is not None \
                            else None
        current.db(
            current.db.stock_store_location.id ==
            stock_store_location.id).update(
                volume_weight_total=stock_store_location.volume_weight_total,
                volume_weight_actual=stock_store_location.volume_weight_actual,
                unit_reference=_unit_reference_id,
                store_location=stock_store_location.store_location.id,
                product=stock_store_location.product.id)

        current.db.commit()
コード例 #11
0
def build_menu():

    _response_menu = []

    if auth.user:
        _quick_request_menu = []

        _quick_request_menu.append((cc.get_string("MENU_ALL_PC"),
                                    False,
                                    URL(request.application, 'product', 'search.html',
                                    vars={'request': 'all'}),
                                    ))

        if auth.has_permission('select_sc') or \
           auth.has_permission('admin'):
            _quick_request_menu.append((cc.get_string("MENU_PC_BORROW_ENTITY"),
                                        False,
                                        URL(request.application, 'product', 'search.html',
                                        vars={'borrow_entity': '1'}),
                                        ))

        if auth.has_permission('select_sc') or \
           auth.has_permission('admin'):
            _quick_request_menu.append((cc.get_string("MENU_PC_ORG"),
                                        False,
                                        URL(request.application, 'product', 'search.html',
                                        vars={'request': 'organization'}),
                                        ))

        if auth.has_permission('select_sc') or \
           auth.has_permission('admin'):

            for _entity in ENTITY_MAPPER().find(person_id=auth.user.id):

                if _entity.name != 'all_entity':

                    _quick_request_sub_menu = []

                    if auth.has_permission('read_sc') or \
                       auth.has_permission('admin'):

                        for _store_location in STORE_LOCATION_MAPPER().find(entity_id=_entity.id, root=True):

                            if  _store_location.can_store:

                                _quick_request_sub_menu.append((_store_location.name,
                                                                False,
                                                                URL(current.request.application,'product','search.html',
                                                                    vars={'request': 'store_location',
                                                                          'is_in_store_location': _store_location.id,
                                                                          'not_archive': 'True'}),
                                                                get_store_location_submenu(_store_location.id)))
                            else:
                                 _quick_request_sub_menu.append((SPAN(_store_location.name, _class="can_not_store"),
                                                                False,
                                                                None,
                                                                get_store_location_submenu(_store_location.id)))

                    _quick_request_menu.append((_entity.name,
                                               False,
                                               URL(request.application,'product','search.html',
                                                   vars={'request': 'entity',
                                                          'is_in_entity': _entity.id,
                                                          'not_archive': 'True'}),
                                                _quick_request_sub_menu
                                                ))


#     _response_menu = [
#         (cc.get_string("INDEX"), False, URL(request.application,'default','index.html'), []),
#         ]

    if auth.user:

        _tools_menu = []
        if auth.has_permission('read_user') or \
           auth.has_permission('update_sl') or \
           auth.has_permission('update_ent') or \
           auth.has_permission('admin'):
            _tools_menu.append((cc.get_string("MENU_MANAGE_USER"), False, URL(request.application,'entity','search.html')))

        if auth.has_permission('update_coc') or \
           auth.has_permission('admin'):
            _tools_menu.append((cc.get_string("MENU_MANAGE_COC"), False, URL(request.application,'class_of_compounds','list.html')))
            _tools_menu.append((cc.get_string("MENU_MANAGE_PHYSICAL_STATE"), False, URL(request.application,'physical_state','list.html')))

        if auth.has_permission('update_sup') or \
           auth.has_permission('admin'):
            _tools_menu.append((cc.get_string("MENU_MANAGE_SUP"), False, URL(request.application,'supplier','list.html')))

        if auth.has_permission('admin'):
            _tools_menu.append((cc.get_string("ADMIN_TOOL_EXPORT_PRODUCT_DATABASE"),
                                      False,
                                      A(cc.get_string("ADMIN_TOOL_EXPORT_PRODUCT_DATABASE"),
                                        _class='noblockui',
                                        _href=URL(a=request.application, c='product', f='export_to_csv'),
                                        _onclick="displayConsole()")))
            _tools_menu.append((cc.get_string("ADMIN_TOOL_IMPORT_PRODUCT_DATABASE"),
                                      False,
                                      URL(a=request.application, c='product', f='import_from_csv')))

        if auth.has_permission('read_pc') or \
           auth.has_permission('admin'):
            _response_menu.append((cc.get_string("MENU_SEARCH_PC"), False, URL(request.application,'product','search.html'), _quick_request_menu))

        if auth.has_permission('create_pc') or \
           auth.has_permission('admin'):
            _response_menu.append((cc.get_string("MENU_ADD_PC"), False, URL(request.application,'product','create.html'), []))

        if auth.has_permission('read_com') or \
           auth.has_permission('admin'):
            _com_menu = []
            _com_menu.append((cc.get_string("MENU_LIST_COM_MINE"), False, URL(request.application,'command','list.html', vars={'request': 'mine'})))
            _com_menu.append((cc.get_string("MENU_LIST_COM_NEW"), False, URL(request.application,'command','list.html', vars={'request': 'new'})))
            _com_menu.append((cc.get_string("MENU_LIST_COM_ACCEPTED"), False, URL(request.application,'command','list.html', vars={'request': 'accepted'})))
            _com_menu.append((cc.get_string("MENU_LIST_COM_ALL"), False, URL(request.application,'command','list.html', vars={'request': 'all'})))
            _response_menu.append((cc.get_string("MENU_LIST_COM"), False, URL(request.application,'command','list.html'), _com_menu))

        if auth.has_permission('read_user') or \
           auth.has_permission('update_sl') or \
           auth.has_permission('update_ent') or \
           auth.has_permission('update_coc') or \
           auth.has_permission('update_sup') or \
           auth.has_permission('delete_archive') or \
           auth.has_permission('admin'):
           _response_menu.append((cc.get_string("MENU_ADMIN"),
                                  False,
                                  URL(request.application,'tools','list.html'),
                                  _tools_menu))

        _response_menu.append((cc.get_string("MESSAGE"), False, URL(request.application,'message','index.html', [])))

#     _response_menu.append(('test', False, A('test',
#                                             _class='noblockui',
#                                             _href=URL(a=request.application, c='test', f='index.html'),
#                                             _onclick="displayConsole()"), []))

        _response_menu.append((cc.get_string("MENU_EXPOSURE_CARD"),
                               False,
                               URL(request.application,
                                   'exposure_card',
                                   'list.html'),
                               []))

    return _response_menu