Inventory
This module provides tools to help users view and manage LNL’s equipment inventory.
Models
- class inventory.models.EquipmentCategory(id, name, usual_place, parent)[source]
- Parameters:
id (AutoField) – Id (required)
name (CharField) – Name (required)
usual_place (ForeignKey to
Location) – Default place for items of this category. Inherits from parent categories.parent (TreeForeignKey to
EquipmentCategory) – If this is a subcategory, the parent is what this is a subcategory of. Choose ‘—’ if not.lft (PositiveIntegerField) – Lft (required)
rght (PositiveIntegerField) – Rght (required)
tree_id (PositiveIntegerField) – Tree id (required)
level (PositiveIntegerField) – Level (required)
- exception DoesNotExist
- exception MultipleObjectsReturned
- breadcrumbs
- default_location
- get_ancestors_inclusive
- get_descendants_inclusive
- id
AutoField(verbose_name=”ID”, primary_key=True, serialize=False, auto_created=True)
- level
PositiveIntegerField(editable=False)
- lft
PositiveIntegerField(editable=False)
- name
CharField(max_length=64)
- parent
TreeForeignKey(blank=True, null=True, help_text=”If this is a subcategory, the parent is what this is a subcategory of. Choose ‘—’ if not.”, related_name=”children”, on_delete=CASCADE(), to=
EquipmentCategory)Parent: If this is a subcategory, the parent is what this is a subcategory of. Choose ‘—’ if not.
- rght
PositiveIntegerField(editable=False)
- tree_id
PositiveIntegerField(db_index=True, editable=False)
- usual_place
ForeignKey(blank=True, null=True, help_text=”Default place for items of this category. Inherits from parent categories.”, on_delete=PROTECT(), to=
Location)Usual place: Default place for items of this category. Inherits from parent categories.
- usual_place_id
Raw (integer) FK for
usual_place
- class inventory.models.EquipmentClass(id, name, category, description, value, model_number, manufacturer, url, holds_items, length, width, height, weight, wiki_text)[source]
- Parameters:
id (AutoField) – Id (required)
name (CharField) – Name (required)
category (TreeForeignKey to
EquipmentCategory) – Category (required)description (TextField) – Function, appearance, and included acessories
value (DecimalField) – Estimated purchase value
model_number (CharField) – Model number
manufacturer (CharField) – Manufacturer
url (URLField) – Url
holds_items (BooleanField) – Can hold other items (default=False)
length (DecimalField) – Length in inches
width (DecimalField) – Width in inches
height (DecimalField) – Height in inches
weight (DecimalField) – Weight in lbs.
wiki_text (TextField) – How to use this item
- exception DoesNotExist
- exception MultipleObjectsReturned
- breadcrumbs
- category
TreeForeignKey(on_delete=CASCADE(), to=
EquipmentCategory)
- description
TextField(blank=True, null=True, help_text=”Function, appearance, and included acessories”)
Description: Function, appearance, and included acessories
- height
DecimalField(blank=True, null=True, help_text=”Height in inches”, max_digits=6, decimal_places=2)
Height: Height in inches
- holds_items
BooleanField(default=False, help_text=”Can hold other items”)
Holds items: Can hold other items
- id
AutoField(verbose_name=”ID”, primary_key=True, serialize=False, auto_created=True)
- length
DecimalField(blank=True, null=True, help_text=”Length in inches”, max_digits=6, decimal_places=2)
Length: Length in inches
- manufacturer
CharField(max_length=128, blank=True, null=True)
- model_number
CharField(max_length=190, blank=True, null=True)
- name
CharField(max_length=190)
- objects = <django.db.models.manager.Manager object>
- url
CharField(blank=True, null=True)
- value
DecimalField(blank=True, null=True, help_text=”Estimated purchase value”, max_digits=9, decimal_places=2)
Value: Estimated purchase value
- weight
DecimalField(blank=True, null=True, help_text=”Weight in lbs.”, max_digits=6, decimal_places=2)
Weight: Weight in lbs.
- width
DecimalField(blank=True, null=True, help_text=”Width in inches”, max_digits=6, decimal_places=2)
Width: Width in inches
- wiki_text
TextField(blank=True, null=True, help_text=”How to use this item”)
Wiki text: How to use this item
- class inventory.models.EquipmentItem(id, item_type, serial_number, case, barcode, purchase_date, home, features)[source]
- Parameters:
id (AutoField) – Id (required)
item_type (ForeignKey to
EquipmentClass) – Item type (required)serial_number (CharField) – Serial number
case (TreeForeignKey to
EquipmentItem) – Case or item that contains this itembarcode (BigIntegerField) – Barcode
purchase_date (DateField) – Purchase date (required)
home (ForeignKey to
Location) – Place where this item typically resides.features (CharField) – Identifying features
lft (PositiveIntegerField) – Lft (required)
rght (PositiveIntegerField) – Rght (required)
tree_id (PositiveIntegerField) – Tree id (required)
level (PositiveIntegerField) – Level (required)
- exception DoesNotExist
- exception MultipleObjectsReturned
- barcode
BigIntegerField(unique=True, blank=True, null=True)
- breadcrumbs
- case
TreeForeignKey(blank=True, null=True, help_text=”Case or item that contains this item”, related_name=”contents”, on_delete=CASCADE(), to=
EquipmentItem)Case: Case or item that contains this item
- features
CharField(verbose_name=”Identifying Features”, max_length=128, blank=True, null=True)
- get_next_by_purchase_date(*, field=<django.db.models.fields.DateField: purchase_date>, is_next=True, **kwargs)
- get_previous_by_purchase_date(*, field=<django.db.models.fields.DateField: purchase_date>, is_next=False, **kwargs)
- home
ForeignKey(blank=True, null=True, help_text=”Place where this item typically resides.”, on_delete=PROTECT(), to=
Location)Home: Place where this item typically resides.
- id
AutoField(verbose_name=”ID”, primary_key=True, serialize=False, auto_created=True)
- item_type
ForeignKey(related_name=”items”, on_delete=CASCADE(), to=
EquipmentClass)
- level
PositiveIntegerField(editable=False)
- lft
PositiveIntegerField(editable=False)
- property location
- objects = <inventory.models.EquipmentItemManager object>
- purchase_date
DateField(blank=True)
- rght
PositiveIntegerField(editable=False)
- save(*args, **kwargs)[source]
If this is a new node, sets tree fields up before it is inserted into the database, making room in the tree structure as necessary, defaulting to making the new node the last child of its parent.
It the node’s left and right edge indicators already been set, we take this as indication that the node has already been set up for insertion, so its tree fields are left untouched.
If this is an existing node and its parent has been changed, performs reparenting in the tree structure, defaulting to making the node the last child of its new parent.
In either case, if the node’s class has its
order_insertion_bytree option set, the node will be inserted or moved to the appropriate position to maintain ordering by the specified field.
- serial_number
CharField(max_length=190, blank=True, null=True)
- status
- tree_id
PositiveIntegerField(db_index=True, editable=False)
- unsafe_to_delete
- class inventory.models.EquipmentMaintEntry(id, date, user, title, entry, equipment, status)[source]
- Parameters:
id (AutoField) – Id (required)
date (DateTimeField) – Date (required)
user (ForeignKey to
User) – User (required)title (CharField) – Title (required)
entry (TextField) – Entry
equipment (ForeignKey to
EquipmentItem) – Equipment (required)status (ForeignKey to
EquipmentStatus) – Status (required)
- exception DoesNotExist
- exception MultipleObjectsReturned
- date
DateTimeField(auto_now_add=True)
- entry
TextField(blank=True, null=True)
- equipment
ForeignKey(related_name=”maintenance”, on_delete=CASCADE(), to=
EquipmentItem)
- get_next_by_date(*, field=<django.db.models.fields.DateTimeField: date>, is_next=True, **kwargs)
- get_previous_by_date(*, field=<django.db.models.fields.DateTimeField: date>, is_next=False, **kwargs)
- id
AutoField(verbose_name=”ID”, primary_key=True, serialize=False, auto_created=True)
- objects = <django.db.models.manager.Manager object>
- status
ForeignKey(on_delete=PROTECT(), to=
EquipmentStatus)
- title
CharField(max_length=32)
- class inventory.models.EquipmentStatus(id, name, glyphicon)[source]
- Parameters:
id (AutoField) – Id (required)
name (CharField) – Name (required)
glyphicon (CharField) – Glyphicon (required)
- exception DoesNotExist
- exception MultipleObjectsReturned
- glyphicon
CharField(max_length=32)
- id
AutoField(verbose_name=”ID”, primary_key=True, serialize=False, auto_created=True)
- name
CharField(max_length=32)
- objects = <django.db.models.manager.Manager object>
Views
- inventory.views.cat(request, category_id)[source]
List items by category
- Parameters:
category_id – The primary key value of the equipment category
- inventory.views.generate_receipt(request, data, renter, checkin=False)[source]
Generate a checkin or checkout receipt
- Parameters:
data – List of dictionaries containing the metadata for each of the items that were just checked in or out
renter – The name of the user or organization the items were rented to
checkin – Set to True if generating a receipt for checkin
- Returns:
Itemized list of item details and the total rental price
- inventory.views.old_snipe_checkin(request)[source]
Equipment inventory checkin form. Communicates with Snipe via their API.
- inventory.views.old_snipe_checkout(request)[source]
Equipment inventory checkout form. Communicates with Snipe via their API.
- inventory.views.remove_saved_tag(post_data, tag)[source]
Removes an item from the list of pending assets and/or accessories stored in a Snipe Checkin or Checkout form.
- Parameters:
post_data – The request’s POST data
tag – The asset tag value of the item to remove
- Returns:
The updated form data and list of item metadata dictionaries
- inventory.views.retrieve_saved_tags(post_data)[source]
Converts the asset tag data stored in a form into a list of dictionaries.
- Parameters:
post_data – The request’s POST data
- Returns:
A list of dictionaries containing the metadata for the selected assets and/or accessories
- inventory.views.snipe_checkin(request)[source]
Equipment inventory checkin form. Communicates with Snipe via their API.
- inventory.views.snipe_checkout(request)[source]
Equipment inventory checkout form. Communicates with the Snipe API.
- inventory.views.snipe_credentials(request)[source]
Display the login credentials for the general Snipe account
- inventory.views.update_tag_list(post_data, new_item)[source]
Adds a new item to the list of asset tags stored in hidden fields on the Snipe Checkin and Checkout forms and returns an additional dictionary containing basic information for each verified item.
- Parameters:
post_data – The request’s POST data
new_item – The next asset or accessory to add to the list
- Returns:
Updated form data and basic inventory item information (Dictionary and list of Dictionaries)
Forms
- class inventory.forms.SnipeCheckinForm(checkin_from_choices, *args, **kwargs)[source]
- base_fields = {'asset_tags': <django.forms.fields.CharField object>}
- declared_fields = {'asset_tags': <django.forms.fields.CharField object>}
- property media
Return all media required to render the widgets on this form.
- class inventory.forms.SnipeCheckoutForm(checkout_to_choices, *args, **kwargs)[source]
- base_fields = {'asset_tags': <django.forms.fields.CharField object>}
- declared_fields = {'asset_tags': <django.forms.fields.CharField object>}
- property media
Return all media required to render the widgets on this form.
- class inventory.forms.SnipeRentalForm(rental_clients, checkout, *args, **kwargs)[source]
- base_fields = {'asset_tag': <django.forms.fields.CharField object>, 'saved_tags': <django.forms.fields.CharField object>}
- declared_fields = {'asset_tag': <django.forms.fields.CharField object>, 'saved_tags': <django.forms.fields.CharField object>}
- property media
Return all media required to render the widgets on this form.
API Methods
- inventory.api.api_request(method, endpoint, data=None)[source]
Send an API request to Snipe
- Parameters:
method – GET, POST, PUT, PATCH or DELETE
endpoint – Snipe endpoint (Must start with / - i.e. /users or /accessories/1)
data – JSON data (if applicable)
- Returns:
Response
- inventory.api.checkedout(tag)[source]
Determine which users a specific accessory has been checked out to
- Parameters:
tag – The item’s asset tag number (String)
- Returns:
List of active rentals for the specified item(s)
- inventory.api.checkin(identifier, accessory=False)[source]
Check in an asset or accessory from a user
- Parameters:
identifier – For accessories, use the ID of the accessory+user relationship. For assets, use its Snipe ID.
accessory – Must be true if the item is an accessory
- Returns:
API Response
- inventory.api.checkout(item_id, renter_id, accessory=False)[source]
Check an asset or accessory out to a user
- Parameters:
item_id – The item’s Snipe ID number
renter_id – The Snipe ID number for the user checking out the item
accessory – Must be True if the item is an accessory
- Returns:
API Response