Merge branch 'fix/is-transfer-for-cut-over' into 'development'

fix: override is_transfer lookup for direct cut-over laying flocks

See merge request mbugroup/lti-api!373
This commit is contained in:
Adnan Zahir
2026-03-17 18:44:11 +07:00
2 changed files with 75 additions and 0 deletions
@@ -318,6 +318,7 @@ func (u *ProjectflockController) LookupProjectFlockKandang(c *fiber.Ctx) error {
dtoResult.IsTransition = isTransition dtoResult.IsTransition = isTransition
dtoResult.IsLaying = isLaying dtoResult.IsLaying = isLaying
} }
applyCutOverLayingLookupOverride(&dtoResult)
if withPopulation { if withPopulation {
population := dtoResult.AvailableQuantity population := dtoResult.AvailableQuantity
dtoResult.Population = &population dtoResult.Population = &population
@@ -344,6 +345,20 @@ func (u *ProjectflockController) LookupProjectFlockKandang(c *fiber.Ctx) error {
Data: dtoResult}) Data: dtoResult})
} }
func applyCutOverLayingLookupOverride(result *dto.ProjectFlockKandangDTO) {
if result == nil || result.ProjectFlock == nil || result.IsLaying || result.ChickInDate == nil {
return
}
category := strings.ToUpper(strings.TrimSpace(result.ProjectFlock.Category))
if category != strings.ToUpper(string(utils.ProjectFlockCategoryLaying)) {
return
}
result.IsTransition = false
result.IsLaying = true
}
func (u *ProjectflockController) Resubmit(c *fiber.Ctx) error { func (u *ProjectflockController) Resubmit(c *fiber.Ctx) error {
param := c.Params("id") param := c.Params("id")
req := new(validation.Resubmit) req := new(validation.Resubmit)
@@ -0,0 +1,60 @@
package controller
import (
"testing"
"time"
"gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/dto"
)
func TestApplyCutOverLayingLookupOverride(t *testing.T) {
t.Run("marks direct cut-over laying flock as laying", func(t *testing.T) {
chickinDate := time.Date(2025, time.August, 15, 0, 0, 0, 0, time.UTC)
result := &dto.ProjectFlockKandangDTO{
ChickInDate: &chickinDate,
ProjectFlock: &dto.ProjectFlockWithPivotDTO{
Category: "LAYING",
},
}
applyCutOverLayingLookupOverride(result)
if !result.IsLaying {
t.Fatalf("expected cut-over laying flock to be exposed as laying")
}
if result.IsTransition {
t.Fatalf("expected cut-over laying flock to stay out of transition")
}
})
t.Run("keeps transfer-based state when chickin is absent", func(t *testing.T) {
result := &dto.ProjectFlockKandangDTO{
ProjectFlock: &dto.ProjectFlockWithPivotDTO{
Category: "LAYING",
},
}
applyCutOverLayingLookupOverride(result)
if result.IsLaying {
t.Fatalf("expected lookup override to skip non cut-over laying flocks")
}
})
t.Run("does not change already laying lookup state", func(t *testing.T) {
chickinDate := time.Date(2025, time.August, 15, 0, 0, 0, 0, time.UTC)
result := &dto.ProjectFlockKandangDTO{
IsLaying: true,
ChickInDate: &chickinDate,
ProjectFlock: &dto.ProjectFlockWithPivotDTO{
Category: "LAYING",
},
}
applyCutOverLayingLookupOverride(result)
if !result.IsLaying {
t.Fatalf("expected laying state to remain true")
}
})
}