Let imports opt out of AI classification
Classification preferences gains "Classify newly imported transactions with AI", stored as classify_on_import in config.toml and on by default, so existing configurations keep their behaviour. It covers CSV imports and bank synchronization alike. With it off, no import path contacts the provider: classification falls to the new provider-free rules path, where an opted-in merchant rule still applies its category and tags, an alias match still attaches its merchant, and everything else arrives on the editable fallback without a provenance error that would suggest the provider had failed. Analyse remains available on demand.
This commit is contained in:
+15
-3
@@ -20,9 +20,13 @@ import (
|
||||
"finance-duck/internal/journal"
|
||||
)
|
||||
|
||||
// Settings holds preferences only, never credentials. ClassifyOnImport controls
|
||||
// whether newly imported transactions are sent to the model at all; merchant
|
||||
// rules always apply.
|
||||
type Settings struct {
|
||||
Model string `json:"model"`
|
||||
IncludeAmount bool `json:"include_amount"`
|
||||
Model string `json:"model"`
|
||||
IncludeAmount bool `json:"include_amount"`
|
||||
ClassifyOnImport bool `json:"classify_on_import"`
|
||||
}
|
||||
type Status struct {
|
||||
SyncError string `json:"sync_error"`
|
||||
@@ -74,6 +78,9 @@ func Open(dir string) (*App, error) {
|
||||
return nil, err
|
||||
}
|
||||
a := &App{dir: dir, journal: j, previews: make(map[string]Preview), csvImports: make(map[string]CSVImport), authStates: make(map[string]authorization), syncRequested: make(chan struct{}, 1)}
|
||||
// Configurations written before this preference existed keep classifying
|
||||
// imports; only an explicit key switches it off.
|
||||
a.settings.ClassifyOnImport = true
|
||||
fail := func(e error) (*App, error) { j.Close(); return nil, e }
|
||||
if err = os.MkdirAll(filepath.Join(dir, "state"), 0700); err != nil {
|
||||
return fail(err)
|
||||
@@ -98,6 +105,8 @@ func Open(dir string) (*App, error) {
|
||||
a.settings.Model, err = strconv.Unquote(v)
|
||||
case "include_amount":
|
||||
a.settings.IncludeAmount, err = strconv.ParseBool(v)
|
||||
case "classify_on_import":
|
||||
a.settings.ClassifyOnImport, err = strconv.ParseBool(v)
|
||||
default:
|
||||
err = fmt.Errorf("unknown setting %q", k)
|
||||
}
|
||||
@@ -326,7 +335,10 @@ func (a *App) SaveSettings(ctx context.Context, s Settings) (State, error) {
|
||||
if len(s.Model) > 200 {
|
||||
return State{}, errors.New("model name is too long")
|
||||
}
|
||||
b := []byte("# Preferences only. Manage secrets in Settings or environment variables, never this file.\nclassification_model = " + strconv.Quote(s.Model) + "\ninclude_amount = " + strconv.FormatBool(s.IncludeAmount) + "\n")
|
||||
b := []byte("# Preferences only. Manage secrets in Settings or environment variables, never this file.\n" +
|
||||
"classification_model = " + strconv.Quote(s.Model) + "\n" +
|
||||
"include_amount = " + strconv.FormatBool(s.IncludeAmount) + "\n" +
|
||||
"classify_on_import = " + strconv.FormatBool(s.ClassifyOnImport) + "\n")
|
||||
if err := atomicFile(filepath.Join(a.dir, "config.toml"), b); err != nil {
|
||||
return State{}, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user