Esempio n. 1
0
def inventory_update_view():
    if login.current_user.is_anonymous():
        abort()
    # 1 = checkin, 2 = checkout
    status = int(request.form["status"])
    checkout_meta = None
    # provide meta
    if status == InventoryItem.CHECKED_OUT:  # checkout
        dtype = int(request.form["duration_type"])
        duration = request.form["duration"]
        try:
            duration = int(duration)
            # enforce duration limit
            if duration > 999:
                duration = 999
        except ValueError:
            duration = 0
        checkout_meta = CheckoutMeta(
            duration=duration, duration_type=dtype, is_ooo=(True if int(request.form.get("ooo", 0)) else False)
        )
    person = Person.objects(id=request.form["personid"]).get()
    item = InventoryItem.objects(id=request.form["itemid"]).get()
    # add a log
    log = InventoryLog.add_log(
        person=person, item=item, status=int(request.form["status"]), checkout_meta=checkout_meta
    )
    # update the item status
    item.status = status
    item.save()
    response = {
        "duration": {"dateAdded": log.get_date_added(), "description": log.get_checkout_description()},
        "person": {"name": log.person.name},
    }
    return json.dumps(response)
Esempio n. 2
0
 def delete_model(self, model):
     """Delete the person record and checks IN any items checked out by
     them (inserts assoc. logs)
     """
     item_names = []
     flash('Removed %s' % model.name)
     # check in the inventory they had
     logs = InventoryLog.objects(person=model,
                                 status=InventoryItem.CHECKED_OUT)
     for log in logs:
         item = log.item
         # check in items
         InventoryLog.add_log(person=model,
                              item=item,
                              status=InventoryItem.CHECKED_IN,
                              checkout_meta=None,
                              person_name=model.name + ' - DELETED')
         item.status = InventoryItem.CHECKED_IN
         item.save()
         item_names.append(item.name)
     if item_names:
         flash('> > Checked IN %s' % u', '.join(item_names),
               category='misc')
     return super(PersonAdmin, self).delete_model(model)
Esempio n. 3
0
 def delete_model(self, model):
     """Delete the person record and checks IN any items checked out by
     them (inserts assoc. logs)
     """
     item_names = []
     flash('Removed %s' % model.name)
     # check in the inventory they had
     logs = InventoryLog.objects(person=model, status=InventoryItem.CHECKED_OUT)
     for log in logs:
         item = log.item
         # check in items
         InventoryLog.add_log(
             person=model,
             item=item,
             status=InventoryItem.CHECKED_IN,
             checkout_meta=None,
             person_name=model.name + ' - DELETED'
         )
         item.status = InventoryItem.CHECKED_IN
         item.save()
         item_names.append(item.name)
     if item_names:
         flash('> > Checked IN %s' % u', '.join(item_names), category='misc')
     return super(PersonAdmin, self).delete_model(model)
Esempio n. 4
0
def CreateLog(user, LogContent):
    newLog = InventoryLog(user=user, content=LogContent)
    newLog.save()
    return