Commit f442aff2 authored by Tristan Cavelier's avatar Tristan Cavelier

erp5_officejs_support_request_ui: improvements in SupportRequest_getSupportTypeList code

- fix `NoneType` as no attribute `getTitle` (service_obj.getTitle()) ;
- use existing variable as most as possible (portal, result) ;
- avoid call `getTitle` on the same object in a loop (project.getTitle()) ;
- avoid compare projects by title as many projects may have the same ;
- avoid using `set` as service id cannot be present twice (set(service_pairs)) ;
- optimise catalog request to get project (limit) ;
- optimise catalog request to get sale supply (destination_project_uid) ;
- rename plurals in variable (service_pairs) ;
- rename abbreviations in variable (*_obj) ;
- remove trailing spaces.
parent 8dc56c7b
portal = context.getPortalObject()
sale_supply_list = portal.portal_catalog(portal_type="Sale Supply")
if project_id:
project_list = context.getPortalObject().portal_catalog(portal_type="Project", id=project_id)
project_list = portal.portal_catalog(portal_type="Project", id=project_id, limit=1)
else:
project_list = context.getPortalObject().portal_catalog(portal_type="Project", validation_state="validated")
project = project_list[0]
service_pairs = []
project_list = portal.portal_catalog(portal_type="Project", validation_state="validated", limit=1)
for sale_supply_obj in sale_supply_list:
sale_supply_lines = sale_supply_obj.contentValues(portal_type='Sale Supply Line')
if sale_supply_obj.getDestinationProjectValue().getTitle() == project.getTitle():
for supply_line in sale_supply_lines:
service_obj = supply_line.getResourceValue()
service_pairs.append((service_obj.getTitle(), service_obj.getId()))
try:
project = project_list[0]
except IndexError:
project = None
result = [list(item) for item in set(service_pairs)]
result = []
if project is not None:
sale_supply_list = portal.portal_catalog(portal_type="Sale Supply", destination_project_uid=project.getUid())
for sale_supply in sale_supply_list:
sale_supply_line_list = sale_supply.contentValues(portal_type='Sale Supply Line')
for supply_line in sale_supply_line_list:
service = supply_line.getResourceValue()
if service is not None:
result.append((service.getTitle(), service.getId()))
if json_flag:
from json import dumps
return dumps(result)
return result
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