Implement classification redesign

This commit is contained in:
Lars Nolden
2026-09-11 22:46:17 +02:00
parent cc43a2f9a7
commit 87f052a3ea
23 changed files with 1602 additions and 296 deletions
+12 -4
View File
@@ -99,7 +99,7 @@ func (a *App) Preview(ctx context.Context, r PreviewRequest) (Preview, error) {
after := t.Enrichment
if r.Fields.Merchant {
after.MerchantID = proposal.Enrichment.MerchantID
if e = addProposal(&s.Data, proposal); e != nil {
if e = addProposal(&s.Data, proposal, t.Facts); e != nil {
p.Errors = append(p.Errors, ClassificationError{t.Facts.ID, e.Error()})
continue
}
@@ -175,16 +175,24 @@ func (a *App) ApplyPreview(ctx context.Context, id, rev string, ids []string) (S
}
needed := map[string]bool{}
for i, t := range s.Data.Transactions {
if selected[t.Facts.ID] {
s.Data.Transactions[i].Enrichment = changes[t.Facts.ID]
needed[changes[t.Facts.ID].MerchantID] = true
if !selected[t.Facts.ID] {
continue
}
s.Data.Transactions[i].Enrichment = changes[t.Facts.ID]
needed[changes[t.Facts.ID].MerchantID] = true
}
for _, m := range p.NewMerchants {
if needed[m.ID] {
s.Data.Merchants = append(s.Data.Merchants, m)
}
}
for _, t := range s.Data.Transactions {
if selected[t.Facts.ID] && t.Enrichment.MerchantID != "" {
// New merchants already carry their first alias; existing merchants
// learn only when the real matcher stays unambiguous.
LearnAlias(&s.Data, t.Facts, t.Enrichment.MerchantID)
}
}
state, err := a.commit(ctx, rev, s.Data)
if err != nil {
return State{}, err