def update(): storage_id = request.args[0] _storage = STORAGE_MAPPER().find(storage_id)[0] # creating the form db.storage.product.widget.attributes['_disabled'] = 'disabled' form = crud.update( db.storage, storage_id, next=URL(request.application, 'product', 'details_reload', args=_storage.product.id, vars={'load_storage_list': True}), onvalidation=lambda theform: (update_storage_person(theform), save_storage_store_location(theform)), onaccept=lambda theform: (auth.archive( theform, archive_table=db.storage_history, archive_current=False), ), ondelete=lambda theform: (auth.archive( theform, archive_table=db.storage_history, archive_current=False))) if form.errors: session.flash = DIV(cc.get_string("MISSING_FIELDS"), _class="flasherror") cache.ram.clear(regex='.*/storage/list') cache.ram.clear(regex='.*/product/details') return dict(storage_id=storage_id, product_id=_storage.product.id, form=form)
def list_history(): storage_id = request.args(0) storages = STORAGE_MAPPER().find(storage_id=storage_id, history=True) return dict(storages=storages)
def create(): my_logger.debug(message='request.vars:%s' % request.vars) product_id = request.args(0) db.storage.product.default = product_id db.storage.barecode.default = STORAGE_MAPPER.create_barecode(product_id) # creating the form db.storage.product.widget.attributes['_disabled'] = 'disabled' form = crud.create( db.storage, next=URL(request.application, 'product', 'details_reload', args=product_id, vars={'load_storage_list': True}), onvalidation=lambda form: clean_unit(form), # onvalidation=lambda form: (clean_unit(form), # generate_barecode(form)), onaccept=lambda form: (duplicate_storage(form), create_stock(form))) if form.errors: session.flash = DIV(cc.get_string("MISSING_FIELDS"), _class="flasherror") cache.ram.clear(regex='.*/storage/list') cache.ram.clear(regex='.*/product/details') return dict(product_id=product_id, form=form)
def label(): storage_id = request.args(0) storage = STORAGE_MAPPER().find(storage_id=storage_id, archive=None)[0] return dict(storage=storage)
def detail(): history = 'history' in request.vars archive = 'archive' in request.vars and request.vars['archive'] my_logger.debug(message='history:%s' % history) my_logger.debug(message='archive:%s' % archive) _id = request.args(0) if history: storage = STORAGE_MAPPER().find(storage_history_id=_id, history=history)[0] else: storage = STORAGE_MAPPER().find(storage_id=_id, archive=archive)[0] return dict(storage=storage, is_history=history, is_archive=archive)
def undestroy(): storage_id = request.args[0] my_logger.debug(message='storage_id:%s' % storage_id) storage_mapper = STORAGE_MAPPER() _storage = storage_mapper.find(storage_id=storage_id)[0] _storage.to_destroy = False _storage.exit_datetime = None STORAGE_MAPPER().update(_storage) cache.ram.clear(regex='.*/storage/list') # in case of error, return json.dumps({'error': 'Error message'}) return json.dumps({'success': True})
def list_archive(): product_id = request.args(0) current_user_entities = [ _entity.id for _entity in ENTITY_MAPPER().find(person_id=auth.user.id) ] my_logger.debug(message='user_entities:%s' % current_user_entities) storages = STORAGE_MAPPER().find(entity_id=current_user_entities, product_id=product_id, archive=True) request.vars['archive'] = True return dict(storages=storages, product_id=product_id)
def create(): storage_id = request.args[0] db.borrow.storage.default = storage_id db.borrow.borrower.default = auth.user.id _storage = STORAGE_MAPPER().find(storage_id=storage_id)[0] form = crud.create(db.borrow, next=URL(request.application, 'product', 'details_reload', args=_storage.product.id, vars={'load_storage_list': True})) cache.ram.clear(regex='.*/storage/list') return dict(storage_id=storage_id, form=form)
def delete(): storage_id = request.args[0] my_logger.debug(message='storage_id:%s' % storage_id) storage_mapper = STORAGE_MAPPER() _storage = storage_mapper.find(storage_id=storage_id, archive=None)[0] if _storage.archive: my_logger.debug(message='storage is archive') storage_mapper.delete(_storage) else: my_logger.debug(message='storage is NOT archive') _storage.archive = True _storage.to_destroy = False _storage.exit_datetime = datetime.now() storage_mapper.update(_storage) # un-borrow the storage if needed db(db.borrow.storage == storage_id).delete() # updating the STOCK # if there's no more active storage for this product and this entity, delete the stock product_id = _storage.product.id entity_id = _storage.store_location.entity.id nb_remain_storage = db( (db.product.id == product_id) & (db.storage.product == db.product.id) & (db.storage.archive == False) & (db.storage.store_location == db.store_location.id) & (db.store_location.entity == entity_id)).count() if nb_remain_storage == 0: db((db.stock.product == product_id) & (db.stock.entity == entity_id)).delete() #update_stock(None, storage=_storage, delete=True) request.vars['storage'] = storage_id cache.ram.clear(regex='.*/storage/list') cache.ram.clear(regex='.*/product/details') return storage_id
def list(): my_logger.debug(message='request.vars:%s' % request.vars) product_id = request.args[0] if len( request.args) > 0 else request.vars['product_id'] my_logger.debug(message='product_id:%s' % product_id) if product_id is None: return 'foo' current_user_entities = [ _entity.id for _entity in ENTITY_MAPPER().find(person_id=auth.user.id) ] my_logger.debug(message='user_entities:%s' % current_user_entities) storages = STORAGE_MAPPER().find(product_id=product_id, entity_id=current_user_entities) d = dict(storages=storages, product_id=product_id) return response.render(d)
def generate_barecode(form): my_logger.debug(message='generate_barecode') product_id = form.element('[name=product]').attributes['_value'] form.vars.barecode = STORAGE_MAPPER.create_barecode(product_id)
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()