Skip to content

Feature ETP-4908: Inject document QR as data field in report-server render - #129

Open
valenvivaldi wants to merge 4 commits into
epic/ETP-3504from
feature/ETP-4908
Open

Feature ETP-4908: Inject document QR as data field in report-server render#129
valenvivaldi wants to merge 4 commits into
epic/ETP-3504from
feature/ETP-4908

Conversation

@valenvivaldi

Copy link
Copy Markdown
Collaborator

Summary

  • Root cause: post-ETP-4083 the canonical helper whitelist excludes qrCode, but report templates still call {{qrCode header}} directly. This produces "Missing helper" on the server-side HTML render (pre-ETP-4083 builds instead threw "require is not defined").
  • Fix: precompute header.qrDataUrl via computeDocumentQrDataUrl/buildDocumentQrText in report-html-helpers.js, injected in server.js before the format branch so both the HTML and jsreport PDF render paths receive it. Added the qrcode dependency. QR failure degrades gracefully (no QR rendered, no request failure).
  • Tests: 11 new tests in cli/test/report-qr.test.js plus a generator regression guard. Full suite: 2957 green.

Jira: ETP-4908

Coordination note: the schema_forge counterpart PR (template edits {{qrCode header}}{{header.qrDataUrl}}) is coming separately. Both PRs must deploy together — this one alone leaves templates calling the now-removed qrCode helper.

🤖 Generated with Claude Code

Document print templates previously relied on an async qrCode Handlebars
helper, which fails on the local HTML render path (helpers whitelist excludes
it since ETP-4083, and Handlebars.compile is synchronous). The QR is now
precomputed once in the report server before the format branch and injected
as header.qrDataUrl into both the local HTML render and the jsreport
PDF/XLSX payload.

- report-html-helpers.js: add pure buildDocumentQrText(header) (exact port of
  the per-report qrCode text logic) and async computeDocumentQrDataUrl(header,
  { qrcode }) with injectable qrcode module (the report-server Docker image
  installs node_modules only under tools/report-server, unreachable from the
  templates/ module path) and lazy dynamic import fallback.
- server.js: injectDocumentQr() computes header.qrDataUrl before rendering;
  QR failure degrades to a report without QR instead of a 500.
- tools/report-server/package.json: add qrcode ^1.5.4.
- Tests: cli/test/report-qr.test.js (text building, data URL, injected module,
  no-header/empty cases) and a regression guard in
  generate-report-template.test.js asserting the generator never emits a
  qrCode helper call.
@github-actions

Copy link
Copy Markdown
Contributor

Copilot PR Review

Outcome: Comment only
No merge-blocking issues detected, but the warnings below should be reviewed.

Warnings

  • New npm dependency added (NEW_DEPENDENCY)
    tools/report-server/package.json adds:
  • qrcode@^1.5.4 (dependencies)
    Justify new dependencies in the PR description and prefer Node.js built-ins where possible.

The 8 per-report qrCode helpers were not identical: invoices used
dateinvoiced/grandtotal, orders and quotations dateordered, shipments and
receipts movementdate (no amount/currency), payment-in paymentdate/amount.
buildDocumentQrText only checked dateinvoiced/grandtotal, so 7 of 8 document
types lost the date (and payment-in its amount) in the QR.

Fallback chains, verified against the original artifacts/print-*/helpers.js
at the parent commit of the functional repo:
- date:   dateinvoiced || dateordered || movementdate || paymentdate
- amount: grandtotal || amount

Segment order and prefixes are unchanged (identical across all 8 originals).
Tests cover each variant plus precedence when multiple candidates exist.
…module

The report server's PDF/XLSX branch sent the raw artifact helpers.js as
jsreport's helpers string. Post-ETP-4083 that file no longer defines the
formatting helpers, so any template using {{#ifCond}}/{{formatDate}} failed
in jsreport with 400 missing helper "ifCond" (pre-existing, reproduced on
epic too).

- templates/reports/helpers/report-html-helpers.js: synced byte-identical
  with the functional repo's copy — brings JSREPORT_HELPER_SOURCES (the
  minification-safe verbatim source-text map, ETP-4728) and
  buildJsreportHelpersString(), plus the ETP-4314 es-ES/useGrouping currency
  behavior, killing the drift between the two copies. QR functions unchanged.
- server.js: the jsreport payload now sends
  buildJsreportHelpersString(helpersCode, undefined, separators) — canonical
  helper sources plus only the report-specific extras — with instance
  separators fetched (and cached) from /sws/neo/currency-format, mirroring
  the Vite dev plugin's composition.
- Tests: ported the functional repo's jsreport helpers builder parity suite
  (46 tests, includes new Function compilation of the emitted string) into
  cli/test; updated server-render.test.js currency assertions to the
  canonical es-ES grouped format.

Verified live against the etendo-jsreport container: print-sales-invoice
format=pdf now returns HTTP 200 with %PDF magic and the QR image embedded;
format=html unchanged.
@sonarscanetendo

Copy link
Copy Markdown

Passed Quality Gate passed

Issues

Measures

Project ID: etendosoftware_schema_forge_core_976a1e0b-4b24-4757-a2f4-8afa9a5e0289

View in SonarQube

@github-actions

Copy link
Copy Markdown
Contributor

📦 Preview packages published — dist-tag alpha

0.3.34-preview.feature-ETP-4908.20260814144445.3d351b1

To exercise the published-package path (no LOCAL_CORE), bump all
core pins to this preview in the functional repo and reinstall:

make bump-core-version VERSION=0.3.34-preview.feature-ETP-4908.20260814144445.3d351b1

Re-posted on each push to this branch; supersedes older previews.

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.

3 participants