From d94ca26870c0910da9219407dc18566a1a93e8ff Mon Sep 17 00:00:00 2001 From: CyrivlClth Date: Wed, 9 Feb 2022 14:58:16 +0800 Subject: [PATCH 1/2] fix: yaml tag --- pkg/config/config.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 921f7b6..e1a687e 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -11,12 +11,12 @@ type Config struct { Title string `yaml:"title,omitempty"` DefaultMinusAccount string `yaml:"defaultMinusAccount,omitempty"` DefaultPlusAccount string `yaml:"defaultPlusAccount,omitempty"` - DefaultCashAccount string `yaml:"defaultCashAccount,omitempty` - DefaultPositionAccount string `yaml:"defaultPositionAccount,omitempty` - DefaultCommissionAccount string `yaml:"defaultCommissionAccount,omitempty` - DefaultPnlAccount string `yaml:"defaultPnlAccount,omitempty` + DefaultCashAccount string `yaml:"defaultCashAccount,omitempty"` + DefaultPositionAccount string `yaml:"defaultPositionAccount,omitempty"` + DefaultCommissionAccount string `yaml:"defaultCommissionAccount,omitempty"` + DefaultPnlAccount string `yaml:"defaultPnlAccount,omitempty"` DefaultCurrency string `yaml:"defaultCurrency,omitempty"` Alipay *alipay.Config `yaml:"alipay,omitempty"` Wechat *wechat.Config `yaml:"wechat,omitempty"` - Huobi *huobi.Config `yaml:"huobi,omitempty` + Huobi *huobi.Config `yaml:"huobi,omitempty"` } From 8a4fa93cb083225a7fec5fe0323352ae4c6b4b45 Mon Sep 17 00:00:00 2001 From: CyrivlClth Date: Wed, 9 Feb 2022 15:01:07 +0800 Subject: [PATCH 2/2] feat: alipay txn flag mark ! when closed --- pkg/compiler/beancount/compiler.go | 3 ++- pkg/compiler/beancount/template.go | 6 ++++-- pkg/ir/ir.go | 10 ++++++---- pkg/provider/alipay/convert.go | 7 ++++--- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/pkg/compiler/beancount/compiler.go b/pkg/compiler/beancount/compiler.go index 391345e..853b885 100644 --- a/pkg/compiler/beancount/compiler.go +++ b/pkg/compiler/beancount/compiler.go @@ -162,6 +162,7 @@ func (b *BeanCount) writeBill(file *os.File, index int) error { case ir.OrderTypeNormal: err = normalOrderTemplate.Execute(&buf, &NormalOrderVars{ PayTime: o.PayTime, + Pending: o.Pending, Peer: o.Peer, Item: o.Item, Note: o.Note, @@ -171,8 +172,8 @@ func (b *BeanCount) writeBill(file *os.File, index int) error { MinusAccount: o.MinusAccount, PnlAccount: o.ExtraAccounts[ir.PnlAccount], CommissionAccount: o.ExtraAccounts[ir.CommissionAccount], - Metadata: o.Metadata, Currency: b.Config.DefaultCurrency, + Metadata: o.Metadata, }) case ir.OrderTypeHuobiTrade: // Huobi trades switch o.TxType { diff --git a/pkg/compiler/beancount/template.go b/pkg/compiler/beancount/template.go index cc2e36e..96fa033 100644 --- a/pkg/compiler/beancount/template.go +++ b/pkg/compiler/beancount/template.go @@ -6,7 +6,7 @@ import ( ) // 普通账单的模版(消费账) -var normalOrder = `{{ .PayTime.Format "2006-01-02" }} * "{{ .Peer }}" "{{ .Item }}"{{ if .Note }} ; {{ .Note }}{{ end }} +var normalOrder = `{{ .PayTime.Format "2006-01-02" }} {{ if .Pending }}!{{ else }}*{{ end }} "{{ .Peer }}" "{{ .Item }}"{{ if .Note }} ; {{ .Note }}{{ end }} {{ .PlusAccount }} {{ .Money | printf "%.2f" }} {{ .Currency }} {{ .MinusAccount }} -{{ .Money | printf "%.2f" }} {{ .Currency }} {{- if .CommissionAccount }}{{ printf "\n" }} {{ .CommissionAccount }} {{ .Commission | printf "%.2f" }} {{ .Currency }}{{ end }} @@ -17,7 +17,9 @@ var normalOrder = `{{ .PayTime.Format "2006-01-02" }} * "{{ .Peer }}" "{{ .Item ` type NormalOrderVars struct { - PayTime time.Time + PayTime time.Time + // 未入账标记 + Pending bool Peer string Item string Note string diff --git a/pkg/ir/ir.go b/pkg/ir/ir.go index 9349df7..fcd8f70 100644 --- a/pkg/ir/ir.go +++ b/pkg/ir/ir.go @@ -28,10 +28,12 @@ type IR struct { // Order is the intermediate representation for the order. type Order struct { - OrderType OrderType - Peer string - Item string - Category string + OrderType OrderType + Peer string + Item string + Category string + // 是否未入账 + Pending bool MerchantOrderID *string OrderID *string Money float64 diff --git a/pkg/provider/alipay/convert.go b/pkg/provider/alipay/convert.go index 0d4fcac..bf7d650 100644 --- a/pkg/provider/alipay/convert.go +++ b/pkg/provider/alipay/convert.go @@ -13,12 +13,13 @@ func (a *Alipay) convertToIR() *ir.IR { Peer: o.Peer, Item: o.ItemName, Category: o.Category, - Method: o.Method, - PayTime: o.PayTime, - Money: o.Money, + Pending: o.Status == "交易关闭", OrderID: &o.DealNo, + Money: o.Money, + PayTime: o.PayTime, TxType: conevertType(o.TxType), TxTypeOriginal: o.TxTypeOriginal, + Method: o.Method, } irO.Metadata = getMetadata(o) if o.MerchantId != "" {