Fix test without available property

This commit is contained in:
2022-04-07 07:53:25 +00:00
parent ed321d3895
commit a2280e50ec
2 changed files with 18 additions and 15 deletions

View File

@@ -13,17 +13,17 @@ import (
type CategoryWithBalance struct {
*postgres.GetCategoriesRow
Available numeric.Numeric
Activity numeric.Numeric
Assigned numeric.Numeric
AvailableLastMonth numeric.Numeric
Activity numeric.Numeric
Assigned numeric.Numeric
}
func NewCategoryWithBalance(category *postgres.GetCategoriesRow) CategoryWithBalance {
return CategoryWithBalance{
GetCategoriesRow: category,
Available: numeric.Zero(),
Activity: numeric.Zero(),
Assigned: numeric.Zero(),
GetCategoriesRow: category,
AvailableLastMonth: numeric.Zero(),
Activity: numeric.Zero(),
Assigned: numeric.Zero(),
}
}
@@ -157,16 +157,17 @@ func (h *Handler) calculateBalances(budget postgres.Budget, month Month,
}
moneyUsed.SubI(bal.Assignments)
categoryWithBalance.Available.AddI(bal.Assignments)
categoryWithBalance.Available.AddI(bal.Transactions)
if !categoryWithBalance.Available.IsPositive() && month.InPast(bal.Date) {
moneyUsed.AddI(categoryWithBalance.Available)
categoryWithBalance.Available = numeric.Zero()
}
if month.InPresent(bal.Date) {
categoryWithBalance.Activity = bal.Transactions
categoryWithBalance.Assigned = bal.Assignments
continue
}
categoryWithBalance.AvailableLastMonth.AddI(bal.Assignments)
categoryWithBalance.AvailableLastMonth.AddI(bal.Transactions)
if !categoryWithBalance.AvailableLastMonth.IsPositive() {
moneyUsed.AddI(categoryWithBalance.AvailableLastMonth)
categoryWithBalance.AvailableLastMonth = numeric.Zero()
}
}