Revert "Changed the code to use the currency_affinity value"
This reverts commit a67c103ccd.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package expenses
|
||||
|
||||
import (
|
||||
"expenses/config"
|
||||
mod "expenses/expenses/models"
|
||||
"sort"
|
||||
|
||||
@@ -102,8 +101,6 @@ func resolveDebt(creditor UserTab, debtors UserTabs) mod.Debts {
|
||||
}
|
||||
|
||||
func resolveDebts(debtors UserTabs, creditors UserTabs) mod.Debts {
|
||||
cfg := config.GetInstance()
|
||||
|
||||
keyedDebts := make(map[CompoundKey]dec.Decimal)
|
||||
|
||||
for _, creditor := range creditors {
|
||||
@@ -124,7 +121,7 @@ func resolveDebts(debtors UserTabs, creditors UserTabs) mod.Debts {
|
||||
newDebt := mod.Debt{
|
||||
Debtor: key.Debtor,
|
||||
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
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package expenses
|
||||
|
||||
import (
|
||||
"expenses/config"
|
||||
mod "expenses/expenses/models"
|
||||
"fmt"
|
||||
"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 {
|
||||
fmt.Printf("Running test: %s\n", tt.name)
|
||||
debtors, creditors := filterExpenseParticipants(tt.exp)
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package expenses
|
||||
|
||||
import (
|
||||
"expenses/config"
|
||||
mod "expenses/expenses/models"
|
||||
|
||||
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
|
||||
// and calculate how much each user actually has to pay - avoids fracd cents
|
||||
func (a *ExpensesApp) NormalizeShares(e *mod.Expense) error {
|
||||
cfg := config.GetInstance()
|
||||
affi := cfg.CurrencyAffinity
|
||||
|
||||
excess := dec.NewFromFloat(0.0)
|
||||
ownerShIdx := -1
|
||||
for k := range e.Shares {
|
||||
@@ -60,9 +55,9 @@ func (a *ExpensesApp) NormalizeShares(e *mod.Expense) error {
|
||||
ownerShIdx = k
|
||||
}
|
||||
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
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package expenses
|
||||
|
||||
import (
|
||||
"expenses/config"
|
||||
mod "expenses/expenses/models"
|
||||
"log"
|
||||
"time"
|
||||
@@ -146,9 +145,6 @@ func ExpenseTotalPayed(exp *mod.Expense) decimal.Decimal {
|
||||
}
|
||||
|
||||
func ExpenseIsEvenlyShared(exp *mod.Expense) bool {
|
||||
cfg := config.GetInstance()
|
||||
affi := cfg.CurrencyAffinity
|
||||
|
||||
shares := mapShares(exp)
|
||||
payments := mapPayments(exp)
|
||||
|
||||
@@ -160,7 +156,7 @@ func ExpenseIsEvenlyShared(exp *mod.Expense) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if !val.Truncate(affi).Equal(share.Truncate(affi)) {
|
||||
if !val.Truncate(2).Equal(share.Truncate(2)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user