dedupe-inventory-allocations

command
v1.4.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Command dedupe-inventory-allocations removes duplicate inventory allocation rows written by replayed production-step scans, and returns the receipts they falsely closed out to `available`.

A production-step delivery is retried with backoff and replayed from the top. Before the step was made transactional, a failure partway through left its allocations committed, so the replay drew the same receipts a second time. The result is stock consumed on paper that never left the floor, and an on-hand figure well below what the plant actually holds.

What counts as a duplicate

Rows sharing (inventory_issue_id, inventory_receipt_id, unit, value). One allocation pass visits a receipt at most once and takes min(available, remaining), so two draws of an identical quantity from the same receipt to the same issue is the replay signature rather than anything the allocator produces on its own.

That test alone is not sufficient. An item consumed in many small equal increments accumulates identical (issue, receipt, value) rows legitimately, and deleting them would leave the issue short of what it actually drew. So a group is only deduplicated when the issue's allocations still cover its ordered quantity afterwards; issues that would end up under-allocated are reported and skipped.

The earliest row in each group is kept, along with its quantity, unit-cost and total-cost rows. The satellite rows of deleted allocations go with them: total_cost_id and quantity_id reference `quantity`, unit_cost_id references `rate`, and each is unique to its allocation.

Receipt re-statusing

An allocation that fully covered a receipt flipped it to `allocated`, which drops it out of on-hand entirely. Once the duplicates are gone the surviving allocations no longer cover those receipts, so any that are no longer fully drawn go back to `available` — the same rule FreeReleasedReceipts applies when a batch scan is undone.

Usage:

DB_URL=<dsn-or-mysql-url> go run ./cmd/dedupe-inventory-allocations --dry-run
DB_URL=<dsn-or-mysql-url> go run ./cmd/dedupe-inventory-allocations

Flags:

--dry-run   report what would change; make no writes.
--item      restrict to a single item id, for verifying the effect on one SKU first.
--limit     cap the number of duplicate groups processed (0 = no cap).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL