feat: add organisation-level portfolio API support#259
Open
patjlm wants to merge 3 commits intolasconic:mainfrom
Open
feat: add organisation-level portfolio API support#259patjlm wants to merge 3 commits intolasconic:mainfrom
patjlm wants to merge 3 commits intolasconic:mainfrom
Conversation
Add `user_organizations.py` with 6 functions mirroring the
`/organizations/{org_id}/…` endpoints (investments, cryptos,
fonds_euro, real_estates, scpis, holdings_accounts).
Add `get_family_org_id()` convenience helper to `user_me.py` that
resolves the family organisation ID from the authenticated user's
organisations list.
Add `test_organizations` integration test that skips cleanly when
the account has no family organisation.
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
- get_organization_cryptos: use /cryptos (flat list) instead of /portfolio/cryptos (aggregated dict) — consistent with all other flat-list org functions - get_organization_investments: keep as /portfolio/investments (dict), mirrors get_portfolio_investments in user_portfolio.py; add docstring to make the return shape explicit - get_organization_securities: new function for /securities (flat list), the actual flat-list counterpart to investments Test: assert isinstance(result["result"], list) for all flat-list functions and dict for get_organization_investments, so wrong endpoint shapes are caught immediately. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Adds an optional --org-id flag to all commands that have an organisation-level equivalent: finary_uapi fonds_euro [--org-id=<org_id>] finary_uapi investments [--org-id=<org_id>] finary_uapi cryptos [--org-id=<org_id>] finary_uapi securities [--org-id=<org_id>] finary_uapi holdings_accounts [...] [--org-id=<org_id>] finary_uapi real_estates [--org-id=<org_id>] finary_uapi scpis [--org-id=<org_id>] Accepts either a UUID or the keyword 'family', which auto-resolves via get_family_org_id(). When --org-id is provided the command routes to the corresponding get_organization_*() function; otherwise falls through to the existing /users/me/ behaviour. Write operations (add, update, delete) are unaffected. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Relates to #132.
Finary's backend exposes
/organizations/{org_id}/…endpoints for household/family accounts. Without this, a user in a couple sees only their own accounts via/users/me/…, missing their partner's PEA, AV, PER, livrets, etc.This PR adds minimal, additive support for the organisation-level endpoints.
New file:
finary_uapi/user_organizations.pySeven functions covering all organisation-level data endpoints:
get_organization_investments/organizations/{id}/portfolio/investmentsdict(aggregated, mirrorsget_portfolio_investments)get_organization_securities/organizations/{id}/securitieslistget_organization_cryptos/organizations/{id}/cryptoslistget_organization_fonds_euro/organizations/{id}/fonds_eurolistget_organization_real_estates/organizations/{id}/real_estateslistget_organization_scpis/organizations/{id}/scpislistget_organization_holdings_accounts/organizations/{id}/holdings_accountslistNote:
get_organization_investmentsreturns a dict (same shape asget_portfolio_investmentsinuser_portfolio.py) because/portfolio/investmentsis the only available investments endpoint at the org level. All other functions return flat lists.New helper:
get_family_org_id()inuser_me.pyCalls the already-existing
get_user_me_organizations()and returns the ID of the first organisation withorganization_type == "family", orNonefor single-user accounts.CLI:
--org-idoption on read commandsAll read commands that have an org-level equivalent now accept
--org-id:--org-idaccepts either a UUID or the keywordfamily, which auto-resolves viaget_family_org_id(). Write operations (add, update, delete) are unaffected.New integration test:
test_organizationsintests/test_get.pypytest.skip) when the account has no family organisation — single-user accounts are unaffectedisinstance(result["result"], list)for all flat-list endpoints, anddictforget_organization_investments, so wrong endpoint shapes are caught immediatelyRemaining gaps (out of scope, for follow-up)
The following org-level endpoints exist and return data, but are not included here because they require pagination and filtering parameters (mirroring the complexity of their counterparts in
user_portfolio.py):portfolio/investments/dividendsportfolio/investments/transactionsportfolio/checking_accounts/transactionsportfolio/credit_accounts/transactionsThe following endpoints do not exist at the org level (404):
portfolio/cryptos/distributionportfolio/crowdlendings/distributionDesign notes
get_family_org_id()+ the newget_organization_*functions, or via--org-id familyon the CLIget_family_org_idreturnsNoneand the new module is never imported unless explicitly usedget_organization_holdings_accountsreturns 40 accounts,get_organization_real_estatesreturns 2 properties,get_organization_fonds_euroreturns 6 funds,get_organization_securitiesreturns 26 securitiesTest plan
test_organizationspasses with correct list/dict shapes verifiedtest_organizationsskips cleanlyfinary_uapi holdings_accounts --org-id familyreturns combined household accounts