Revert "Changed the code to use the currency_affinity value"

This reverts commit a67c103ccd.
This commit is contained in:
2025-08-31 19:35:30 +01:00
parent a67c103ccd
commit 05047af0c3
4 changed files with 4 additions and 21 deletions
+1 -4
View File
@@ -1,7 +1,6 @@
package expenses package expenses
import ( import (
"expenses/config"
mod "expenses/expenses/models" mod "expenses/expenses/models"
"sort" "sort"
@@ -102,8 +101,6 @@ func resolveDebt(creditor UserTab, debtors UserTabs) mod.Debts {
} }
func resolveDebts(debtors UserTabs, creditors UserTabs) mod.Debts { func resolveDebts(debtors UserTabs, creditors UserTabs) mod.Debts {
cfg := config.GetInstance()
keyedDebts := make(map[CompoundKey]dec.Decimal) keyedDebts := make(map[CompoundKey]dec.Decimal)
for _, creditor := range creditors { for _, creditor := range creditors {
@@ -124,7 +121,7 @@ func resolveDebts(debtors UserTabs, creditors UserTabs) mod.Debts {
newDebt := mod.Debt{ newDebt := mod.Debt{
Debtor: key.Debtor, Debtor: key.Debtor,
Creditor: key.Creditor, Creditor: key.Creditor,
Sum: debt.Truncate(cfg.CurrencyAffinity), // Removes fractional cents from the debt Sum: debt.Truncate(2), // Removes fractional cents from the debt
} }
// Only appends the debt if its not zero // Only appends the debt if its not zero
-5
View File
@@ -1,7 +1,6 @@
package expenses package expenses
import ( import (
"expenses/config"
mod "expenses/expenses/models" mod "expenses/expenses/models"
"fmt" "fmt"
"testing" "testing"
@@ -41,10 +40,6 @@ func TestFilterExpenseParticipants(t *testing.T) {
}, },
} }
// Need to set the config before running the tests
config.SetConfiguration(&config.Configuration{
CurrencyAffinity: 2,
})
for _, tt := range testCases { for _, tt := range testCases {
fmt.Printf("Running test: %s\n", tt.name) fmt.Printf("Running test: %s\n", tt.name)
debtors, creditors := filterExpenseParticipants(tt.exp) debtors, creditors := filterExpenseParticipants(tt.exp)
+2 -7
View File
@@ -1,9 +1,7 @@
package expenses package expenses
import ( import (
"expenses/config"
mod "expenses/expenses/models" mod "expenses/expenses/models"
dec "github.com/shopspring/decimal" dec "github.com/shopspring/decimal"
) )
@@ -50,9 +48,6 @@ func ParseFormShares(userIDs []string, shares []string, sharesIDs []string,
// NormalizeShares will take the total of an expense and the proposed shares // NormalizeShares will take the total of an expense and the proposed shares
// and calculate how much each user actually has to pay - avoids fracd cents // and calculate how much each user actually has to pay - avoids fracd cents
func (a *ExpensesApp) NormalizeShares(e *mod.Expense) error { func (a *ExpensesApp) NormalizeShares(e *mod.Expense) error {
cfg := config.GetInstance()
affi := cfg.CurrencyAffinity
excess := dec.NewFromFloat(0.0) excess := dec.NewFromFloat(0.0)
ownerShIdx := -1 ownerShIdx := -1
for k := range e.Shares { for k := range e.Shares {
@@ -60,9 +55,9 @@ func (a *ExpensesApp) NormalizeShares(e *mod.Expense) error {
ownerShIdx = k ownerShIdx = k
} }
owed := e.Value.Mul(e.Shares[k].Share) owed := e.Value.Mul(e.Shares[k].Share)
excess = excess.Add(owed.Sub(owed.Truncate(affi))) excess = excess.Add(owed.Sub(owed.Truncate(2)))
e.Shares[k].Calculated = owed.Truncate(affi) e.Shares[k].Calculated = owed.Truncate(2)
} }
// It fails here for some reason // It fails here for some reason
+1 -5
View File
@@ -1,7 +1,6 @@
package expenses package expenses
import ( import (
"expenses/config"
mod "expenses/expenses/models" mod "expenses/expenses/models"
"log" "log"
"time" "time"
@@ -146,9 +145,6 @@ func ExpenseTotalPayed(exp *mod.Expense) decimal.Decimal {
} }
func ExpenseIsEvenlyShared(exp *mod.Expense) bool { func ExpenseIsEvenlyShared(exp *mod.Expense) bool {
cfg := config.GetInstance()
affi := cfg.CurrencyAffinity
shares := mapShares(exp) shares := mapShares(exp)
payments := mapPayments(exp) payments := mapPayments(exp)
@@ -160,7 +156,7 @@ func ExpenseIsEvenlyShared(exp *mod.Expense) bool {
return false return false
} }
if !val.Truncate(affi).Equal(share.Truncate(affi)) { if !val.Truncate(2).Equal(share.Truncate(2)) {
return false return false
} }
} }