From 60723b73c93acae2cd770cd7b6bd2f311f53dc2a Mon Sep 17 00:00:00 2001 From: Anantha Kumaran Date: Sun, 20 Aug 2023 00:00:20 +0530 Subject: [PATCH] handle quoted commodity --- internal/ledger/ledger.go | 2 +- internal/server/assets/balance.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/ledger/ledger.go b/internal/ledger/ledger.go index dbb0ec04..15373687 100644 --- a/internal/ledger/ledger.go +++ b/internal/ledger/ledger.go @@ -386,7 +386,7 @@ func (HLedgerCLI) Prices(journalPath string) ([]price.Price, error) { func parseLedgerPrices(output string, defaultCurrency string) ([]price.Price, error) { var prices []price.Price - re := regexp.MustCompile(`P (\d{4}\/\d{2}\/\d{2}) (?:\d{2}:\d{2}:\d{2}) ([^\s\d.-]+) (.+)\n`) + re := regexp.MustCompile(`P (\d{4}\/\d{2}\/\d{2}) (?:\d{2}:\d{2}:\d{2}) ([^\s\d.-]+|"[^"]+") (.+)\n`) matches := re.FindAllStringSubmatch(output, -1) for _, match := range matches { diff --git a/internal/server/assets/balance.go b/internal/server/assets/balance.go index 31cdbdf0..8fba13c8 100644 --- a/internal/server/assets/balance.go +++ b/internal/server/assets/balance.go @@ -5,6 +5,7 @@ import ( "github.com/samber/lo" + "github.com/ananthakumaran/paisa/internal/accounting" "github.com/ananthakumaran/paisa/internal/model/posting" "github.com/ananthakumaran/paisa/internal/query" "github.com/ananthakumaran/paisa/internal/service" @@ -60,7 +61,7 @@ func computeBreakdown(db *gorm.DB, postings []posting.Posting) map[string]AssetB return acc + -p.Amount } }, 0.0) - marketAmount := lo.Reduce(ps, func(acc float64, p posting.Posting, _ int) float64 { return acc + p.MarketAmount }, 0.0) + marketAmount := accounting.CurrentBalance(ps) var balanceUnits float64 if leaf { balanceUnits = lo.Reduce(ps, func(acc float64, p posting.Posting, _ int) float64 {