fix over consume by code, revert migration overconsume sell

This commit is contained in:
giovanni
2026-06-06 07:49:34 +07:00
parent 6d2b6a0cb8
commit 33bae94d43
4 changed files with 85 additions and 2 deletions
@@ -195,9 +195,12 @@ func (s *fifoStockV2Service) allocateInternal(ctx context.Context, tx *gorm.DB,
if remaining > 0 {
if !allowOverConsume {
return nil, fmt.Errorf("%w: requested %.3f, allocated %.3f", ErrInsufficientStock, req.NeedQty, result.AllocatedQty)
s.logger.Warnf("FIFO v2: clearing historical pending (%.3f) for %s/%d at PW=%d — over-consume is blocked by rule",
remaining, req.Usable.LegacyTypeKey, req.Usable.ID, req.ProductWarehouseID)
result.PendingQty = 0
} else {
result.PendingQty = remaining
}
result.PendingQty = remaining
}
if err := s.applyUsableDeltas(tx, *usableRule, req.Usable.ID, result.AllocatedQty, result.PendingQty); err != nil {