Skip to content

Odoo 18 migration - T3173 migrate auth external#51

Open
NoeBerdoz wants to merge 3 commits into
mainfrom
T3173-migrate-auth-external
Open

Odoo 18 migration - T3173 migrate auth external#51
NoeBerdoz wants to merge 3 commits into
mainfrom
T3173-migrate-auth-external

Conversation

@NoeBerdoz
Copy link
Copy Markdown
Contributor

@NoeBerdoz NoeBerdoz commented May 12, 2026

Adaptations for Odoo 18.0
DO NOT MERGE THIS YET

  • We should rename the main branch as 14.0 and create a new branch 18.0
  • Then this PR has to be targeted to 18.0
  • Will do ASAP

Dependencies:
CompassionCH/compassion-modules#2096
CompassionCH/compassion-switzerland#1756

NoeBerdoz added 3 commits May 12, 2026 15:52
- vite.config.js: server. proxy /auth and /xmlrpc -> VITE_DEV_PROXY_TARGET
 (default http://localhost:8069).
 Lets npm run dev work against a
 local Odoo without CORS hacks, v18's /xmlrpc/2/* declares no cors= attribute, so cross-origin XML-RPC fails preflight in the browser. The proxy makes the browser see same-origin requests instead.
- .env: VITE_ODOO_URL default changed from a placeholder to "" with guidance, recommended setting both for local dev (proxy intercepts relative URLs) and for the production deployment where Odoo serves     the SPA from static/tp/ (also same-origin). Added VITE_DEV_PROXY_TARGET.
- README: added "Running against Odoo 18" section documenting the
 three deployment modes (Odoo-served, dev with Vite proxy, true cross-origin which requires an Odoo-side CORS patch). The legacy v12/v14 source-patch instructions are kept for historical reference.

The webapp's RPC contracts already match the v18 auth_external controllers, no changes to OdooAPI.ts, the store, or any DAO.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for Odoo 18 by implementing a Vite dev proxy to handle authentication and XML-RPC requests, effectively bypassing CORS issues during local development. Documentation has been updated to reflect these changes and provide guidance on deployment modes. Additionally, the data access objects for letters and translators were updated to use the search_count method instead of a count parameter in the search method. Feedback suggests adding fallback values to these count requests to ensure type safety and prevent runtime errors if the API returns undefined.

Comment thread src/models/LetterDAO.ts
const [letterIds, total] = await Promise.all([
OdooAPI.execute_kw('correspondence', 'search', searchParams),
OdooAPI.execute_kw('correspondence', 'search', [...searchParams, true]) as Promise<number>
OdooAPI.execute_kw('correspondence', 'search_count', countParams) as Promise<number>,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The OdooAPI.execute_kw method can return undefined if the request fails. Since the total property in the returned object is expected to be a number (per the ListResponse interface), it is safer to provide a default value of 0 to avoid potential runtime issues in UI components (like pagination) and to maintain type safety.

Suggested change
OdooAPI.execute_kw('correspondence', 'search_count', countParams) as Promise<number>,
OdooAPI.execute_kw('correspondence', 'search_count', countParams).then((res) => res ?? 0) as Promise<number>,

const [translatorIds, total] = await Promise.all([
OdooAPI.execute_kw('translation.user', 'search', searchParams),
OdooAPI.execute_kw('translation.user', 'search', [...searchParams, true]) as Promise<number>
OdooAPI.execute_kw('translation.user', 'search_count', countParams) as Promise<number>,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the LetterDAO, the total count should have a fallback value. If the API call fails, execute_kw returns undefined, which violates the number type requirement for the total field in the response. Defaulting to 0 ensures robustness.

Suggested change
OdooAPI.execute_kw('translation.user', 'search_count', countParams) as Promise<number>,
OdooAPI.execute_kw('translation.user', 'search_count', countParams).then((res) => res ?? 0) as Promise<number>,

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 12, 2026

Confidence Score: 4/5

Safe to merge into the correct target branch — all logic changes are correct and self-consistent.

The search → search_count migration is correct: countParams passes only the domain, which is what Odoo 18 search_count expects. The Vite proxy config is correct and scoped to the dev server. The only finding is a trivial missing-newline in .env (P2).

No files require special attention; .env has a minor trailing-newline nit.

Important Files Changed

Filename Overview
src/models/LetterDAO.ts Switches total-count strategy from search(count=True) to search_count with just the domain; countParams correctly captures the mutated domain before passing it to Promise.all.
src/models/TranslatorDAO.ts Same search → search_count migration as LetterDAO; no domain mutation involved, so countParams is straightforwardly correct.
vite.config.js Adds dev-server proxy for /auth and /xmlrpc paths, driven by VITE_DEV_PROXY_TARGET, to eliminate CORS issues when developing against a local Odoo 18 instance.
.env VITE_ODOO_URL cleared to empty string (recommended default), VITE_DEV_PROXY_TARGET added; VITE_ODOO_DBNAME retains the placeholder and the file is missing a trailing newline.
README.md Adds clear documentation covering Odoo 18 auth flow and three deployment modes (served-by-Odoo, Vite proxy dev, cross-origin); no issues found.

Reviews (1): Last reviewed commit: "[MIG] adapt cors guidance" | Re-trigger Greptile

Comment thread .env
# Where `npm run dev` proxies /auth/* and /xmlrpc/* to. Defaults to
# http://localhost:8069 if unset. Override if your Odoo runs on a
# different port or host.
VITE_DEV_PROXY_TARGET="http://localhost:8069" No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Missing trailing newline

The file still ends without a trailing newline (\ No newline at end of file). Some tooling (e.g. dotenv parsers, git diff, linters) can misbehave or produce noisy diffs when a file is missing the final newline.

Suggested change
VITE_DEV_PROXY_TARGET="http://localhost:8069"
VITE_DEV_PROXY_TARGET="http://localhost:8069"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant