Most Powerful Open Source ERP

Guideline ListField Or MultListField For Categories Must Use Item List Method

Preserve consistency in pop-up field rendering.
  • Last Update:2019-07-15
  • Version:001
  • Language:en

ListField Or MultListField For Categories Must Use Item List Method

Always use the "item list method" from when you configure a ListField or MultiListField to handle categories in forms.

The way to render categories in pop-up menus must be consistent across various forms and must be configured from user preferences.

  • The categories titles are translated using Localizer (erp5_content).
  • The categories must be sorted by int_index, then by translated title, while respecting the hierarchical structure. The idea behind this is to have for example this ordering: A, B, P, Z, Others. With "Others" in last position, to achieve this, we have to set and int_index on "Others" category with a value greater than 0 (which is the default for A, B, P, Z).
  • The categories that cannot be viewed (ie. no View permission) by the user should not be displayed.
  • The method must be defined on the first level field library, and use the value preferred_category_child_item_list_method_id from preferences. The "items" TALES for the first field is horrible, but generic:
    getattr(here.portal_categories[field.getId().replace('my_', '', 1)],
      preferences.getPreference(
        'preferred_category_child_item_list_method_id',
        'getCategoryChildCompactLogicalPathItemList')
      )(
        local_sort_id=('int_index', 'translated_title'),
        checked_permission='View'
      )

    In some cases, the method used to render a list of categories could be different. For example, when handling values of the function category on a person, only leaves of the category tree should be displayed.