Fix bin check zeroing bulk item quantities
Build and push image / build (push) Successful in 1m3s

Bin check was using count_last_audit (0 for bulk items) as the audit
value for all items. Now looks up product kind and uses
last_audit_weight for bulk items, only updates count_last_audit for
discrete items.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-06 18:37:43 -04:00
parent 5fa1e34914
commit 3674ecf328
+13 -3
View File
@@ -455,22 +455,32 @@ inventoryRouter.post("/bins/:id/check", (req, res) => {
const item = db
.prepare<
[string],
{ product_id: string; count_original: number; count_last_audit: number | null }
{ product_id: string; weight: number; last_audit_weight: number | null; count_original: number; count_last_audit: number | null }
>(
`SELECT product_id, count_original, count_last_audit FROM inventory_items WHERE id = ?`,
`SELECT product_id, weight, last_audit_weight, count_original, count_last_audit FROM inventory_items WHERE id = ?`,
)
.get(itemId);
if (!item) continue;
const prev = item.count_last_audit ?? item.count_original;
const product = db
.prepare<[string], { kind: string }>(`SELECT kind FROM products WHERE id = ?`)
.get(item.product_id);
const isDiscrete = product?.kind === "discrete";
const prev = isDiscrete
? item.count_last_audit ?? item.count_original
: item.last_audit_weight ?? item.weight;
db.prepare(
`INSERT INTO audits (inventory_id, date, mode, value, prev_value, confirmed_by)
VALUES (?, ?, 'presence', ?, ?, 'bin-check')`,
).run(itemId, date, prev, prev);
if (isDiscrete) {
db.prepare(
`UPDATE inventory_items SET count_last_audit = ? WHERE id = ?`,
).run(prev, itemId);
}
}
for (const itemId of goneItemIds) {
try {