forked from sahana/eden
-
Notifications
You must be signed in to change notification settings - Fork 0
/
supply.py
127 lines (95 loc) · 4.14 KB
/
supply.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# -*- coding: utf-8 -*-
"""
Supply
Generic Supply functionality such as catalogs and items that are used across multiple applications
"""
module = request.controller
resourcename = request.function
if not (deployment_settings.has_module("inv") or deployment_settings.has_module("asset")):
raise HTTP(404, body="Module disabled: %s" % module)
# =============================================================================
def index():
"""
Application Home page
"""
module_name = deployment_settings.modules[module].name_nice
response.title = module_name
return dict(module_name=module_name)
# -----------------------------------------------------------------------------
def catalog():
""" RESTful CRUD controller """
return s3_rest_controller(rheader=catalog_rheader)
# -----------------------------------------------------------------------------
def catalog_rheader(r):
""" Resource Header for Catalogs """
if r.representation == "html":
catalog = r.record
if catalog:
tabs = [
(T("Edit Details"), None),
(T("Categories"), "item_category"),
(T("Items"), "catalog_item"),
]
rheader_tabs = s3_rheader_tabs(r, tabs)
table = r.table
rheader = DIV(TABLE(TR( TH("%s: " % table.name.label),
catalog.name,
),
TR( TH("%s: " % table.organisation_id.label),
table.organisation_id.represent(catalog.organisation_id),
),
),
rheader_tabs
)
return rheader
return None
# =============================================================================
def item_category():
""" RESTful CRUD controller """
return s3_rest_controller()
# -----------------------------------------------------------------------------
def item_pack():
""" RESTful CRUD controller """
tablename = "%s_%s" % (module, resourcename)
s3mgr.configure(tablename,
listadd=False)
return s3_rest_controller()
# -----------------------------------------------------------------------------
def brand():
""" RESTful CRUD controller """
return s3_rest_controller()
# =============================================================================
def item():
""" RESTful CRUD controller """
supply_item_table = s3db.supply_item #kit field
def prep(r):
if r.component and r.component.name == "inv_item":
inv_item_pack_requires = IS_ONE_OF(db,
"supply_item_pack.id",
s3db.supply_item_pack_represent,
sort=True,
filterby = "item_id",
filter_opts = [r.record.id],
)
s3db.inv_inv_item.item_pack_id.requires = inv_item_pack_requires
return True
response.s3.prep = prep
# Sort Alphabetically for the AJAX-pulled dropdown
s3mgr.configure("supply_item",
orderby=s3db.supply_item.name)
# Defined in the Model for use from Multiple Controllers for unified menus
return s3db.supply_item_controller()
# -----------------------------------------------------------------------------
def kit_item():
""" RESTful CRUD controller """
return s3_rest_controller()
# =============================================================================
def catalog_item():
""" RESTful CRUD controller """
return s3_rest_controller()
# =============================================================================
def item_entity():
""" RESTful CRUD controller """
# Defined in the Model for use from Multiple Controllers for unified menus
return s3db.supply_item_entity_controller()
# END =========================================================================