How Does the Dropshipping Stock Ledger Work?
Learn IHASHOP Dropshipping stock ledger, expected stock, order events, write traces and stock conflicts.
What is the stock ledger?
IHASHOP Dropshipping 1.0.0 uses the stock ledger in real mode to distinguish normal order movements from unexpected stock differences. In reviewed b817b5d9 it is not a separate movement table. Net totals come from ds_order_allocations. Shadow mode does not perform this check.
Stock reference and calculation
core_stock_written is the last stock reference. ledger_net_at_write is the net ledger at that reference. D = sum(deducted_qty − restored_qty). Expected core B = W − (D − D0), W last reference, D0 ledger at reference. Actual stock is compared with B. Target S = max(0, K − T − R), stored source stock minus buffer and reserve. These calculations serve different purposes.
D may be negative. core_stock_written_at records reference time and may refresh without physical writing. Expected stock is not clamped to zero.
Order and return events
TahsisTarayici reads order items for active variant links. Cutoff is stok_yazim_baslangic. Web deduction uses stock_deducted_at. If absent, marketplace ID and created_at are used for marketplace orders. Deductions at or after cutoff enter deducted_qty. Cancellation and restocked returns contribute restored_qty. Earlier sale cancelled later may create ledger-only row: 0 − 2 = −2. order_item_id is unique.
Repeating unchanged events creates no duplicate. forwarded state remains. No double-restoration guard exists in the cancellation and return sum. Reserve includes qualifying positive net quantities; ledger sums all allocations.
Transaction safety
StokYazici uses a short DB transaction per link. Normally first query calls CekirdekStokYaziciUygulama::kilitle with FOR UPDATE on a variant and non-deleted parent join. Next active link is locked. Sales state and trace are reread. Orders are rescanned, existing allocations locked and ledger calculated. Core order rows are not locked.
Design aims to see committed sale deductions; it does not guarantee concurrency safety for every external writer. Source stock and initial trash information are read before the loop. A link that becomes inactive is skipped. Model write and trace share link transaction. Individual errors are counted and others may continue. Closed Seller gate stops remaining writes and marks kismi.
Decision order and first takeover
StokKarari first handles cop or cekirdek_yok. Blocked variant link, missing source or null stock gives S=0. With trace, actual stock is compared against expected first. Mismatch gives cakisma and no write. Next zero or negative stock to positive target requires freshness. Skipped source gives acilis_ertelendi. Without trace ilk_devralma accepts target without prior stock comparison. Initial writing may replace external value.
Equal target avoids model write but establishes trace. Freshness refers to skipped external product IDs in run, not general age limit.
Unchanged stock and conflicts
With trace and target equal to actual, decision is yazmazdi. If reference or ledger changed, trace refreshes; if both match, trace stays unchanged. W=10, D0=0, D=3, C=7, S=7 yields new trace W=7, D0=3. W−D0 stays 10. No model write needed. Different target with successful checks yields yazardi, writing ProductVariant stock and updating product aggregate. Observers may trigger marketplace pending and stock notifications.
Conflict preserves external stock. Open variant is blocked stock_conflict; existing reason remains. Open sales alone cannot clear stock_conflict. Controlled Take over stock, successful zero-target real sync and administrator opening are needed. Equal net stock does not prove absence of external movements; offsetting changes may be invisible.
GiyimDepom and Luxstoree examples
Illustrative GiyimDepom: last reference 30, ledger then 4. Five new sales and two restored units give D=7. Expected 30 − (7 − 4) = 27. Actual 27, source 35, buffer 5, reserve 3 gives target 27. yazmazdi refreshes trace to 27/7. Luxstoree: W=20, D0=2, D=5; expected 17. External stock 23 gives cakisma. Even with source target 12, 23 remains. Open link becomes stock_conflict. Not live data; open links and other checks assumed.
GiyimDepomLuxstoree30 − (7 − 4) = 2720 − (5 − 2) = 1735 − 5 − 3 = 2723 ≠ 17yazmazdi: 27/7cakisma: 23Tests and safe operation
StokDefteriTest 138–166 covers first takeover, aggregate, observers and no equal-stock model write. 167–190 covers skipped-source strict opening; 191–223 sales, cancellation and partial return; 224–290 external stock and existing reason; 308–355 cutoff, marketplace and repeat scan; 503–518 decision table. Tests were not rerun. Inspect stats.stok.sayilar: ilk_devralma, yazardi, yazmazdi, cakisma, yazilan, hata and kismi.
Report shows at most 50 selected examples. nm includes supplier feed delay and marketplace zero-stock deduction. Verify actual inventory and storefront purchasability separately.
Related guides
- How Do Dropshipping Order Stock Reservations Work?
- How Does the Dropshipping Stock Safety Buffer Work?
- How to Use Shadow Stock and Real Stock Modes
- How Does Dropshipping Stock Management Work?
- How to Manage Dropshipping Sales Blocks
- How to Integrate GiyimDepom Dropshipping with IHASHOP
- How to Integrate Luxstoree Dropshipping with IHASHOP
- IHASHOP Dropshipping
Frequently asked questions
Is ledger a separate movement table?
No; it sums order allocations.
Is expected stock the target?
No; expected stock detects conflicts and target determines writing.
Can unchanged stock refresh trace?
Yes, if reference or ledger changed.
Does conflict erase external stock?
No; writing stops and open link is blocked.
Does initial takeover compare previous stock?
No prior trace exists; other safety checks still apply.