Stock Corrections: Transfers, Deletes and Purchase Edits
Bug FixA deep audit of how stock is drawn from purchase batches turned up several ways the numbers could quietly drift. All are fixed.
🔄 Deleting a Stock Transfer: • The source batch was credited back twice, leaving it looking like it had more stock than it really did • Now reversed exactly once.
🏭 Deleting a Production Entry: • The ingredients were returned correctly, then a second pass wrongly credited them against sales instead • Now only the production counter moves.
🧾 Deleting a Purchase: • If the batch had been oversold, leftover allocation rows were stranded pointing at a purchase that no longer existed • Every allocation is now moved onto the remaining batches • And deleting a purchase whose stock has already been used by other transactions is now refused with a clear message rather than silently pulling your balance down twice.
✏️ Editing a Purchase Line: • Reducing a line below what has already been sold or consumed from it is now refused, naming the product, how much is already consumed and what you tried to enter • Removing a line that has any consumption behind it is blocked the same way.
⚡ Busy Branches: • Two sales landing at the same moment could overwrite each other's allocation counters • Those updates are now atomic — nothing gets lost under load.
🛠️ The Stock Report Fix Button: • Now restricted to superadmin, and every overwrite is written to stock history with the old and new value — it was previously the one untracked way a balance could change.
📊 Supplier-Wise Stock: • No longer double counts purchase returns.
Result: Stock balances stop drifting, and the ways they used to drift now refuse the operation instead.