Introducing a new way to review your PRs.

Read the announcement

frappe / erpnext

Free and Open Source Enterprise Resource Planning (ERP)

View on GitHub

20 documents · Updated Nov 23, 2026

docs / stock-valuation-and-reposting

Stock valuation and reposting

Stock valuation turns each inventory movement into a running quantity and value for an item in a warehouse. Reposting replays that history when a backdated movement, a rate change, or a ledger correction makes later stock and accounting values stale. This page explains how the stock ledger, valuation rules, reconciliation tools, adjustment entries, and queued jobs work together to keep physical inventory and financial value aligned. See Inventory and warehouse operations for the wider stock domain, Inventory replenishment and traceability for stock identity and movement, and Financial transaction posting for the accounting side.

Stock ledger value model

The stock ledger is the time-ordered record of stock movement. Each Stock Ledger Entry (SLE) records the quantity change and the resulting balance for one item and warehouse. It also carries the valuation rate, balance value, value change, and—when the valuation method needs it—the current stock queue.

The ledger is stateful: a later entry uses the state left by the prior entry. The system orders entries by the stored posting datetime, then by creation time. A change inserted into the past can therefore change every later balance, rate, queue, and value change for the same item and warehouse.

Quantity and value effects

For each ledger entry, the system carries these related results forward:

Ledger resultMeaning
Actual quantityThe movement made by the voucher. A receipt is positive and an issue is negative.
Quantity after transactionThe running quantity after the movement.
Valuation rateThe rate used to value the balance at that point in time.
Stock valueThe value of the balance after the movement.
Stock value differenceThe change in stock value caused by the movement.
Stock queueThe remaining quantity layers and rates for queue-based valuation.

The ledger updates the related warehouse balance after it processes an entry. If no live ledger entry remains for an item and warehouse, the replay also clears that balance so the warehouse view does not retain stale quantity, rate, or value. In a company with perpetual inventory, where stock value posts to accounts as stock moves, the stock value difference also drives the matching accounting effect. A change in the ledger can therefore require both stock replay and General Ledger (GL) replay.

References: erpnext/…/stock_ledger.py• L1038-1225 erpnext/…/stock_ledger.py• L1504-1523 erpnext/…/stock_ledger.py• L2434-2465 erpnext/…/stock_ledger_entry.py• L43-82

Stock entry value allocation

The erpnext/…/stock_entry.py Stock Entry is the main source of movement rates for transfers, manufacturing, repacking, and adjustments. Outgoing rows use the value of stock at the source, while incoming rows receive a derived, selected, or manually entered rate. Manufacturing and repacking use the consumed value as the cost basis for finished goods and secondary items. A BOM-linked secondary item can receive a share of that cost, while a secondary item without a BOM link uses either its valuation rate or a manual rate.

Additional costs are spread across incoming rows and become part of their inventory value. The form refreshes rates when quantity, unit, warehouse, or serial and batch data changes. This keeps the amount shown on the Stock Entry aligned with the ledger value that is posted later.

References: erpnext/…/stock_entry.py• L585-725 erpnext/…/stock_entry.py• L800-877 erpnext/…/stock_entry.py• L928-981 erpnext/…/stock_entry.js• L1022-1051 erpnext/…/test_stock_entry.py• L683-755 erpnext/…/test_stock_entry.py• L1341-1568

Valuation methods

The item can define its valuation method. If it does not, the company setting or the stock setting supplies the default. The method controls how the system turns incoming rates and outgoing quantities into the next balance value.

MethodStock value model
FIFOConsumes the oldest incoming quantity first. The queue stores quantity and rate layers.
LIFOConsumes the newest incoming quantity first. The queue acts as a stack of layers.
Moving AverageRecalculates one running rate from the balance value and quantity.
Standard CostUses the standard rate effective on the posting date instead of a transaction queue. A posting before the latest effective standard rate is blocked.

Serial and batch bundles can supply their own incoming values. Batchwise valuation can value a batch separately. These paths still end in the same ledger balance model, so their quantity and value results must remain in step. Standard Cost has a separate path: a permitted backdated movement shifts later quantities and values at the effective standard rate without a queue-based rate replay.

