Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

Commit

Permalink
repopulate transactions partly done
Browse files Browse the repository at this point in the history
  • Loading branch information
72nd committed Jul 26, 2020
1 parent 7a7a60f commit 435ec41
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ func main() {
s.Expenses.Repopulate(s)
s.Invoices.Repopulate(s)
s.MiscRecords.Repopulate(s)
s.Statement.Repopulate(s)
s.Save()
return nil
},
Expand Down
6 changes: 6 additions & 0 deletions pkg/schema/statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ func (t Statement) TransactionSearchItems() util.SearchItems {
return result
}

func (t Statement) Repopulate(s Schema) {
for i := range t.Transactions {
t.Transactions[i].Repopulate(s)
}
}

func (t *Statement) AssistedCompletion(s Schema, doAll, autoSave, autoMode, askSkip, documentsOnly bool) {
first := true
for i := range t.Transactions {
Expand Down
29 changes: 29 additions & 0 deletions pkg/schema/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,35 @@ func (t Transaction) Validate() util.ValidateResults {
return []util.ValidateResult{util.Check(t)}
}

func (t *Transaction) Repopulate(s Schema) {
docDone := false
for i := range s.Expenses {
if s.Expenses[i].SettlementTransaction.Match(t) {
t.AssociatedDocument = NewRef(s.Expenses[i].SettlementTransaction.Id)
docDone = true
break
}
}
if !docDone {
for i := range s.Invoices {
if s.Invoices[i].SettlementTransaction.Match(t) {
t.AssociatedDocument = NewRef(s.Invoices[i].SettlementTransaction.Id)
docDone = true
break
}
}
}
if !docDone {
for i := range s.MiscRecords {
if s.MiscRecords[i].Transaction.Match(t) {
t.AssociatedDocument = NewRef(s.MiscRecords[i].Transaction.Id)
docDone = true
break
}
}
}
}

func (t Transaction) SearchItem() util.SearchItem {
return util.SearchItem{
Name: t.Description,
Expand Down

0 comments on commit 435ec41

Please sign in to comment.