forked from sahana/eden
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasset.py
144 lines (110 loc) · 4.99 KB
/
asset.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
# -*- coding: utf-8 -*-
"""
Asset Management Functionality
http://eden.sahanafoundation.org/wiki/BluePrint/Assets
"""
module = request.controller
resourcename = request.function
if not settings.has_module(module):
raise HTTP(404, body="Module disabled: %s" % module)
# -----------------------------------------------------------------------------
def index():
""" Module Home Page """
module_name = settings.modules[module].name_nice
response.title = module_name
return dict(module_name=module_name)
# -----------------------------------------------------------------------------
def create():
""" Redirect to asset/create """
redirect(URL(f="asset", args="create"))
# -----------------------------------------------------------------------------
def asset():
""" RESTful CRUD controller """
# Use the item() controller in this module to set options correctly
s3db.asset_asset.item_id.comment = S3AddResourceLink(f="item",
label=T("Add New Item"),
title=T("Item"),
tooltip=T("Type the name of an existing catalog item OR Click 'Add New Item' to add an item which is not in the catalog."))
# Defined in Model for use from Multiple Controllers for unified menus
return s3db.asset_controller()
# -----------------------------------------------------------------------------
def brand():
""" RESTful CRUD controller """
return s3_rest_controller("supply", "brand")
# -----------------------------------------------------------------------------
def catalog():
""" RESTful CRUD controller """
return s3_rest_controller("supply", "catalog",
rheader=s3db.supply_catalog_rheader)
# -----------------------------------------------------------------------------
def item():
""" RESTful CRUD controller """
if "catalog_item" not in request.args:
# Filter to just Assets
table = s3db.supply_item
ctable = s3db.supply_item_category
s3.filter = (table.item_category_id == ctable.id) & \
(ctable.can_be_asset == True)
# Limit the Categories to just those which can be Assets
# - make category mandatory so that filter works
field = s3db.supply_item.item_category_id
field.requires = IS_ONE_OF(db,
"supply_item_category.id",
s3db.supply_item_category_represent,
sort=True,
filterby = "can_be_asset",
filter_opts = [True]
)
field.comment = S3AddResourceLink(f="item_category",
label=T("Add Item Category"),
title=T("Item Category"),
tooltip=T("Only Categories of type 'Asset' will be seen in the dropdown."))
# Defined in the Model for use from Multiple Controllers for unified menus
return s3db.supply_item_controller()
# -----------------------------------------------------------------------------
def catalog_item():
"""
RESTful CRUD controller
- used for Imports
"""
return s3_rest_controller("supply", "catalog_item",
csv_template=("supply", "catalog_item"),
csv_stylesheet=("supply", "catalog_item.xsl"),
)
# -----------------------------------------------------------------------------
def item_category():
""" RESTful CRUD controller """
table = s3db.supply_item_category
# Filter to just Assets
s3.filter = (table.can_be_asset == True)
# Default to Assets
field = table.can_be_asset
field.readable = field.writable = False
field.default = True
return s3_rest_controller("supply", "item_category")
# -----------------------------------------------------------------------------
def supplier():
""" RESTful CRUD controller """
request.get_vars["organisation.organisation_type_id$name"] = "Supplier"
# Load model
table = s3db.org_organisation
# Modify CRUD Strings
ADD_SUPPLIER = T("Add Supplier")
s3.crud_strings.org_organisation = Storage(
title_create=ADD_SUPPLIER,
title_display=T("Supplier Details"),
title_list=T("Suppliers"),
title_update=T("Edit Supplier"),
title_search=T("Search Suppliers"),
title_upload=T("Import Suppliers"),
subtitle_create=ADD_SUPPLIER,
label_list_button=T("List Suppliers"),
label_create_button=ADD_SUPPLIER,
label_delete_button=T("Delete Supplier"),
msg_record_created=T("Supplier added"),
msg_record_modified=T("Supplier updated"),
msg_record_deleted=T("Supplier deleted"),
msg_list_empty=T("No Suppliers currently registered")
)
return s3db.org_organisation_controller()
# END =========================================================================