diff --git a/spp_registrant_gis/views/res_partner_views.xml b/spp_registrant_gis/views/res_partner_views.xml index 781d0b5f..5a258a56 100644 --- a/spp_registrant_gis/views/res_partner_views.xml +++ b/spp_registrant_gis/views/res_partner_views.xml @@ -1,14 +1,15 @@ - + spp_registrant_gis.view_individuals_form_gis res.partner - @@ -19,15 +20,15 @@ - + spp_registrant_gis.view_groups_form_gis res.partner - diff --git a/spp_registry/models/group.py b/spp_registry/models/group.py index 22a36a83..0bf71d47 100644 --- a/spp_registry/models/group.py +++ b/spp_registry/models/group.py @@ -52,6 +52,47 @@ def _compute_force_recompute_canary(self): "Group Members", ) + # True when the group-membership-type vocabulary has at least one code. + # Used by views to hide the "Group Role" column entirely when the + # vocabulary is empty (otherwise the column shows blank tag cells with + # nothing pickable). + has_group_membership_type_codes = fields.Boolean( + compute="_compute_has_group_membership_type_codes", + ) + + # True when the group-type vocabulary has at least one code. Used to + # hide the Group Type form field when there's nothing to pick. + has_group_type_codes = fields.Boolean( + compute="_compute_has_group_type_codes", + ) + + def _compute_has_group_membership_type_codes(self): + # sudo() so non-admin readers can still resolve the column-visibility + # flag; we only return a boolean, no vocabulary content leaks. + has_codes = bool( + self.env["spp.vocabulary.code"] # nosemgrep: odoo-sudo-without-context + .sudo() + .search_count( + [("vocabulary_id.namespace_uri", "=", "urn:openspp:vocab:group-membership-type")], + limit=1, + ) + ) + for rec in self: + rec.has_group_membership_type_codes = has_codes + + def _compute_has_group_type_codes(self): + # sudo(): same rationale as above — we only expose a boolean. + has_codes = bool( + self.env["spp.vocabulary.code"] # nosemgrep: odoo-sudo-without-context + .sudo() + .search_count( + [("vocabulary_id.namespace_uri", "=", "urn:openspp:vocab:group-type")], + limit=1, + ) + ) + for rec in self: + rec.has_group_type_codes = has_codes + def write(self, values): res = super().write(values) self._validate_unique_membership_types() diff --git a/spp_registry/models/group_membership.py b/spp_registry/models/group_membership.py index a1170fc2..467170fd 100644 --- a/spp_registry/models/group_membership.py +++ b/spp_registry/models/group_membership.py @@ -27,9 +27,29 @@ class SPPGroupMembership(models.Model): ) membership_type_ids = fields.Many2many( "spp.vocabulary.code", - string="Membership Types", + string="Group Role", domain="[('namespace_uri', '=', 'urn:openspp:vocab:group-membership-type')]", ) + # True when the group-membership-type vocabulary has at least one code. + # Drives column_invisible on the standalone Group Membership tree view + # (the embedded lists on the registrant forms read this from + # `parent.has_group_membership_type_codes` on res.partner instead). + has_group_membership_type_codes = fields.Boolean( + compute="_compute_has_group_membership_type_codes", + ) + + def _compute_has_group_membership_type_codes(self): + has_codes = bool( + self.env["spp.vocabulary.code"] # nosemgrep: odoo-sudo-without-context + .sudo() + .search_count( + [("vocabulary_id.namespace_uri", "=", "urn:openspp:vocab:group-membership-type")], + limit=1, + ) + ) + for rec in self: + rec.has_group_membership_type_codes = has_codes + start_date = fields.Datetime(default=lambda self: fields.Datetime.now()) ended_date = fields.Datetime() status = fields.Selection( diff --git a/spp_registry/views/group_membership_view.xml b/spp_registry/views/group_membership_view.xml index a1cc189a..62cbca63 100644 --- a/spp_registry/views/group_membership_view.xml +++ b/spp_registry/views/group_membership_view.xml @@ -9,13 +9,15 @@ 1 + @@ -52,10 +54,7 @@ />
-