Enhance tender estimated value resolution and add unit tests

- Updated the `ResolvedEstimatedValueAndCurrency` method to aggregate procurement lot values when the tender-level estimated value is not set, improving accuracy in value retrieval.
- Introduced the `AggregateProcurementLotEstimatedValue` function to sum estimated values from procurement lots and return the first found currency.
- Modified the `ToResponseWithLanguage` method to utilize the new estimated value resolution logic.
- Added unit tests for the new functionality, ensuring correct behavior for various scenarios in the `entity_test.go` and `budget_test.go` files.

This update improves the handling of estimated values in tenders, enhancing the overall reliability of the tender management system.
This commit is contained in:
Mazyar
2026-06-20 12:29:47 +03:30
parent 6fb57c41c1
commit 4cfca5aa55
7 changed files with 259 additions and 26 deletions
+40 -5
View File
@@ -305,20 +305,55 @@ func (t *Tender) GetMainOrganization() *Organization {
// HasEstimatedValue returns true if the tender has an estimated value
func (t *Tender) HasEstimatedValue() bool {
return t.EstimatedValue > 0
value, _ := t.ResolvedEstimatedValueAndCurrency()
return value > 0
}
// AggregateProcurementLotEstimatedValue sums lot-level estimated values and returns the first lot currency found.
func AggregateProcurementLotEstimatedValue(lots []ProcurementLot) (value float64, currency string) {
for _, lot := range lots {
if lot.EstimatedValue <= 0 {
continue
}
value += lot.EstimatedValue
if currency == "" {
currency = strings.TrimSpace(lot.Currency)
}
}
return value, currency
}
// ResolvedEstimatedValueAndCurrency returns the tender-level estimated value when set,
// otherwise aggregates procurement lot values for API and display use.
func (t *Tender) ResolvedEstimatedValueAndCurrency() (float64, string) {
if t == nil {
return 0, ""
}
if t.EstimatedValue > 0 {
return t.EstimatedValue, strings.TrimSpace(t.Currency)
}
value, currency := AggregateProcurementLotEstimatedValue(t.ProcurementLots)
if value > 0 {
if currency == "" {
currency = strings.TrimSpace(t.Currency)
}
return value, currency
}
return 0, strings.TrimSpace(t.Currency)
}
// GetFormattedEstimatedValue returns formatted estimated value with currency
func (t *Tender) GetFormattedEstimatedValue() string {
if !t.HasEstimatedValue() {
value, currency := t.ResolvedEstimatedValueAndCurrency()
if value <= 0 {
return ""
}
if t.Currency != "" {
return fmt.Sprintf("%.2f %s", t.EstimatedValue, t.Currency)
if currency != "" {
return fmt.Sprintf("%.2f %s", value, currency)
}
return fmt.Sprintf("%.2f", t.EstimatedValue)
return fmt.Sprintf("%.2f", value)
}
// UpdateStatus updates the tender status and updated timestamp