References: erpnext/…/utils.py• L334-409 erpnext/…/valuation.py• L14-63 erpnext/…/stock_ledger.py• L104-186 erpnext/…/stock_ledger.py• L1289-1316 erpnext/…/stock_ledger.py• L1386-1454 erpnext/…/stock_ledger.py• L2851-2908

Accounting value effects

The stock ledger is the stock-side source for the value change of a stock transaction. When perpetual inventory is enabled, reposting finds the affected stock vouchers and refreshes their stock-related GL entries. It can also refresh vouchers that depend on the changed item and warehouse, including the stock-delivered-but-not-billed case.

The stock and account value comparison report groups both ledgers by voucher. It exposes a mismatch between the stock value change and the value in stock asset accounts. Journal Entries are not repaired by stock reposting because they have no stock ledger movement. Reposting also keeps payment-ledger entries and invoice outstanding amounts from being duplicated or changed by a stock-value refresh.

Accounting-only reposting is valid for a stock voucher that already has a stock-ledger source. A standalone GL Entry is rejected because it has no stock movement from which the system can rebuild its accounting value.

References: erpnext/…/repost_item_valuation.py• L116-127 erpnext/…/repost_item_valuation.py• L666-710 erpnext/…/stock_and_account_value_comparison.py• L27-81 erpnext/…/test_repost_item_valuation.py• L455-502

Stock reconciliation

Stock Reconciliation is the controlled correction path for a physical count or an opening balance. It compares the entered quantity and rate with the balance before the reconciliation, then posts only the difference needed to reach the entered state.

Physical balance correction

On submit, a reconciliation validates the item, warehouse, rate, and any serial or batch data. It creates stock ledger effects for quantity or value changes and posts the difference to the configured stock adjustment or opening account. It then asks the normal stock flow to repost later entries, because the correction changes the state used by those entries.

The document does not create work when a row already matches the current balance. An unset valuation rate means that the current rate is kept, while an explicit zero is treated as a real revaluation. The document also blocks a quantity change when the affected stock is reserved. For serialized or batched items, the correction uses the serial and batch record so that the physical identity of the stock matches the valued quantity. Inventory dimensions are limited to opening entries when they would change quantity or value.

Large reconciliations are submitted or cancelled as background actions. This keeps a large physical count from blocking the request while preserving the same ledger, accounting, and later-repost flow.

When a backdated change shifts future balances, the next relevant reconciliation is the boundary for that shift. A batch reconciliation is relevant when it counts the affected batch, including a batch recorded through its serial and batch bundle. A reconciliation for another batch does not stop the shift. This keeps a counted batch stable while allowing unrelated stock balances to carry the change forward.

The form makes generated Adjustment Entry rows and their purpose read-only. It also refreshes the displayed balance when the posting date, posting time, item, or warehouse changes, so the proposed correction is compared with the ledger state at the selected point.

References: erpnext/…/stock_reconciliation.py• L83-167 erpnext/…/stock_reconciliation.py• L940-990 erpnext/…/stock_reconciliation.py• L1521-1545 erpnext/…/stock_reconciliation.py• L992-1069 erpnext/…/stock_ledger.py• L2863-2918 erpnext/…/stock_ledger.py• L3006-3095 erpnext/…/test_stock_reconciliation.py• L2867-2907 erpnext/…/stock_reconciliation.js• L68-75 erpnext/…/stock_reconciliation.js• L184-255

Reconciliation value refresh

A submitted reconciliation can become stale after a backdated transaction changes its ledger entries. During reposting, the system recalculates the reconciliation's current quantity, current rate, amount difference, and total difference from the current ledger. The row amount difference is based on the sum of its live stock value changes, so the document and its GL effect use the same value.

Standard Cost items follow a separate rule: the effective standard rate owns their valuation. A reconciliation can set the first standard rate or create a new rate effective on its posting date. When the reconciliation is cancelled, the system cancels a rate that it created only if no stock activity on or after that effective date still uses the rate. This protects later stock entries while allowing a plain rate change with no later activity to be reversed.

