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.
This commit is contained in:
+4
-5
@@ -2003,7 +2003,7 @@ func (cn ContractNotice) GetBudget() (amount string, currency string) {
|
||||
}
|
||||
|
||||
func budgetFromProcurementLots(lots []ProcurementProjectLot) (amount string, currency string) {
|
||||
var total float64
|
||||
amounts := make([]valuedAmount, 0, len(lots))
|
||||
for i := range lots {
|
||||
pp := lots[i].ProcurementProject
|
||||
if pp == nil || pp.RequestedTenderTotal == nil {
|
||||
@@ -2017,11 +2017,10 @@ func budgetFromProcurementLots(lots []ProcurementProjectLot) (amount string, cur
|
||||
if !ok || value <= 0 {
|
||||
continue
|
||||
}
|
||||
total += value
|
||||
if currency == "" {
|
||||
currency = lotCurrency
|
||||
}
|
||||
amounts = append(amounts, valuedAmount{value: value, currency: lotCurrency})
|
||||
}
|
||||
|
||||
total, currency := aggregateSameCurrencyAmounts(amounts)
|
||||
if total <= 0 {
|
||||
return "", ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user