Skip to content

Commit

Permalink
support hledger's equity conversion postings
Browse files Browse the repository at this point in the history
  • Loading branch information
ananthakumaran committed Oct 2, 2023
1 parent cdafcda commit e259572
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
5 changes: 3 additions & 2 deletions desktop/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ func main() {
Bind: []interface{}{
app,
},
WindowStartState: options.Maximised,
Logger: &logger.Logger{},
WindowStartState: options.Maximised,
EnableDefaultContextMenu: true,
Logger: &logger.Logger{},
Mac: &mac.Options{
About: &mac.AboutInfo{
Title: "Paisa",
Expand Down
13 changes: 7 additions & 6 deletions docs/reference/recurring.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,23 @@ right next to period metadata.
│ ┌─────────── month 1-12
│ │ ┌─────────── day of the week 0-6 (Sunday to Saturday)
│ │ │
* * *
1 * ?
```

The syntax of the period is similar to [cron](https://en.wikipedia.org/wiki/Cron), with the omission of
seconds and hours.

| Field | Allowed value | Special characters |
| Field | Allowed values | Special characters |
|--------------|---------------------|--------------------|
| Day of month | `1–31` | `* , - ? L W` |
| Month | `1-12` or `JAN-DEC` | `* , -` |
| Day of week | `0-6` or `SUN-SAT` | `* , - ? L` |

`?` means you want to omit the field, usually you use it on the day of
month or day of week. `L` means last day of the month or week. `,` can
be used to specify multiple entries. `-` can be used to specify
range. `W` means the closest business day to given day of month
`*` also known as wildcard represents all valid values. `?` means you
want to omit the field, usually you use it on the day of month or day
of week. `L` means last day of the month or week. `,` can be used to
specify multiple entries. `-` can be used to specify range. `W` means
the closest business day to given day of month

Multiple cron expressions can be specified by joining them using
`|`. Refer the [wikipedia](https://en.wikipedia.org/wiki/Cron) for more information. If you are not
Expand Down
13 changes: 9 additions & 4 deletions internal/ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (HLedgerCLI) Prices(journalPath string) ([]price.Price, error) {
}

var output, error bytes.Buffer
err = utils.Exec("hledger", &output, &error, "-f", journalPath, "--auto", "--infer-market-prices", "prices")
err = utils.Exec("hledger", &output, &error, "-f", journalPath, "--auto", "--infer-market-prices", "--infer-costs", "prices")
if err != nil {
return prices, err
}
Expand Down Expand Up @@ -222,12 +222,17 @@ func parseHLedgerPrices(output string, defaultCurrency string) ([]price.Price, e
return nil, err
}

commodity := utils.UnQuote(match[2])
if target != defaultCurrency {
continue
if commodity == defaultCurrency && !value.Equal(decimal.Zero) {
commodity = target
target = defaultCurrency
value = decimal.NewFromInt(1).Div(value)
} else {
continue
}
}

commodity := utils.UnQuote(match[2])

date, err := time.ParseInLocation("2006-01-02", match[1], time.Local)
if err != nil {
return nil, err
Expand Down

0 comments on commit e259572

Please sign in to comment.