Skip to content

Commit

Permalink
adjust dates
Browse files Browse the repository at this point in the history
  • Loading branch information
ananthakumaran committed Feb 11, 2024
1 parent c7b377d commit 0a212ac
Show file tree
Hide file tree
Showing 27 changed files with 618 additions and 633 deletions.
4 changes: 2 additions & 2 deletions internal/query/posting.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (q *Query) All() []posting.Posting {
var postings []posting.Posting

q.context = q.context.Where("forecast = ?", q.includeForecast)
result := q.context.Order("date " + q.order + ", amount desc").Find(&postings)
result := q.context.Order("date " + q.order + ", amount desc, account asc").Find(&postings)
if result.Error != nil {
log.Fatal(result.Error)
}
Expand All @@ -140,7 +140,7 @@ func (q *Query) All() []posting.Posting {
func (q *Query) First() *posting.Posting {
var posting posting.Posting
q.context = q.context.Where("forecast = ?", q.includeForecast)
result := q.context.Order("date " + q.order + ", amount desc").First(&posting)
result := q.context.Order("date " + q.order + ", amount desc, account asc").First(&posting)

if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
Expand Down
2 changes: 1 addition & 1 deletion tests/fixture/inr-beancount/allocation.json
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@
"Assets:Checking": {
"date": "2022-01-29T00:00:00Z",
"account": "Assets:Checking",
"market_amount": 11097.22810619763
"market_amount": 12169.22810619763
},
"Assets:Coinbase:BTC": {
"date": "2022-01-29T00:00:00Z",
Expand Down
4 changes: 2 additions & 2 deletions tests/fixture/inr-beancount/assets_balance.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"marketAmount": 102155.81133819763,
"balanceUnits": 0,
"latestPrice": 0,
"xirr": 12.15,
"xirr": 12.14,
"gainAmount": 13414.62810619763,
"absoluteReturn": 0.1358193262974935
},
Expand All @@ -18,7 +18,7 @@
"marketAmount": 13169.22810619763,
"balanceUnits": 0,
"latestPrice": 0,
"xirr": 44.43,
"xirr": 44.37,
"gainAmount": 13169.22810619763,
"absoluteReturn": 0
},
Expand Down
48 changes: 24 additions & 24 deletions tests/fixture/inr-beancount/dashboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,18 @@
"balanceUnits": 0,
"netInvestmentAmount": 100972
},
"xirr": 12.15
"xirr": 12.14
},
"transactionSequences": [],
"transactions": [
{
"id": "7de56ebcddef5b0fd2525c04178705d3",
"id": "5e31c18d8b6da4f8b27ee2eee680e3ed",
"date": "2022-01-31T00:00:00Z",
"payee": "Interest",
"postings": [
{
"id": 25,
"transaction_id": "7de56ebcddef5b0fd2525c04178705d3",
"transaction_id": "5e31c18d8b6da4f8b27ee2eee680e3ed",
"date": "2022-01-31T00:00:00Z",
"payee": "Interest",
"account": "Assets:Checking",
Expand All @@ -107,8 +107,8 @@
"status": "cleared",
"tag_recurring": "",
"tag_period": "",
"transaction_begin_line": 66,
"transaction_end_line": 69,
"transaction_begin_line": 69,
"transaction_end_line": 72,
"file_name": "main.beancount",
"forecast": false,
"note": "",
Expand All @@ -118,7 +118,7 @@
},
{
"id": 24,
"transaction_id": "7de56ebcddef5b0fd2525c04178705d3",
"transaction_id": "5e31c18d8b6da4f8b27ee2eee680e3ed",
"date": "2022-01-31T00:00:00Z",
"payee": "Interest",
"account": "Income:Interest:Checking",
Expand All @@ -128,8 +128,8 @@
"status": "cleared",
"tag_recurring": "",
"tag_period": "",
"transaction_begin_line": 66,
"transaction_end_line": 69,
"transaction_begin_line": 69,
"transaction_end_line": 72,
"file_name": "main.beancount",
"forecast": false,
"note": "",
Expand All @@ -140,20 +140,20 @@
],
"tag_recurring": "",
"tag_period": "",
"beginLine": 66,
"endLine": 69,
"beginLine": 69,
"endLine": 72,
"fileName": "main.beancount",
"note": ""
},
{
"id": "3262b6a59ca5bc147ceb6f7ee90955c7",
"date": "2022-01-30T00:00:00Z",
"id": "ab7ce9cc56fadc16bd1ed6e908d9aacf",
"date": "2022-01-29T00:00:00Z",
"payee": "(Padding inserted for Balance of 21000 INR for difference 1072.7 INR)",
"postings": [
{
"id": 22,
"transaction_id": "3262b6a59ca5bc147ceb6f7ee90955c7",
"date": "2022-01-30T00:00:00Z",
"transaction_id": "ab7ce9cc56fadc16bd1ed6e908d9aacf",
"date": "2022-01-29T00:00:00Z",
"payee": "(Padding inserted for Balance of 21000 INR for difference 1072.7 INR)",
"account": "Assets:Checking",
"commodity": "INR",
Expand All @@ -173,8 +173,8 @@
},
{
"id": 23,
"transaction_id": "3262b6a59ca5bc147ceb6f7ee90955c7",
"date": "2022-01-30T00:00:00Z",
"transaction_id": "ab7ce9cc56fadc16bd1ed6e908d9aacf",
"date": "2022-01-29T00:00:00Z",
"payee": "(Padding inserted for Balance of 21000 INR for difference 1072.7 INR)",
"account": "Equity:OpeningBalances",
"commodity": "INR",
Expand Down Expand Up @@ -206,13 +206,13 @@
"payee": "Purchased 0.00000001 BTC",
"postings": [
{
"id": 20,
"id": 21,
"transaction_id": "6bf2d0bd8cc5cc3ecfec78ecc069a14d",
"date": "2022-01-10T00:00:00Z",
"payee": "Purchased 0.00000001 BTC",
"account": "Assets:Coinbase:BTC",
"commodity": "BTC",
"quantity": 1e-8,
"account": "Assets:Checking",
"commodity": "USD",
"quantity": -0.00042772,
"amount": 0,
"status": "cleared",
"tag_recurring": "",
Expand All @@ -227,13 +227,13 @@
"balance": 0
},
{
"id": 21,
"id": 20,
"transaction_id": "6bf2d0bd8cc5cc3ecfec78ecc069a14d",
"date": "2022-01-10T00:00:00Z",
"payee": "Purchased 0.00000001 BTC",
"account": "Assets:Checking",
"commodity": "USD",
"quantity": -0.00042772,
"account": "Assets:Coinbase:BTC",
"commodity": "BTC",
"quantity": 1e-8,
"amount": 0,
"status": "cleared",
"tag_recurring": "",
Expand Down
12 changes: 6 additions & 6 deletions tests/fixture/inr-beancount/expense.json
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@
},
{
"id": 24,
"transaction_id": "7de56ebcddef5b0fd2525c04178705d3",
"transaction_id": "5e31c18d8b6da4f8b27ee2eee680e3ed",
"date": "2022-01-31T00:00:00Z",
"payee": "Interest",
"account": "Income:Interest:Checking",
Expand All @@ -332,8 +332,8 @@
"status": "cleared",
"tag_recurring": "",
"tag_period": "",
"transaction_begin_line": 66,
"transaction_end_line": 69,
"transaction_begin_line": 69,
"transaction_end_line": 72,
"file_name": "main.beancount",
"forecast": false,
"note": "",
Expand Down Expand Up @@ -589,7 +589,7 @@
},
{
"id": 24,
"transaction_id": "7de56ebcddef5b0fd2525c04178705d3",
"transaction_id": "5e31c18d8b6da4f8b27ee2eee680e3ed",
"date": "2022-01-31T00:00:00Z",
"payee": "Interest",
"account": "Income:Interest:Checking",
Expand All @@ -599,8 +599,8 @@
"status": "cleared",
"tag_recurring": "",
"tag_period": "",
"transaction_begin_line": 66,
"transaction_end_line": 69,
"transaction_begin_line": 69,
"transaction_end_line": 72,
"file_name": "main.beancount",
"forecast": false,
"note": "",
Expand Down
2 changes: 1 addition & 1 deletion tests/fixture/inr-beancount/files.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"files": [
{
"name": "main.beancount",
"content": "1970-01-01 open Assets:Checking\n1970-01-01 open Assets:Equity:AAPL\n1970-01-01 open Assets:Equity:ABNB\n1970-01-01 open Assets:Equity:NIFTY\n1970-01-01 open Expenses:Rent\n1970-01-01 open Expenses:Charges\n1970-01-01 open Income:CapitalGains:Equity:AAPL\n1970-01-01 open Income:Interest:Checking\n1970-01-01 open Income:Salary:Acme\n1970-01-01 open Assets:Coinbase:BTC\n1970-01-01 open Assets:Dollar\n1970-01-01 open Equity:OpeningBalances\n\n1970-01-01 commodity AAPL\n1970-01-01 commodity ABNB\n1970-01-01 commodity INR\n1970-01-01 commodity NIFTY\n1970-01-01 commodity USD\n1970-01-01 commodity BTC\n\n2022-01-07 price NIFTY 100 INR\n2022-02-07 price NIFTY 100.273 INR\n\n2022-01-01 txn \"Salary\"\n Income:Salary:Acme -100,000 INR\n Assets:Checking 100,000 INR\n\n2022-01-03 txn \"Rent\"\n Assets:Checking -20,000 INR\n Expenses:Rent\n\n2022-01-06 txn \"Bonus\"\n Income:Salary:Acme -20,000 INR\n Assets:Checking 20,000 INR\n\n2022-01-07 txn \"Investment\"\n Assets:Checking -80,000 INR\n Assets:Equity:NIFTY 800 NIFTY {100 INR}\n\n2022-01-08 txn \"Buy ABNB\"\n Assets:Equity:ABNB 0.76 ABNB {131.27 USD}\n Assets:Checking\n\n2022-01-08 txn \"Buy Apple\"\n Assets:Equity:AAPL 100 AAPL {100 INR}\n Assets:Checking\n\n2022-01-09 txn \"Sell\"\n Assets:Equity:AAPL -100 AAPL {100 INR} @ 100.273 INR\n Income:CapitalGains:Equity:AAPL -27.3 INR\n Assets:Checking 10027.3 INR\n\n2022-01-08 price USD 80.442048 INR\n\n2022-01-09 txn \"Multi Currency Debit\"\n Expenses:Charges 100 INR\n Assets:Dollar 10 USD\n Assets:Checking\n\n2022-01-10 txn \"Purchased 0.00000001 BTC\"\n Assets:Coinbase:BTC 0.00000001 BTC {42772 USD}\n Assets:Checking -0.00042772 USD\n\n2022-01-31 txn \"Interest\"\n ; Global note\n ; :interest:\n Income:Interest:Checking -1,000 INR ; Posting note\n Assets:Checking\n\n2022/01/31 balance Assets:Equity:NIFTY 800 NIFTY\n\n2022/01/30 pad Assets:Checking Equity:OpeningBalances\n2022/01/31 balance Assets:Checking 21000 INR\n",
"content": "1970-01-01 open Assets:Checking\n1970-01-01 open Assets:Equity:AAPL\n1970-01-01 open Assets:Equity:ABNB\n1970-01-01 open Assets:Equity:NIFTY\n1970-01-01 open Expenses:Rent\n1970-01-01 open Expenses:Charges\n1970-01-01 open Income:CapitalGains:Equity:AAPL\n1970-01-01 open Income:Interest:Checking\n1970-01-01 open Income:Salary:Acme\n1970-01-01 open Assets:Coinbase:BTC\n1970-01-01 open Assets:Dollar\n1970-01-01 open Equity:OpeningBalances\n\n1970-01-01 commodity AAPL\n1970-01-01 commodity ABNB\n1970-01-01 commodity INR\n1970-01-01 commodity NIFTY\n1970-01-01 commodity USD\n1970-01-01 commodity BTC\n\n2022-01-07 price NIFTY 100 INR\n2022-02-07 price NIFTY 100.273 INR\n\n2022-01-01 txn \"Salary\"\n Income:Salary:Acme -100,000 INR\n Assets:Checking 100,000 INR\n\n2022-01-03 txn \"Rent\"\n Assets:Checking -20,000 INR\n Expenses:Rent\n\n2022-01-06 txn \"Bonus\"\n Income:Salary:Acme -20,000 INR\n Assets:Checking 20,000 INR\n\n2022-01-07 txn \"Investment\"\n Assets:Checking -80,000 INR\n Assets:Equity:NIFTY 800 NIFTY {100 INR}\n\n2022-01-08 txn \"Buy ABNB\"\n Assets:Equity:ABNB 0.76 ABNB {131.27 USD}\n Assets:Checking\n\n2022-01-08 txn \"Buy Apple\"\n Assets:Equity:AAPL 100 AAPL {100 INR}\n Assets:Checking\n\n2022-01-09 txn \"Sell\"\n Assets:Equity:AAPL -100 AAPL {100 INR} @ 100.273 INR\n Income:CapitalGains:Equity:AAPL -27.3 INR\n Assets:Checking 10027.3 INR\n\n2022-01-08 price USD 80.442048 INR\n\n2022-01-09 txn \"Multi Currency Debit\"\n Expenses:Charges 100 INR\n Assets:Dollar 10 USD\n Assets:Checking\n\n2022-01-10 txn \"Purchased 0.00000001 BTC\"\n Assets:Coinbase:BTC 0.00000001 BTC {42772 USD}\n Assets:Checking -0.00042772 USD\n\n2022/01/29 pad Assets:Checking Equity:OpeningBalances\n2022/01/30 balance Assets:Checking 21000 INR\n\n2022-01-31 txn \"Interest\"\n ; Global note\n ; :interest:\n Income:Interest:Checking -1,000 INR ; Posting note\n Assets:Checking\n\n2022/01/31 balance Assets:Equity:NIFTY 800 NIFTY\n",
"versions": [],
"operation": ""
}
Expand Down
12 changes: 6 additions & 6 deletions tests/fixture/inr-beancount/income.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
},
{
"id": 24,
"transaction_id": "7de56ebcddef5b0fd2525c04178705d3",
"transaction_id": "5e31c18d8b6da4f8b27ee2eee680e3ed",
"date": "2022-01-31T00:00:00Z",
"payee": "Interest",
"account": "Income:Interest:Checking",
Expand All @@ -78,8 +78,8 @@
"status": "cleared",
"tag_recurring": "",
"tag_period": "",
"transaction_begin_line": 66,
"transaction_end_line": 69,
"transaction_begin_line": 69,
"transaction_end_line": 72,
"file_name": "main.beancount",
"forecast": false,
"note": "",
Expand Down Expand Up @@ -165,7 +165,7 @@
},
{
"id": 24,
"transaction_id": "7de56ebcddef5b0fd2525c04178705d3",
"transaction_id": "5e31c18d8b6da4f8b27ee2eee680e3ed",
"date": "2022-01-31T00:00:00Z",
"payee": "Interest",
"account": "Income:Interest:Checking",
Expand All @@ -175,8 +175,8 @@
"status": "cleared",
"tag_recurring": "",
"tag_period": "",
"transaction_begin_line": 66,
"transaction_end_line": 69,
"transaction_begin_line": 69,
"transaction_end_line": 72,
"file_name": "main.beancount",
"forecast": false,
"note": "",
Expand Down
44 changes: 22 additions & 22 deletions tests/fixture/inr-beancount/ledger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"postings": [
{
"id": 24,
"transaction_id": "7de56ebcddef5b0fd2525c04178705d3",
"transaction_id": "5e31c18d8b6da4f8b27ee2eee680e3ed",
"date": "2022-01-31T00:00:00Z",
"payee": "Interest",
"account": "Income:Interest:Checking",
Expand All @@ -12,8 +12,8 @@
"status": "cleared",
"tag_recurring": "",
"tag_period": "",
"transaction_begin_line": 66,
"transaction_end_line": 69,
"transaction_begin_line": 69,
"transaction_end_line": 72,
"file_name": "main.beancount",
"forecast": false,
"note": "",
Expand All @@ -23,7 +23,7 @@
},
{
"id": 25,
"transaction_id": "7de56ebcddef5b0fd2525c04178705d3",
"transaction_id": "5e31c18d8b6da4f8b27ee2eee680e3ed",
"date": "2022-01-31T00:00:00Z",
"payee": "Interest",
"account": "Assets:Checking",
Expand All @@ -33,8 +33,8 @@
"status": "cleared",
"tag_recurring": "",
"tag_period": "",
"transaction_begin_line": 66,
"transaction_end_line": 69,
"transaction_begin_line": 69,
"transaction_end_line": 72,
"file_name": "main.beancount",
"forecast": false,
"note": "",
Expand All @@ -44,8 +44,8 @@
},
{
"id": 22,
"transaction_id": "3262b6a59ca5bc147ceb6f7ee90955c7",
"date": "2022-01-30T00:00:00Z",
"transaction_id": "ab7ce9cc56fadc16bd1ed6e908d9aacf",
"date": "2022-01-29T00:00:00Z",
"payee": "(Padding inserted for Balance of 21000 INR for difference 1072.7 INR)",
"account": "Assets:Checking",
"commodity": "INR",
Expand All @@ -65,8 +65,8 @@
},
{
"id": 23,
"transaction_id": "3262b6a59ca5bc147ceb6f7ee90955c7",
"date": "2022-01-30T00:00:00Z",
"transaction_id": "ab7ce9cc56fadc16bd1ed6e908d9aacf",
"date": "2022-01-29T00:00:00Z",
"payee": "(Padding inserted for Balance of 21000 INR for difference 1072.7 INR)",
"account": "Equity:OpeningBalances",
"commodity": "INR",
Expand All @@ -85,13 +85,13 @@
"balance": -1072.7
},
{
"id": 21,
"id": 20,
"transaction_id": "6bf2d0bd8cc5cc3ecfec78ecc069a14d",
"date": "2022-01-10T00:00:00Z",
"payee": "Purchased 0.00000001 BTC",
"account": "Assets:Checking",
"commodity": "USD",
"quantity": -0.00042772,
"account": "Assets:Coinbase:BTC",
"commodity": "BTC",
"quantity": 1e-8,
"amount": 0,
"status": "cleared",
"tag_recurring": "",
Expand All @@ -102,17 +102,17 @@
"forecast": false,
"note": "",
"transaction_note": "",
"market_amount": -0.03440667277056,
"balance": 19817.53437228
"market_amount": 0,
"balance": 1e-8
},
{
"id": 20,
"id": 21,
"transaction_id": "6bf2d0bd8cc5cc3ecfec78ecc069a14d",
"date": "2022-01-10T00:00:00Z",
"payee": "Purchased 0.00000001 BTC",
"account": "Assets:Coinbase:BTC",
"commodity": "BTC",
"quantity": 1e-8,
"account": "Assets:Checking",
"commodity": "USD",
"quantity": -0.00042772,
"amount": 0,
"status": "cleared",
"tag_recurring": "",
Expand All @@ -123,8 +123,8 @@
"forecast": false,
"note": "",
"transaction_note": "",
"market_amount": 0,
"balance": 1e-8
"market_amount": -0.03440667277056,
"balance": 19817.53437228
},
{
"id": 15,
Expand Down
6 changes: 3 additions & 3 deletions tests/fixture/inr-beancount/main.beancount
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@
Assets:Coinbase:BTC 0.00000001 BTC {42772 USD}
Assets:Checking -0.00042772 USD

2022/01/29 pad Assets:Checking Equity:OpeningBalances
2022/01/30 balance Assets:Checking 21000 INR

2022-01-31 txn "Interest"
; Global note
; :interest:
Income:Interest:Checking -1,000 INR ; Posting note
Assets:Checking

2022/01/31 balance Assets:Equity:NIFTY 800 NIFTY

2022/01/30 pad Assets:Checking Equity:OpeningBalances
2022/01/31 balance Assets:Checking 21000 INR
Loading

0 comments on commit 0a212ac

Please sign in to comment.