forked from ptressel/ssf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreq.py
289 lines (273 loc) · 12.3 KB
/
req.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# -*- coding: utf-8 -*-
"""
Request Management
A module to record requests & commitments for:
- inventory items
- people (actually request skills, but commit people)
- assets
- other
@ToDo: Link to Tasks via link table (optional way of working)
"""
req_item_inv_item_btn = dict(url = URL(c = "req",
f = "req_item_inv_item",
args = ["[id]"]
),
_class = "action-btn",
label = str(T("Request from Facility")), # Change to Fulfil? Match?
)
# -----------------------------------------------------------------------------
# Defined in the Model for use from Multiple Controllers for unified menus
#
def req_controller():
"""
Request Controller
"""
#
# req_table = s3db.req_req
#
# # Set the req_item site_id (Requested From), called from action buttons on req/req_item_inv_item/x page
# if "req_item_id" in request.vars and "inv_item_id" in request.vars:
# inv_item = s3db.inv_inv_item[request.vars.inv_item_id]
# site_id = inv_item.site_id
# item_id = inv_item.item_id
# s3db.req_req_item[request.vars.req_item_id] = dict(site_id = site_id)
# response.confirmation = T("%(item)s requested from %(site)s" % {"item":s3db.supply_item_represent(item_id, show_link = False),
# "site":s3db.org_site_represent(site_id, link=False)
# })
#
# default_type = request.vars.default_type
# if default_type:
# type_field = req_table.type
# type_field.default = int(default_type)
# type_field.writable = False
#
# def prep(r):
#
# s3db.req_prep(r)
#
# # Remove type from list_fields
# list_fields = s3mgr.model.get_config("req_req",
# "list_fields")
# try:
# list_fields.remove("type")
# except:
# # It has already been removed.
# # This can happen if the req controller is called
# # for a second time, such as when printing reports
# pass
# s3mgr.configure("req_req", list_fields=list_fields)
#
# if r.interactive:
# # Set Fields and Labels depending on type
# type = ( r.record and r.record.type ) or \
# ( request.vars and request.vars.type )
# if type:
# type = int(type)
# req_table.type.default = int(type)
#
# # This prevents the type from being edited AFTER it is set
# req_table.type.readable = False
# req_table.type.writable = False
#
# crud_strings = deployment_settings.get_req_req_crud_strings(type)
# if crud_strings:
# s3.crud_strings["req_req"] = crud_strings
#
# # Filter the query based on type
# if response.s3.filter:
# response.s3.filter = response.s3.filter & \
# (s3db.req_req.type == type)
# else:
# response.s3.filter = (s3db.req_req.type == type)
#
# # @ToDo: apply these changes via JS for the create form where type is edittable
# if type == 1: # Item
# req_table.date_recv.readable = True
# req_table.date_recv.writable = True
# req_table.date_recv.readable = True
# req_table.date_recv.writable = True
#
# req_table.purpose.label = T("What the Items will be used for")
# req_table.site_id.label =T("Deliver To")
# req_table.request_for_id.label = T("Deliver To")
# req_table.recv_by_id.label = T("Delivered To")
#
# if type == 3: # Person
# req_table.date_required_until.readable = True
# req_table.date_required_until.writable = True
#
# req_table.purpose.label = T("Task Details")
# req_table.site_id.label = T("Report To")
# req_table.request_for_id.label = T("Report To")
# req_table.recv_by_id.label = T("Reported To")
#
# if r.method != "update" and r.method != "read":
# if not r.component:
# # Hide fields which don't make sense in a Create form
# # - includes one embedded in list_create
# # - list_fields over-rides, so still visible within list itself
# s3db.req_create_form_mods()
#
# # Get the default Facility for this user
# # @ToDo: Use site_id in User Profile (like current organisation_id)
# if deployment_settings.has_module("hrm"):
# hrtable = s3db.hrm_human_resource
# query = (hrtable.person_id == s3_logged_in_person())
# site = db(query).select(hrtable.site_id,
# limitby=(0, 1)).first()
# if site:
# r.table.site_id.default = site.site_id
#
# elif r.component.name == "document":
# s3.crud.submit_button = T("Add")
# table = r.component.table
# # @ToDo: Fix for Link Table
# #table.date.default = r.record.date
# #if r.record.site_id:
# # stable = db.org_site
# # query = (stable.id == r.record.site_id)
# # site = db(query).select(stable.location_id,
# # stable.organisation_id,
# # limitby=(0, 1)).first()
# # if site:
# # table.location_id.default = site.location_id
# # table.organisation_id.default = site.organisation_id
#
# elif r.component.name == "req_item":
# table = r.component.table
# table.site_id.writable = table.site_id.readable = False
# s3db.req_hide_quantities(table)
#
# elif r.component.name == "req_skill":
# s3db.req_hide_quantities(r.component.table)
#
# if r.component and r.component.name == "commit":
# table = r.component.table
# # Allow commitments to be added when doing so as a component
# s3mgr.configure(table,
# listadd = True)
#
# type = r.record.type
# if type == 1: # Items
# # Limit site_id to facilities the user has permissions for
# auth.permission.permitted_facilities(table=r.table,
# error_msg=T("You do not have permission for any facility to make a commitment."))
# if r.interactive:
# # Redirect to the Items tab after creation
# s3mgr.configure(table,
# create_next = URL(c="req", f="commit",
# args=["[id]", "commit_item"]),
# update_next = URL(c="req", f="commit",
# args=["[id]", "commit_item"]))
# else:
# # Non-Item commits can have an Organisation
# # Check if user is affiliated to an Organisation
# if is_affiliated():
# # Limit organisation_id to organisations the user has permissions for
# auth.permission.permitted_organisations(table=r.table,
# redirect_on_error=False)
# table.organisation_id.readable = True
# table.organisation_id.writable = True
# else:
# # Unaffiliated people can't commit on behalf of others
# r.component.table.committer_id.writable = False
# r.component.table.committer_id.comment = None
#
# # Non-Item commits shouldn't have a From Inventory
# # @ToDo: Assets do?
# table.site_id.readable = False
# table.site_id.writable = False
# if r.interactive and r.record.type == 3: # People
# # Redirect to the Persons tab after creation
# s3mgr.configure(table,
# create_next = URL(c="req", f="commit",
# args=["[id]", "commit_person"]),
# update_next = URL(c="req", f="commit",
# args=["[id]", "commit_person"]))
# else:
# # Limit site_id to facilities the user has permissions for
# # @ToDo: Non-Item requests shouldn't be bound to a Facility?
# auth.permission.permitted_facilities(table=r.table,
# error_msg=T("You do not have permission for any facility to make a request."))
#
# return True
# response.s3.prep = prep
#
# # Post-process
# def postp(r, output):
#
# if r.interactive:
# s3_action_buttons(r)
# if not r.component:
# if deployment_settings.get_req_use_commit():
# # This is appropriate to all
# response.s3.actions.append(
# dict(url = URL(c = "req",
# f = "req",
# args = ["[id]", "commit", "create"]),
# _class = "action-btn",
# label = str(T("Commit"))
# )
# )
# # This is only appropriate for item requests
# query = (r.table.type == 1)
# rows = db(query).select(r.table.id)
# restrict = [str(row.id) for row in rows]
# response.s3.actions.append(
# dict(url = URL(c = "req",
# f = "req",
# args = ["[id]", "req_item"]),
# _class = "action-btn",
# label = str(T("View Items")),
# restrict = restrict
# )
# )
# elif r.component.name == "req_item":
# response.s3.actions.append(req_item_inv_item_btn)
# elif r.component.name == "req_skill":
# pass
# else:
# # We don't yet have other components
# pass
#
# return output
# response.s3.postp = postp
#
# output = s3_rest_controller("req", "req",
# rheader=eden.req.req_rheader)
#
# return output
# ---------------------------------------------------------------------
def req_skill_controller():
"""
Request Skills Controller
"""
tablename = "req_req_skill"
table = s3db[tablename]
s3mgr.configure(tablename,
insertable=False)
def prep(r):
if r.interactive:
if r.method != "update" and r.method != "read":
# Hide fields which don't make sense in a Create form
# - includes one embedded in list_create
# - list_fields over-rides, so still visible within list itself
s3db.req_hide_quantities(r.table)
return True
response.s3.prep = prep
# Post-process
def postp(r, output):
if r.interactive:
response.s3.actions = [
dict(url = URL(c = "req",
f = "req",
args = ["req_skill", "[id]"]),
_class = "action-btn",
label = str(READ)
)
]
return output
response.s3.postp = postp
output = s3_rest_controller("req", "req_skill")
return output
# END =========================================================================