The form refreshes the displayed quantity, valuation rate, amount, and serial or batch balance when the posting date, posting time, item, or warehouse changes. This lets the user compare the proposed correction with the ledger state at the selected point before submission.

References: erpnext/…/stock_reconciliation.py• L169-227 erpnext/…/stock_reconciliation.py• L1364-1519 erpnext/…/stock_ledger.py• L1550-1705 erpnext/…/stock_ledger.py• L2386-2413 erpnext/…/stock_reconciliation.js• L184-255

Valuation adjustment entries

An Adjustment Entry is a system-created Stock Reconciliation used by the Stock Valuation Comparison report when a closed history cannot be rewritten safely. It sets the stock and value from a chosen date forward while keeping the ledger before that date unchanged. Users cannot create this purpose by hand.

The adjustment plan describes the stock that should exist for each item and warehouse. It includes serial values, batch values, queue layers, moving-average stock, or the Standard Cost rate that applies on the adjustment date. Posting first counts out the old stock and then counts in the planned rows. The ledger marks these movements as adjustment entries so reports can show the reset as one net change instead of many internal movements.

The system validates the result against both quantity and value. It also blocks a stock transaction or cancellation dated before a later adjustment for the same item and warehouse or for the same serial numbers or batches. This boundary is needed because the adjustment deliberately makes the later ledger start from a new counted state.

References: erpnext/…/valuation_adjustment.py• L4-30 erpnext/…/valuation_adjustment.py• L103-247 erpnext/…/valuation_adjustment.py• L307-360 erpnext/…/valuation_adjustment.py• L363-470 erpnext/…/valuation_adjustment.py• L472-730 erpnext/…/stock_reconciliation.py• L121-160 erpnext/…/test_stock_reconciliation.py• L2478-2617

Closed-period boundaries

Normal reconciliation and reposting cannot rewrite stock or accounts inside a closed period. Stock closing entries and period closing vouchers establish a boundary. Account freeze dates add a second boundary for financial postings.

When an old value must be corrected without reopening that history, the valuation comparison flow can create an Adjustment Entry. The entry resets the state from its posting date onward and applies the difference through the configured adjustment account. This preserves the closed part of the ledger while giving later stock and financial reports a consistent value.

References: erpnext/…/stock_ledger.py• L189-233 erpnext/…/repost_item_valuation.py• L161-234 erpnext/…/stock_closing_entry.py• L28-55 erpnext/…/valuation_adjustment.py• L4-30

Reposting lifecycle

Reposting is the replay of a changed point in stock history and all later entries that depend on it. The replay restores the running quantity, valuation rate, stock value, stock queue, transaction rates, and related GL effects.

Reposting triggers

The system treats a stock transaction as backdated when a future entry exists for one of its item and warehouse pairs. It then creates a submitted Repost Item Valuation record instead of doing all future work during the original submit. Reposting can also start from a stock reconciliation, a landed cost change, a user request, or a diagnostic report.

Two scopes control the work:

  • Transaction: replay the voucher and the future stock state it affects.
  • Item and Warehouse: replay one item and warehouse from a chosen posting point.

An item-and-warehouse scope is useful when a ledger check finds a local inconsistency. A transaction scope is useful when a voucher changes rates or affects several item and warehouse pairs. Standard Cost entries use the fixed-rate future-balance path when a permitted backdated movement does not require a full valuation replay.

References: erpnext/…/stock_ledger_service.py• L219-250 erpnext/…/reposting.md• L3-19 erpnext/…/repost_item_valuation.json• L44-146 erpnext/…/stock_ledger.py• L2851-2908

Reposting queue

The Repost Item Valuation document is the durable work record for this process. It can represent work based on a transaction or on an item and warehouse. It also records whether the worker must refresh stock ledgers, accounting ledgers, or valuation rates. Transaction work can also request stock-ledger recreation or a fresh purchase valuation rate; these modes have their own validation and do not represent ordinary item-based replay. Only submitted records in Queued or In Progress state are eligible for processing. A normal job selects the oldest work by posting date and creation time, then moves each record through its result state.

