Commit 0438140f authored by Boxiang Sun's avatar Boxiang Sun Committed by Eteri

erp5_officejs_support_request_ui: Dynamically add keys to `count_by_state` dict.

The keys in the `count_by_state` dict in SupportRequest_getSupportRequestStatisticsAsJson.py
was hardcoded in previous version. This commit can add the keys to the dict dynamically according
to the states of Support Request. Thus the code can still work if there has new state added to
Support Request.
parent 8a381c10
...@@ -4,9 +4,8 @@ portal = context.getPortalObject() ...@@ -4,9 +4,8 @@ portal = context.getPortalObject()
support_request_list = portal.portal_catalog(portal_type="Support Request") support_request_list = portal.portal_catalog(portal_type="Support Request")
count_by_state = {}
count_by_state = {"validated": 0, "submitted": 0, "suspended": 0, "invalidated": 0, "draft": 0, "cancelled": 0} count_by_date = {"le2": {}, "2to7": {}, "7to30": {}, "gt30": {}}
count_by_date = {"le2": count_by_state.copy(), "2to7": count_by_state.copy(), "7to30": count_by_state.copy(), "gt30": count_by_state.copy()}
# Get the split date # Get the split date
now_date = DateTime() now_date = DateTime()
...@@ -23,6 +22,13 @@ for sr in support_request_list: ...@@ -23,6 +22,13 @@ for sr in support_request_list:
sr_date = sr.getModificationDate() sr_date = sr.getModificationDate()
sr_state = sr.getSimulationState() sr_state = sr.getSimulationState()
if sr_state not in count_by_state:
count_by_state[sr_state] = 0
if sr_state not in count_by_date["le2"]:
for date_category in count_by_date:
count_by_date[date_category][sr_state] = 0
if sr_date >= date_2_midnight: if sr_date >= date_2_midnight:
count_by_date["le2"][sr_state] = count_by_date["le2"][sr_state] + 1 count_by_date["le2"][sr_state] = count_by_date["le2"][sr_state] + 1
elif sr_date >= date_7_midnight: elif sr_date >= date_7_midnight:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment