Files
Mazyar ee5414bc10 Enhance procurement lot estimated value aggregation and add unit tests
- Updated the `AggregateProcurementLotEstimatedValue` function to reject mixed currencies and allow empty lot currencies, ensuring accurate aggregation of estimated values.
- Introduced new unit tests in `entity_test.go` to validate the behavior of the aggregation function under various scenarios, including mixed currencies and empty lot currencies.
- Refactored budget calculation in `budget_test.go` to utilize the new aggregation logic, improving consistency in budget retrieval.

This update improves the handling of estimated values in procurement lots, enhancing the reliability of the tender management system.
2026-06-21 09:41:33 +03:30

42 lines
791 B
Go

package ted
import "strings"
type valuedAmount struct {
value float64
currency string
}
// aggregateSameCurrencyAmounts sums values only when every non-empty currency matches.
// Lots with an empty currency are included; conflicting currencies yield zero.
func aggregateSameCurrencyAmounts(amounts []valuedAmount) (total float64, currency string) {
var refCurrency string
for _, item := range amounts {
if item.value <= 0 {
continue
}
c := strings.TrimSpace(item.currency)
if c == "" {
continue
}
if refCurrency == "" {
refCurrency = c
continue
}
if c != refCurrency {
return 0, ""
}
}
for _, item := range amounts {
if item.value <= 0 {
continue
}
total += item.value
}
if total <= 0 {
return 0, ""
}
return total, refCurrency
}