-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloanmanagement.py
81 lines (67 loc) · 2.52 KB
/
loanmanagement.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import logging
from django.core.validators import MinValueValidator
from django.http import HttpResponse, JsonResponse
from django.urls import include, re_path, path
from django.utils.translation import gettext_lazy as _
from django.shortcuts import render
from django.views.generic import RedirectView
from plugin import InvenTreePlugin
from stock.models import StockItem
from plugin.mixins import AppMixin, NavigationMixin, SettingsMixin, UrlsMixin, ActionMixin, PanelMixin
from stock.views import StockItemDetail
class LoaningManagementPlugin(AppMixin, ActionMixin, SettingsMixin, UrlsMixin, NavigationMixin, PanelMixin,
InvenTreePlugin):
"""
Adds loaning management functionality to InvenTree.
"""
# Plugin Metadata
NAME = "Loan Management"
SLUG = "loan"
TITLE = "Loan Management"
DESCRIPTION = "A plugin to manage loaning and tracking stock items."
VERSION = "0.0.1"
AUTHOR = "Joshua Miller, Kyle Wilt @ RPI"
# Navigation
NAVIGATION_TAB_NAME = "Loan"
NAVIGATION_TAB_ICON = 'fas fa-handshake'
NAVIGATION = [
{
'name': 'Loan Tracking',
'link': 'plugin:loan:tracking',
'icon': 'fas fa-clock'
},
]
# Settings
SETTINGS = {
'DEFAULT_LOAN_DURATION_DAYS': {
'name': _('Default Loan Duration'), # TODO Rewrite
'description': "The default duration an item will be loaned for in days.", # TODO Rewrite
'default': 28,
'validator': [
int,
MinValueValidator(0)
]
},
}
# Custom Panels
STOCK_ITEM_LOAN_PANEL_TITLE = "Loaning"
def get_custom_panels(self, view, request):
panels = []
# Stock Item Loaning information panel
if isinstance(view, StockItemDetail):
panels.append({
"title": LoaningManagementPlugin.STOCK_ITEM_LOAN_PANEL_TITLE,
"icon": "fas fa-handshake",
"content_template": "loaning_stats_panel.html",
"javascript_template": "js/track.js",
})
return panels
# URL Patterns for the plugin
def setup_urls(self):
from .urls import api_patterns
from .views import LoanItemDetail, LoanTrackingDetail
return [
re_path(r'^api/', include(api_patterns), name="api"),
re_path(r'^tracking/', LoanTrackingDetail.as_view(), name='tracking'),
re_path(r'^', LoanTrackingDetail.as_view(), name='tracking')
]