예제 #1
0
 def update(article):
     if location_id:
         location = queries.user_location(session, user, location_id).one()
         if location.warehouse_id != article.warehouse_id:
             raise Exception("wrong_location_id")
     db_tags = queries.get_tags_from_ids(session, user, article.warehouse_id, tags)
     if db_tags == None:
         raise Exception("invalid_tag_ids")
     return {"location_id": location_id, "quantity": quantity, "expiry": expiry, "tags": db_tags}
예제 #2
0
def update_location(session: helpers.extend.session, user: hug.directives.user,
                    response, id: int, name):
    """Updates a location"""
    if len(name) == 0:
        return helpers.response.error("location_name_mandatory",
                                      falcon.HTTP_400)
    return helpers.update(
        "location", session,
        queries.with_editor_role(queries.user_location(session, user, id)),
        {"name": name})
예제 #3
0
def create_article(session: helpers.extend.session, user: hug.directives.user, response, warehouse_id: int, reference_id: int, quantity: int, expiry: fields.Date(allow_none=True)=None, location_id: fields.Int(allow_none=True)=None, tags=None):
    """Creates a article"""
    db_tags = queries.get_tags_from_ids(session, user, warehouse_id, tags)
    if db_tags == None:
        return response.error("invalid_tag_ids", falcon.HTTP_400)
    try:
        warehouse = queries.with_editor_role(queries.user_warehouse(session, user, warehouse_id)).one()
        location = queries.with_editor_role(queries.user_location(session, user, location_id)).one() if location_id else None
        reference = queries.with_editor_role(queries.user_reference(session, user, reference_id)).one()
        if warehouse.id != reference.warehouse.id or (location is not None and warehouse.id != location.warehouse.id):
            return helpers.response.error("bad_referenece_and_or_location", falcon.HTTP_400)
        article = Article(warehouse=warehouse, location=location, reference=reference, quantity=quantity, expiry=expiry, tags=db_tags)
        return article
    except NoResultFound:
        return helpers.response.error("warehouse_location_or_reference_not_found", falcon.HTTP_401)
예제 #4
0
def delete_location(session: helpers.extend.session, user: hug.directives.user,
                    response, id: int):
    """Deletes a location"""
    return helpers.delete(
        "location", session,
        queries.with_editor_role(queries.user_location(session, user, id)))
예제 #5
0
def get_location(session: helpers.extend.session, user: hug.directives.user,
                 response, id: int):
    """Gets a location"""
    return helpers.get(
        "location", session,
        queries.with_viewer_role(queries.user_location(session, user, id)))