From 8319b33c00b912c5f1bf5e61c08c1795788bcd5b Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Sun, 31 Aug 2025 19:12:53 +0100 Subject: [PATCH] Added the currency_affinity field to the configuration --- src/TODO.md | 9 ++++----- src/config.yaml | 2 ++ src/config/config.go | 22 +++++++++++++++------- src/expenses/app.go | 2 +- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/TODO.md b/src/TODO.md index 85649a8..c0a4af2 100644 --- a/src/TODO.md +++ b/src/TODO.md @@ -1,8 +1,6 @@ # DOING -Adding the field `Calculated` to `Share` to avoid computing what each user owes -everytime due to the fractional cents problem -Make a script for the current migration to compute the Calculated value with -our rules +- Make the dec.Decimal fields in the database actually be numbers, only if we +can keep the 2 decimal places # TODO - [ ] On the categories page, add a column of how many times a given category is @@ -10,7 +8,7 @@ used - [ ] Multiple categories per expense - [X] Make all the other items update/create page be like expenses - [ ] Ability to attach a document to an expense -- [ ] Debts table +~~- [ ] Debts table~~ - [ ] Ability to export data in multiple formats and with a selection of columns - [ ] Migrate every column named "ExpenseSomething" to "ExpSomething" - [ ] Make the models just return errors and not do any handling themselves @@ -22,6 +20,7 @@ used - [ ] Rename this file - [ ] Better UX when adding expenses on the payments and share values (default even split) - [ ] Verification popups for delete actions +- [ ] Users (auth) ### Stack - Go diff --git a/src/config.yaml b/src/config.yaml index e62f8e9..11c39e6 100644 --- a/src/config.yaml +++ b/src/config.yaml @@ -4,3 +4,5 @@ dbpath: "./data/data.db" dbsys: "sqlite3" migrations_path: "file://expenses/db/migrations/" mig_custom_scripts: "./expenses/db/migrations/custom/" +# How many decimal places the money we are working on has +currency_affinity: 2 diff --git a/src/config/config.go b/src/config/config.go index c9cecef..46d343b 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -8,12 +8,13 @@ import ( ) type Configuration struct { - AssetsDir string `yaml:"assets"` - Port string `yaml:"port"` - DBSys string `yaml:"dbsys"` - DBPath string `yaml:"dbpath"` - MigrationsPath string `yaml:"migrations_path"` - MigCustomScript string `yaml:"mig_custom_scripts"` + AssetsDir string `yaml:"assets"` + Port string `yaml:"port"` + DBSys string `yaml:"dbsys"` + DBPath string `yaml:"dbpath"` + MigrationsPath string `yaml:"migrations_path"` + MigCustomScript string `yaml:"mig_custom_scripts"` + CurrencyAffinity int32 `yaml:"currency_affinity"` } var ( @@ -24,6 +25,9 @@ var ( func GetInstance() *Configuration { once.Do(func() { + if instance != nil { + return + } instance = &Configuration{} instance.loadConfiguration() }) @@ -31,10 +35,14 @@ func GetInstance() *Configuration { return instance } -func SetConfig(path string) { +func SetConfPath(path string) { confPath = path } +func SetConfiguration(config *Configuration) { + instance = config +} + func (c *Configuration) loadConfiguration() { file, err := os.ReadFile(confPath) if err != nil { diff --git a/src/expenses/app.go b/src/expenses/app.go index d191b87..c4205e5 100644 --- a/src/expenses/app.go +++ b/src/expenses/app.go @@ -45,7 +45,7 @@ func StartLuaVM() (*lua.LState, error) { } func StartApp() error { - config.SetConfig("./config.yaml") + config.SetConfPath("./config.yaml") cfg := config.GetInstance() migDB, err := openDB(cfg.DBSys, cfg.DBPath, "")