-
Notifications
You must be signed in to change notification settings - Fork 1
feat(spp_api_v2): auto-assign system_id to registrants for API addressability #162
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
Draft
pmigueld
wants to merge
15
commits into
19.0
Choose a base branch
from
fix/api-v2-skip-records-without-identifiers
base: 19.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
95a8d95
fix(spp_api_v2): skip records without identifiers instead of crashing…
pmigueld b0130c6
fix(spp_api_v2): handle None from to_api_schema in all callers and fi…
pmigueld 2f63663
test(spp_api_v2): add coverage for records without valid identifiers
pmigueld 2a9dcab
test(spp_api_v2): fix test setup for no-identifier coverage tests
pmigueld cf54325
test(spp_api_v2): add coverage for no-identifier paths and pragma on …
pmigueld 291a18e
fix(spp_api_v2): return records without identifiers using internal ID…
pmigueld efe2cd5
fix(spp_api_v2): use fallback identifier in membership references for…
pmigueld 2c0845c
feat(spp_api_v2): auto-assign system_id to registrants for API addres…
pmigueld d761de0
test(spp_api_v2): update tests for system_id auto-assignment and memb…
pmigueld a7299be
fix(spp_api_v2): sort system_id last in identifier lists and prefer r…
pmigueld ca0c89b
test(spp_api_v2): relax membership reference assertions to accept any…
pmigueld 910e853
fix(spp_api_v2): protect system_id from manual edit and deletion
pmigueld e4fc7bc
fix(spp_api_v2): make system_id rows readonly and muted in registry I…
pmigueld cc7ee10
fix(spp_api_v2): prefer non-system_id identifiers in references and u…
pmigueld 385a127
refactor(spp_api_v2): hide system_id from UI instead of readonly prot…
pmigueld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <!-- | ||
| Part of OpenSPP. See LICENSE file for full copyright and licensing details. | ||
| --> | ||
| <odoo noupdate="1"> | ||
| <!-- System-generated identifier for API addressability. | ||
| Every registrant gets one automatically at creation time. | ||
| Unlike identity documents (national_id, passport), this is | ||
| not a real-world document — it's an internal stable UUID | ||
| that allows the API to address records that don't yet have | ||
| any identity documents assigned. --> | ||
| <record id="code_id_type_system_id" model="spp.vocabulary.code"> | ||
| <field name="vocabulary_id" ref="spp_vocabulary.vocab_id_type" /> | ||
| <field name="code">system_id</field> | ||
| <field name="display">System ID</field> | ||
| <field name="target_type">both</field> | ||
| <field | ||
| name="definition" | ||
| >Auto-generated unique identifier for API addressability. Not an identity document.</field> | ||
| <field name="sequence">0</field> | ||
| </record> | ||
| </odoo> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # Part of OpenSPP. See LICENSE file for full copyright and licensing details. | ||
| """Auto-assign system ID to registrants for API addressability.""" | ||
|
|
||
| import logging | ||
| import uuid | ||
|
|
||
| from odoo import api, models | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class ResPartnerSystemId(models.Model): | ||
| _inherit = "res.partner" | ||
|
|
||
| @api.model_create_multi | ||
| def create(self, vals_list): | ||
| """Auto-assign a system_id registry ID to new registrants. | ||
|
|
||
| Every registrant needs at least one identifier so the API can | ||
| address it. Identity documents (national_id, passport) may be | ||
| added later or not at all. The system_id is a stable UUID that | ||
| fills this gap without exposing internal database IDs. | ||
| """ | ||
| partners = super().create(vals_list) | ||
| self._assign_system_ids(partners) | ||
| return partners | ||
|
|
||
| def _assign_system_ids(self, partners): | ||
| """Create system_id registry entries for registrants that lack one.""" | ||
| system_id_type = self._get_system_id_type() | ||
| if not system_id_type: | ||
| return | ||
|
|
||
| RegistryId = self.env["spp.registry.id"].sudo() # nosemgrep: odoo-sudo-without-context | ||
|
|
||
| for partner in partners: | ||
| if not partner.is_registrant: | ||
| continue | ||
|
|
||
| # Check if already has a system_id | ||
| existing = RegistryId.search( | ||
| [ | ||
| ("partner_id", "=", partner.id), | ||
| ("id_type_id", "=", system_id_type.id), | ||
| ], | ||
| limit=1, | ||
| ) | ||
| if existing: | ||
| continue | ||
|
|
||
| RegistryId.create( | ||
| { | ||
| "partner_id": partner.id, | ||
| "id_type_id": system_id_type.id, | ||
| "value": str(uuid.uuid4()), | ||
| } | ||
| ) | ||
|
|
||
| def _get_system_id_type(self): | ||
| """Retrieve the system_id vocabulary code, or None if not installed.""" | ||
| try: | ||
| return self.env.ref("spp_api_v2.code_id_type_system_id") | ||
| except ValueError: | ||
| _logger.warning("system_id vocabulary code not found — skipping auto-assignment") | ||
| return None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Part of OpenSPP. See LICENSE file for full copyright and licensing details. | ||
| """Hide system_id from the ID type dropdown in the UI.""" | ||
|
|
||
| from odoo import models | ||
|
|
||
|
|
||
| class SPPRegistryIdSystem(models.Model): | ||
| _inherit = "spp.registry.id" | ||
|
|
||
| def _compute_available_id_type_ids(self): # pylint: disable=missing-return | ||
| """Exclude system_id from the dropdown — it is auto-assigned, not user-selectable.""" | ||
| super()._compute_available_id_type_ids() | ||
| for rec in self: | ||
| rec.available_id_type_ids = rec.available_id_type_ids.filtered(lambda c: c.code != "system_id") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.