StateMeaning
QueuedWork is waiting for a background job.
In ProgressA worker is replaying the ledger or GL, or a recoverable error left it ready for retry.
CompletedThe requested replay finished.
SkippedAnother replay covered the same work or the replay was not needed.
FailedA non-recoverable error stopped the replay.
CancelledThe work record was discarded or cancelled.

The record stores progress and compressed replay data so a long job can resume. Similar queued work is deduplicated. An older item-and-warehouse request can cover a newer duplicate, while unrelated item or warehouse work remains queued. Related item-and-warehouse requests can also be merged into one ordered pass when they share the same replay settings. A GL-only child record can wait for its source stock replay and then refresh only accounting ledgers. The queue also exposes separate progress for stock work and accounting work, so operators can see which part remains. The form starts queued submitted work in the background, shows these progress measures, and offers a restart action for failed work.

The checkpoint file is required when a replay resumes. If it is missing or corrupt, the system stops with an error instead of continuing with incomplete affected-voucher data.

References: erpnext/…/repost_item_valuation.json• L44-85 erpnext/…/repost_item_valuation.json• L121-270 erpnext/…/repost_item_valuation.py• L39-71 erpnext/…/repost_item_valuation.py• L300-385 erpnext/…/repost_item_valuation.py• L454-550 erpnext/…/repost_item_valuation.py• L778-815 erpnext/…/stock_ledger.py• L579-635 erpnext/…/repost_item_valuation.js• L44-167 erpnext/…/test_repost_item_valuation.py• L151-196 erpnext/…/test_repost_item_valuation.py• L1420-1451

Ledger replay

When a worker starts a replay, it begins with the last valid state before the changed point. It then processes affected entries in posting order. For each entry it recalculates the next quantity, rate, value, and queue, then updates downstream transaction rates when the source voucher needs them.

The replay follows dependent item and warehouse pairs. This matters for transfers, repacks, and manufacturing where one stock entry links more than one ledger stream. When a stock entry has additional costs, rate recalculation persists the redistributed cost across its incoming rows so the voucher and ledger use the same value. A serial or batch bundle replay uses the movement quantity recorded in the ledger, so a later change to bundle detail cannot change physical quantity during valuation repair. The worker records its position after progress so a timeout does not require it to start from the beginning.

Large replays keep only the identity and sort data for the pending work, then load complete ledger rows in small batches. The worker releases local caches as it saves progress. This limits memory use and the number of locked rows without changing the ordered replay.

When a manufacturing or repack replay also covers a dependent item and warehouse, later queued item-based work for that covered range can be skipped. Transaction-based work is skipped only when every affected item and warehouse stream is covered.

The flow from a backdated change to the final financial result is:

flowchart LR
    A[Backdated or changed stock transaction] --> B[Repost Item Valuation]
    B --> C[Replay affected stock ledger entries]
    C --> D[Update balances and transaction rates]
    D --> E[Find affected stock vouchers]
    E --> F[Replay stock-related GL entries]
    F --> G[Completed or recoverable queue state]

References: erpnext/…/stock_ledger.py• L436-503 erpnext/…/stock_ledger.py• L985-1208 erpnext/…/stock_ledger.py• L1504-1523 erpnext/…/stock_ledger.py• L1619-1628 erpnext/…/repost_item_valuation.py• L639-710 erpnext/…/test_repost_item_valuation.py• L730-950

Parallel jobs

The normal scheduler runs reposting hourly during its configured time slot. Parallel mode replaces that item-based drain with a 15-minute recovery scan and starts long jobs for independent item codes. The configured parallel count limits how many item codes are selected at once. Work for an item that already has an active item repost is excluded. Transaction work and accounting-only work are handled without the item-code grouping.

Each worker uses a stable job identity and deduplication. When a parallel worker finishes, it starts the next queue scan so the queue can drain without waiting for the next scheduler tick. A configured continuation also starts the next batch when the current worker exits with an error. The feature is available only with item-based reposting.

References: erpnext/hooks.py• L468-494 erpnext/…/repost_item_valuation.py• L1041-1161 erpnext/…/stock_reposting_settings.py• L43-70 erpnext/…/test_repost_item_valuation.py• L1015-1090 erpnext/…/test_repost_item_valuation.py• L1481-1556

