-
Notifications
You must be signed in to change notification settings - Fork 1
fix(spp_registry): registry UX polish (#942) #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 19.0
Are you sure you want to change the base?
Changes from all commits
ad51f8d
09ed95d
0a708fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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, | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+85
to
+92
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The search_count method does not support the limit parameter. This will cause a TypeError. Use search() with limit=1 to perform an efficient existence check. This non-deterministic search is acceptable but should be acknowledged as technical debt to be addressed if the context changes.
Suggested change
References
|
||||||||||||||||||||||||||||||||||
| for rec in self: | ||||||||||||||||||||||||||||||||||
| rec.has_group_type_codes = has_codes | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def write(self, values): | ||||||||||||||||||||||||||||||||||
| res = super().write(values) | ||||||||||||||||||||||||||||||||||
| self._validate_unique_membership_types() | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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, | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+42
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Odoo, search_count does not accept a limit argument. This implementation will fail with a TypeError. Please use search() with limit=1 for an optimized existence check. This approach is non-deterministic without an explicit order and should be acknowledged as technical debt to be addressed if the context changes.
Suggested change
References
|
||||||||||||||||||||||||||||||||||
| 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( | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The search_count method in Odoo does not accept a limit argument. Passing limit=1 will result in a TypeError at runtime. To efficiently check for the existence of at least one record, use search() with limit=1 instead. Note: This non-deterministic search (using limit=1 without order) is acceptable here but should be acknowledged as technical debt to be addressed if the context changes.
References