سامانه صدور فاکتور و حسابداری

docs: record explicit active tenant sync requirement

davoodmehraban89 committed Nov 17, 2026 at 14:00 UTC f07762134e9cc2c5460e70160f16bd4f3ad4135d
1 file changed +5
PROJECT_STATE.md
+5
@@ -365,3 +365,8 @@ Owner requests layer-by-layer click/functional testing of all controls and compa
365 - Remaining confirmed gap: `js/invoices.js::finalizeInvoiceDocument` and `js/purchases.js::finalizePurchasePilotDraft` still call `jePostSourceRecord`, whose `jeAutoPost` path locally creates/posts journal rows and later relies on generic `finora_sync_records`. `js/sync.js::computeDiff/runSync` still includes `journalVouchers`, `journalLines`, and `journalLineDimensions`.
366 - Server-side `public.finora_journal_autopost` already exists for sale/purchase in migration `20261016103100_phase1a_autopost_server_authority.sql`; it validates persisted source identity/version, derives authoritative posting lines from the approved account-role snapshot, compares client line sets when supplied, enforces idempotent replay, and posts atomically with the journal rows. It requires the source business record to be persisted first. Therefore the next implementation is a narrow client orchestration adapter: flush/persist the draft source without dirty generic journal diffs, call the dedicated auto-post RPC, reconcile the returned voucher, then persist only the source-to-voucher link/status. Preserve retry safety when the RPC committed but its response/refresh was lost.
367 - No direct writes to journal collections through generic sync are to be introduced. Do not globally remove journal collections from generic sync until every legacy producer and correction/reversal path is migrated and regression-tested. No new migration or Production operation is required for this client package.
368 +
369 +
370 +### 2026-11-17 — Active-tenant scope required for source-draft flush
371 +- During implementation review, `runSync` was found to call the two-argument `finora_sync_records` overload, which falls back to `private.default_organization_id()`. The journal/source adapter already knows the active `currentUser.organizationId`; relying on a default tenant is unsafe for a user switching between multiple organizations.
372 +- This package therefore also changes the generic sync call to pass the explicit active `p_organization_id` through the existing three-argument overload (the WP1 migration retains the two-argument compatibility overload). Add a regression assertion for explicit tenant scope. This is a client-only use of an existing RPC signature; no new schema change.