Consistency safeguards

Stock values are safe only when the ledger order, physical quantity, valuation state, and accounting result agree. The system uses validation before posting, locks during concurrent work, and reports after posting to protect those relationships.

Posting and concurrency controls

Stock writes are serialized by item and warehouse where the database needs an explicit gate. Background reposts lock complete ledger rows in small ordered batches. This prevents two workers from calculating from the same old balance and losing one worker's result while avoiding a lock over an entire large history.

The system also checks negative stock, reserved stock, warehouse and company links, inventory dimensions, standard-cost effective dates, stock freeze dates, and later valuation adjustments. A cancellation uses reverse ledger effects rather than deleting the original ledger history. Reposting writes only valuation and balance fields to an active SLE, so an entry cancelled while the replay is running is not revived. Reposting keeps the submitted ledger quantity as the physical movement even if a serial or batch bundle is later changed.

References: erpnext/…/stock_ledger.py• L104-233 erpnext/…/stock_ledger.py• L1068-1089 erpnext/…/stock_ledger.py• L1504-1523 erpnext/…/stock_ledger.py• L1619-1628 erpnext/…/stock_ledger_entry.py• L94-172 erpnext/…/valuation_adjustment.py• L892-948

Failure recovery

Deadlocks, lock waits, query timeouts, and job timeouts are recoverable failures. The queue keeps such work in In Progress so a later run can retry it. Other failures become Failed, retain an error log, and can notify the configured role. A failed record can be restarted after the cause is fixed, and the restart action checks that the caller has write permission on the repost record.

The queue commits progress during long replays and removes its temporary replay file after completion. This limits the cost of a retry and leaves an operator-visible record when a replay needs attention. Stable job identities also prevent a retry or chained worker from creating duplicate queue jobs.

References: erpnext/…/repost_item_valuation.py• L36-37 erpnext/…/repost_item_valuation.py• L287-316 erpnext/…/repost_item_valuation.py• L554-629 erpnext/…/repost_item_valuation.py• L754-786 erpnext/…/repost_item_valuation.py• L852-871 erpnext/…/test_repost_item_valuation.py• L362-391 erpnext/…/test_repost_item_valuation.py• L1064-1090

Ledger diagnostics

The diagnostic reports compare different parts of the same stock story:

ReportMain question
Stock Ledger Invariant CheckDoes each entry's quantity, value, rate, and queue agree with its running state?
Stock Ledger VarianceWhich item and warehouse first show a ledger inconsistency?
Incorrect Stock ValueDoes each stock value equal the prior value plus the entry's value change?
Stock and Account Value ComparisonDoes each voucher's stock value match its stock asset account value?

The weekly auto-repost option can create item-and-warehouse work for current-year ledger variance and can create transaction or item-and-warehouse work for stock-account mismatches. It does not repost Journal Entries. If a warehouse points to a non-Stock account, the system reports the configuration problem instead of creating a replay that cannot fix the mismatch. The comparison flow can offer an Adjustment Entry when reopening the affected history is not safe.

References: erpnext/…/stock_ledger_invariant_check.py• L40-150 erpnext/…/incorrect_stock_value_report.py• L28-92 erpnext/…/stock_reposting_settings.py• L132-197 erpnext/…/stock_reposting_settings.py• L202-313 erpnext/…/valuation_adjustment.py• L103-130

Change checklist

