Skip to content

Commit

Permalink
CCC: supply_person_item changes 'complete'
Browse files Browse the repository at this point in the history
  • Loading branch information
flavour committed Nov 22, 2019
1 parent 87f97f1 commit e7f57f4
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 55 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6668bfd43 (2019-11-22 09:01:08)
87f97f1f4 (2019-11-22 11:41:18)
6 changes: 6 additions & 0 deletions controllers/supply.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ def kit_item():

return s3_rest_controller()

# -----------------------------------------------------------------------------
def person_item():
""" RESTful CRUD controller """

return s3_rest_controller()

# -----------------------------------------------------------------------------
def person_item_status():
""" RESTful CRUD controller """
Expand Down
1 change: 1 addition & 0 deletions languages/en-gb.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
'Delete Program': 'Delete Programme',
'Department Catalog': 'Department Catalogue',
'Donating Organization': 'Donating Organisation',
'Donor Organization': 'Donor Organisation',
'Edit Catalog': 'Edit Catalogue',
'Edit Catalog Item': 'Edit Catalogue Item',
'Edit Organization': 'Edit Organisation',
Expand Down
11 changes: 6 additions & 5 deletions modules/s3db/supply.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
__all__ = ("S3SupplyModel",
"S3SupplyDistributionModel",
"S3SupplyDistributionDVRActivityModel",
"S3DonorPersonModel",
"S3SupplyPersonModel",
"supply_item_rheader",
"supply_item_controller",
"supply_item_entity_controller",
Expand Down Expand Up @@ -1746,7 +1746,7 @@ def model(self):
return {}

# =============================================================================
class S3DonorPersonModel(S3Model):
class S3SupplyPersonModel(S3Model):
"""
Link table between People & Items
- e.g. Donations
Expand Down Expand Up @@ -1793,6 +1793,7 @@ def model(self):
# Reusable Field
represent = S3Represent(lookup = tablename)
status_id = S3ReusableField("status_id", "reference %s" % tablename,
label = T("Status"),
ondelete = "SET NULL",
represent = represent,
requires = IS_EMPTY_OR(
Expand All @@ -1810,16 +1811,16 @@ def model(self):
self.supply_item_id(comment = None,
empty = False,
ondelete = "CASCADE",
widget = S3MultiSelectWidget(),
widget = None, # Dropdown not AC
),
self.pr_person_id(empty = False,
ondelete = "CASCADE",
),
s3_comments(comment = None),
status_id(),
status_id(empty = False),
# Requested By / Taken By
self.org_organisation_id(ondelete = "SET NULL",
),
s3_comments(comment = None),
*s3_meta_fields())

crud_strings[tablename] = Storage(
Expand Down
2 changes: 2 additions & 0 deletions modules/templates/CCC/auth_roles.csv
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ ORG_ADMIN,"Organisation Administrator",,,,pr_person,CREATE|READ|UPDATE|DELETE,,,
ORG_ADMIN,"Organisation Administrator",,project,task,,ALL,,,
ORG_ADMIN,"Organisation Administrator",,project,comments,,ALL,,,
ORG_ADMIN,"Organisation Administrator",,req,need,,CREATE|READ|UPDATE|DELETE,,,
ORG_ADMIN,"Organisation Administrator",,supply,person_item,,CREATE|READ|UPDATE,,,
AGENCY,"Agency Staff",,cms,post,,READ,,,
AGENCY,"Agency Staff",,doc,document,,READ,,any,
AGENCY,"Agency Staff",,hrm,training_event,,READ,,,
AGENCY,"Agency Staff",,project,task,,CREATE,READ|UPDATE|DELETE,,
AGENCY,"Agency Staff",,req,need,,READ,,any,
AGENCY,"Agency Staff",,supply,person_item,,READ,,,
DONOR,"Donor",,dummy,dummy,,READ,,,
GROUP_ADMIN,"Volunteer Group Leader",,cms,post,,READ,,,
GROUP_ADMIN,"Volunteer Group Leader",,pr,group,,CREATE|READ|UPDATE,,,
Expand Down
166 changes: 136 additions & 30 deletions modules/templates/CCC/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ def customise_pr_group_membership_resource(r, tablename):
def customise_pr_person_resource(r, tablename):

from gluon import IS_EMPTY_OR, IS_IN_SET
from s3 import S3SQLCustomForm, S3SQLInlineLink
from s3 import S3SQLCustomForm, S3SQLInlineComponent, S3SQLInlineLink

s3db = current.s3db

Expand All @@ -1494,11 +1494,11 @@ def customise_pr_person_resource(r, tablename):
"filterby": {"tag": "organisation"},
"multiple": False,
},
{"name": "organisation_type",
"joinby": "person_id",
"filterby": {"tag": "organisation_type"},
"multiple": False,
},
#{"name": "organisation_type",
# "joinby": "person_id",
# "filterby": {"tag": "organisation_type"},
# "multiple": False,
# },
#{"name": "items_details",
# "joinby": "person_id",
# "filterby": {"tag": "items_details"},
Expand All @@ -1520,21 +1520,18 @@ def customise_pr_person_resource(r, tablename):
"multiple": False,
},
),
supply_person_item = {"joinby": "person_id",
"multiple": False,
},
)

# Individual settings for specific tag components
components_get = s3db.resource(tablename).components.get

organisation_type = components_get("organisation_type")
f = organisation_type.table.value
f.requires = IS_EMPTY_OR(IS_IN_SET([T("Business Donor"),
T("Individual Donor"),
T("Public Sector Organization"),
T("Voluntary Sector Organization"),
]))
#organisation_type = components_get("organisation_type")
#f = organisation_type.table.value
#f.requires = IS_EMPTY_OR(IS_IN_SET([T("Business Donor"),
# T("Individual Donor"),
# T("Public Sector Organization"),
# T("Voluntary Sector Organization"),
# ]))

delivery = components_get("delivery")
f = delivery.table.value
Expand All @@ -1550,22 +1547,32 @@ def customise_pr_person_resource(r, tablename):
if get_vars_get("donors") or \
has_role("DONOR", include_admin=False):
# Donor
stable = s3db.supply_person_item_status
status = current.db(stable.name == "Available").select(stable.id,
limitby = (0, 1)
).first()
if status:
s3db.supply_person_item.status_id.default = status.id
crud_fields = ["first_name",
"middle_name",
"last_name",
"date_of_birth",
(T("Gender"), "gender"),
(T("Name of Organization"), "organisation.value"),
(T("Type of Organization"), "organisation_type.value"),
S3SQLInlineLink("item",
field = "item_id",
label = T("Goods / Services"),
),
#(T("Type of Organization"), "organisation_type.value"),
#S3SQLInlineLink("item",
# field = "item_id",
# label = T("Goods / Services"),
# ),
#(T("Details"), "items_details.value"),
(T("Goods / Services"), "person_item.item_id"),
(T("Details"), "person_item.comments"),
(T("Status"), "person_item.status_id"),
(T("Requested By"), "person_item.organisation_id"),
S3SQLInlineComponent("person_item",
label = "",
fields = [(T("Goods / Services"), "item_id"),
(T("Details"), "comments"),
(T("Status"), "status_id"),
(T("Requested By"), "organisation_id"),
],
),
(T("Are you able to Deliver?"), "delivery.value"),
S3SQLInlineLink("location",
field = "location_id",
Expand Down Expand Up @@ -2269,7 +2276,9 @@ def customise_req_need_resource(r, tablename):
"need_contact.person_id",
S3SQLInlineComponent("need_skill",
label = "",
fields = ["skill_id", "quantity"],
fields = ["skill_id",
"quantity",
],
multiple = False,
),
(T("Age Restrictions"), "age_restrictions.value"),
Expand Down Expand Up @@ -2341,13 +2350,110 @@ def customise_req_need_person_resource(r, tablename):
# -------------------------------------------------------------------------
def customise_supply_person_item_resource(r, tablename):

from s3 import S3SQLCustomForm, S3OptionsFilter, S3TextFilter

s3db = current.s3db
f = s3db.supply_person_item.item_id

# Filtered components
s3db.add_components("pr_person",
pr_person_tag = ({"name": "organisation",
"joinby": "person_id",
"filterby": {"tag": "organisation"},
"multiple": False,
},
{"name": "delivery",
"joinby": "person_id",
"filterby": {"tag": "delivery"},
"multiple": False,
},
{"name": "availability",
"joinby": "person_id",
"filterby": {"tag": "availability"},
"multiple": False,
},
),
)

# No Hyperlink for Items (don't have permissions anyway)
f.represent = s3db.supply_ItemRepresent()
# Dropdown, not Autocomplete
f.widget = None
s3db.supply_person_item.item_id.represent = s3db.supply_ItemRepresent()

current.response.s3.crud_strings[tablename] = Storage(
title_display = T("Donation Details"),
title_list = T("Donations"),
title_update = T("Edit Donation"),
label_list_button = T("List Donations"),
msg_record_modified = T("Donation updated"),
msg_list_empty = T("No Donations currently registered")
)

crud_form = S3SQLCustomForm((T("Goods / Service"), "item_id"),
(T("Details"), "comments"),
(T("Donor"), "person_id"),
"status_id",
(T("Requested By"), "organisation_id"),
)

filter_widgets = [S3TextFilter(["item_id$name",
"comments",
# Not working:
#"person_id$first_name",
#"person_id$last_name",
],
#formstyle = text_filter_formstyle,
label = "",
_placeholder = T("Search"),
),
S3OptionsFilter("status_id",
),
]

list_fields = [(T("Goods / Service"), "item_id"),
(T("Details"), "comments"),
(T("Donor"), "person_id"),
(T("Donor Organization"), "person_id$organisation.value"),
(T("Delivery"), "person_id$delivery.value"),
(T("Availability"), "person_id$availability.value"),
"status_id",
(T("Requested By"), "organisation_id"),
]

s3db.configure("supply_person_item",
crud_form = crud_form,
deletable = False,
insertable = False,
filter_widgets = filter_widgets,
list_fields = list_fields,
)

settings.customise_supply_person_item_resource = customise_supply_person_item_resource

# -----------------------------------------------------------------------------
def customise_supply_person_item_controller(**attr):

s3db = current.s3db

stable = s3db.supply_person_item_status
status = current.db(stable.name == "Available").select(stable.id,
limitby = (0, 1)
).first()
if status:
# Default Filter
from s3 import s3_set_default_filter
s3_set_default_filter("~.status_id",
status.id,
tablename = "supply_person_item")

if current.auth.s3_has_role("ORG_ADMIN"):
# Add Hyperlink for Donors
from gluon import URL
s3db.supply_person_item.person_id.represent = \
s3db.pr_PersonRepresentContact(linkto = URL(c="pr", f="person",
args = ["[id]"],
vars = {"donors": 1},
extension=""))

return attr

settings.customise_supply_person_item_controller = customise_supply_person_item_controller

# END =========================================================================
39 changes: 25 additions & 14 deletions modules/templates/CCC/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,15 +718,15 @@ def individual_formfields():
Field("organisation",
label = T("Name of Organization"),
),
Field("organisation_type",
label = T("Type of Organization"),
requires = IS_EMPTY_OR(
IS_IN_SET([T("Business Donor"),
T("Individual Donor"),
T("Public Sector Organization"),
T("Voluntary Sector Organization"),
])),
),
#Field("organisation_type",
# label = T("Type of Organization"),
# requires = IS_EMPTY_OR(
# IS_IN_SET([T("Business Donor"),
# T("Individual Donor"),
# T("Public Sector Organization"),
# T("Voluntary Sector Organization"),
# ])),
# ),
Field("addr_L3", "reference gis_location",
label = T("Location"),
requires = IS_IN_SET(districts_and_uk),
Expand Down Expand Up @@ -1684,19 +1684,30 @@ def auth_user_register_onaccept(user_id):
person_id = person.id

# Create Items
items_details = custom["items_details"]
stable = s3db.supply_person_item_status
status = db(stable.name == "Available").select(stable.id,
limitby = (0, 1)
).first()
if status:
status_id = status.id
else:
raise HTTP(500, "'Available' Status for Donations not found")
itable = s3db.supply_person_item
for item_id in custom["item_id"]:
record = {"person_id": person_id,
"item_id": item_id,
"comments": items_details,
"status_id": status_id,
}
itable.insert(**record)

ttable = s3db.pr_person_tag
record = {"person_id": person_id,
"tag": "items_details",
"value": custom["items_details"],
}
ttable.insert(**record)
#record = {"person_id": person_id,
# "tag": "items_details",
# "value": custom["items_details"],
# }
#ttable.insert(**record)

record = {"person_id": person_id,
"tag": "organisation",
Expand Down
Loading

0 comments on commit e7f57f4

Please sign in to comment.