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 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