When these files or sections are changed, remember to consider these:

  • If ledger fields or valuation rules change, check the running quantity, balance value, queue state, and value difference together. The invariant and variance reports depend on all four.
  • If ledger ordering or posting datetime storage changes, check both the replay boundary and the tie-break by creation time. Backdated entries must use the stored ledger position.
  • If the ledger can become empty for an item and warehouse, check that the related Bin is reset for quantity, valuation rate, and stock value. A normal replay may have no prior ledger state to update.
  • If Standard Cost rules change, check the latest effective-date validation, the reconciliation-created rate, and the lighter future-balance update path. A permitted backdated entry must not cause an unnecessary queue replay.
  • If a reconciliation can create or cancel a standard rate, check that later stock activity prevents cancellation of a rate that is still in use. Also check that an explicit zero rate remains a real revaluation and that an unset rate keeps the current rate.
  • If a reconciliation's ledger refresh changes, check that row and total difference amounts still equal live stock_value_difference values and that the GL uses the same source.
  • If future balance shifts or next-reconciliation selection changes, check the boundary for the affected batch, including batches stored in serial and batch bundles. A change before a batch reconciliation must keep that counted batch stable while still shifting unrelated later balances.
  • If Adjustment Entry rules change, check report-created plans, lot and serial coverage, count-out and count-in netting, result validation, and the boundary against later backdated transactions.
  • If repost scope or queue status changes, check scheduler selection, duplicate suppression, resume data, cancellation behavior, the stock-only and accounting-only options, and the GL-only child flow.
  • If repost checkpoints or attached replay files change, check that progress cannot resume with missing or corrupt affected-voucher data, and that files are removed only after the replay is complete.
  • If a whitelisted repost action changes, check write permission before it resets or restarts queue work.
  • If a new voucher can affect stock, check its stock ledger creation, future-entry detection, dependent voucher discovery, transaction-rate refresh, and accounting repost path.
  • If stock entry cost allocation changes, check that recalculated additional costs remain persisted on all affected incoming rows and match the replayed stock value.
  • If manufacturing or repacking cost rules change, check the source of consumed cost, BOM-linked percentage allocation, BOM-less secondary item modes, and the treatment of a real zero consumed cost.
  • If serial or batch bundle handling changes, check that reposting updates value and rate without changing the submitted physical movement quantity.
  • If closing or freeze rules change, check both synchronous stock posting and queued repost validation. A job must not bypass a closed stock or accounting period.
  • If warehouse account rules change, check the stock/account comparison and the weekly auto-repost guard for non-Stock accounts.
  • If parallel settings change, check item-based mode, active-job filtering by item code, stable job identity, transaction and accounting-only handling, database locking, and the 15-minute recovery scan.
  • If repost coverage or dependent discovery changes, check that manufacturing and repack work skips only item-based requests whose full affected range is already covered.
  • If accounting-only repost validation changes, check that the source voucher has stock-ledger entries and that standalone GL Entries cannot create empty accounting replacements.
  • If replay batching changes, check ordered processing, row locking, resume state, queue re-sorting after dependent discovery, and memory release during long jobs.

Important failure modes

TriggerConsequenceGuard
A backdated entry is posted without replaying future entriesLater rates, queues, stock values, and GL values remain staleFuture-entry detection creates a Repost Item Valuation work record.
A backdated cost change shifts balances through a later reconciliation that counts the affected batchThe counted batch can lose the quantity or value that the reconciliation establishedFuture balance updates stop at the next reconciliation for that batch, while unrelated batch reconciliations do not stop the shift.
A Standard Cost entry is dated before the latest effective standard rateThe entry would sit behind a rate revaluation and make the on-hand snapshot stalePosting validation rejects the entry before it reaches the ledger.
A reconciliation creates a standard rate that later stock activity still uses, then the reconciliation is cancelledCancelling the rate would corrupt the valuation of later stockCancellation checks for stock activity on or after the rate's effective date before cancelling the source rate.
An Adjustment Entry is created from incomplete or stale valuation dataThe reset can set stock to the wrong serials, batches, quantity, or valueThe entry is system-only, validates its rows against a current plan, and checks the final ledger balance.
A transaction is posted before a later Adjustment Entry for the same stockThe later reset no longer has a valid state boundaryPosting and cancellation are blocked before the adjustment date.
Two workers replay the same item and warehouse at onceOne worker can calculate from an old state and overwrite the other resultPer-item work selection and ordered row locks serialize the work.
The last live ledger entry for an item and warehouse is cancelled or removedThe Bin can retain stale quantity, valuation rate, or stock value after the ledger is emptyReplay checks for the absence of live entries and resets the Bin values to zero.
A replay reaches a closed stock or accounting periodA closed report or ledger could be changedClosing-entry, period-closing, and account-freeze checks reject the replay.
Stock and account values differ because the warehouse uses a non-Stock accountReposting cannot make the two values agreeThe weekly repair scan alerts System Managers instead of retrying ineffective work.
A worker times out or hits a deadlockThe replay stops before all entries are processedRecoverable errors keep the work retryable and progress is saved during long jobs.
A replay resumes with a missing or corrupt checkpoint fileA later GL refresh could omit vouchers affected by the stock replayResume fails loudly and requires a restart that regenerates the replay data.
A user without write permission restarts repostingQueue progress can be reset by an unauthorized userThe whitelisted restart action checks write permission before changing the record.
A physical correction changes reserved stockFulfillment reservations no longer describe available stockStock Reconciliation blocks the quantity change until the reservation is released.
A serial or batch bundle is edited after its stock movement is submittedA valuation repair could change the physical balance while it recalculates valueReposting uses the submitted Stock Ledger Entry movement quantity.
A GL-only repost targets a standalone GL EntryExisting GL rows can be removed without a stock source to rebuild themRepost Item Valuation rejects GL-only work for GL Entry vouchers.
A long replay keeps every full ledger row or cached source document in memoryThe worker can exhaust memory before it finishesReposting queues sort keys, loads complete rows in batches, and releases local caches at progress points.
A dependent manufacturing or repack stream is replayed while its later duplicate remains queuedThe same finished-good history is replayed more than onceCovered item-based requests are marked Skipped after the dependent stream is replayed.
A submitted reconciliation keeps its old difference after a backdated valuation changeThe document display and its GL effect can disagreeReposting rebuilds row and total differences from live ledger value changes.

