FIX[BE]Stop adjusting target product warehouse quantity

Avoid double counting: population entries and ConsumeChickinStocks already update inventory. Pullet/layer for the flock will
be added via other flows (purchase, transfer, etc.)
This commit is contained in:
aguhh18
2025-12-31 11:43:03 +07:00
parent 42853aaac0
commit bec6a93152
@@ -612,15 +612,12 @@ func (s *chickinService) convertChickinsToTarget(ctx *fiber.Ctx, chickins []enti
totalQuantityAdded += quantityToConvert totalQuantityAdded += quantityToConvert
} }
if totalQuantityAdded > 0 { // NOTE: Tidak menambah target ProductWarehouse quantity karena:
if err := s.ProductWarehouseRepo.AdjustQuantities(ctx.Context(), map[uint]float64{ // 1. Ayam sudah dipakai (masuk population)
targetPW.Id: totalQuantityAdded, // 2. ProductWarehouse source sudah berkurang saat create chickin (ConsumeChickinStocks)
}, func(db *gorm.DB) *gorm.DB { // 3. Menambah quantity disini akan menyebabkan double count
return dbTransaction //
}); err != nil { // PULLET/LAYER untuk flock ini akan di-add lewat mekanisme lain (misal: purchase, transfer, dll)
return fmt.Errorf("failed to update target product warehouse quantity: %w", err)
}
}
return nil return nil
} }