Key files

FileWhy to read it
erpnext/…/stock_ledger.pyCentral ledger replay rules, valuation updates, dependent streams, locks, Bin resets, Standard Cost handling, batch-aware reconciliation boundaries, batch loading, and transaction-rate refresh.
erpnext/…/valuation.pyThe shared FIFO and LIFO queue model and its balance value calculation.
erpnext/…/valuation_adjustment.pySystem-created valuation adjustment plans, reset entries, report netting, and the boundary against later backdated stock.
erpnext/…/utils.pyThe precedence for choosing an item's valuation method and fallback rates.
erpnext/…/stock_ledger_service.pyThe boundary between stock vouchers, ledger entries, and repost requests.
erpnext/…/stock_ledger_entry.pyPosting checks for frozen stock, inventory dimensions, backdated transactions, and later valuation adjustments.
erpnext/…/repost_item_valuation.jsonThe queue contract, work scope, progress fields, stock and accounting replay options, and operator-visible states.
erpnext/…/repost_item_valuation.pyQueue states, replay lifecycle, permission checks, GL replay, retry behavior, deduplication, coverage, checkpoint handling, and parallel jobs.
erpnext/…/repost_item_valuation.jsThe user-facing scope selection, background start action, restart action, and live progress display.
erpnext/…/stock_reconciliation.pyPhysical count correction, valuation differences, Standard Cost changes, large-document jobs, and reconciliation refresh after reposting.
erpnext/…/stock_reconciliation.jsThe balance lookup and display rules that keep reconciliation rows aligned with the selected stock state, including generated adjustment-entry protection.
erpnext/…/test_stock_reconciliation.pyRegression coverage for backdated quantity and value replay, serialized and batched stock, batch reconciliation boundaries, adjustment entries, zero-value revaluation, and reconciliation differences that match GL impact.
erpnext/…/test_stock_ledger_entry.pyRegression coverage for ledger order, valuation queues, transfer rates, future balance shifts, cancellation races, and precision behavior.
erpnext/…/stock_reposting_settings.pyReposting schedule, parallel mode, and weekly automatic repair policy.
erpnext/…/stock_ledger_invariant_check.pyThe main internal consistency checks for quantities, values, rates, and queues.
erpnext/…/stock_and_account_value_comparison.pyThe stock-ledger to GL comparison used for financial reconciliation and valuation adjustment proposals.
erpnext/hooks.pyThe scheduler entries that run normal, parallel, and weekly valuation repair work.