Skip to content

Commit

Permalink
fix(alipay): refund transactions with txType as "收入" (#83)
Browse files Browse the repository at this point in the history
* fix #82 alipay refund transaction with txType as income

* fix test

* update readme
  • Loading branch information
wych42 authored Jan 29, 2023
1 parent 864a4f6 commit d765283
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,13 @@ alipay:

`targetAccount` 与 `methodAccount` 的增减账户关系如下表:

|收/支|methodAccount|targetAccount|
|----|----|----|
|收入|plusAccount|minusAccount|
|支出|minusAccount|plusAccount|
|其他|minusAccount|plusAccount|
|收/支|交易分类|methodAccount|targetAccount|
|----|----|----|----|
|收入|*|plusAccount|minusAccount|
|收入|退款|plusAccount|minusAccount|
|支出|*|minusAccount|plusAccount|
|其他|*|minusAccount|plusAccount|
|其他|退款|plusAccount|minusAccount|

> 当交易类型为「其他」时,需要自行手动定义借贷账户。此时本软件会认为 `methodAccount` 是贷账户,`targetAccount` 是借账户。

Expand Down
18 changes: 10 additions & 8 deletions example/alipay/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ defaultCurrency: CNY
title: 测试
alipay:
rules:
# 泛匹配结果应当放在前面
- type: 收入 # 其他转账收款
targetAccount: Income:FIXME
methodAccount: Assets:Alipay

- type: 收入 # 收款码收款
item: 商品
targetAccount: Income:Alipay:ShouKuanMa
methodAccount: Assets:Alipay

- category: 日用百货
targetAccount: Expenses:Groceries
- category: 餐饮美食
Expand All @@ -30,14 +40,6 @@ alipay:
fullMatch: true
methodAccount: Assets:Bank:CN:CMB-9876:Savings

- type: 收入 # 其他转账收款
targetAccount: Income:FIXME
methodAccount: Assets:Alipay
- type: 收入 # 收款码收款
item: 商品
targetAccount: Income:Alipay:ShouKuanMa
methodAccount: Assets:Alipay

# 交易类型为其他
- type: 其他
item: 收益发放
Expand Down
12 changes: 12 additions & 0 deletions example/alipay/example-alipay-output.beancount
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ option "operating_currency" "CNY"
Assets:Bank:CN:CMB-9876:Savings 109.90 CNY
Expenses:Groceries -109.90 CNY

2021-06-01 * "dettol滴露官方旗舰店" "退款-【直接下单付款】滴露消毒液1.2L*2家用杀菌消毒水衣物地板宠物"
category: "退款"
merchantId: "ABC9876"
method: "招商银行(9876)"
orderId: "123456"
payTime: "2021-06-01 00:13:56 +0800 CST"
source: "支付宝"
status: "退款成功"
txType: "收入"
Assets:Bank:CN:CMB-9876:Savings 109.90 CNY
Expenses:Groceries -109.90 CNY

2021-06-14 * "蚂蚁会员(北京)网络技术服务有限公司" "相互宝分摊-6月第1期-*"
category: "互助保障"
merchantId: "ABC9876"
Expand Down
1 change: 1 addition & 0 deletions example/alipay/example-alipay-records.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
��/֧ ,���׶Է� ,�Է��˺� ,��Ʒ˵�� ,��/���ʽ ,��� ,����״̬ ,���׷��� ,���׶����� ,�̼Ҷ����� ,����ʱ�� ,
֧�� ,���ϻ�Ա�����������缼���������޹�˾ , ,�໥����̯-6�µ�1��-* ,��������(9876) ,6.51 ,���׳ɹ� ,�������� ,123456 ,ABC9876 ,2021-06-14 14:00:38 ,
���� ,dettol��¶�ٷ��콢�� ,zhi***@hkmanon.com ,�˿�-��ֱ���µ������¶����Һ1.2L*2����ɱ������ˮ����ذ����,��������(9876) ,109.90 ,�˿�ɹ� ,�˿� ,123456 ,ABC9876 ,2021-06-01 00:13:56 ,
���� ,dettol��¶�ٷ��콢�� ,zhi***@hkmanon.com ,�˿�-��ֱ���µ������¶����Һ1.2L*2����ɱ������ˮ����ذ����,��������(9876) ,109.90 ,�˿�ɹ� ,�˿� ,123456 ,ABC9876 ,2021-06-01 00:13:56 ,
֧�� ,dettol��¶�ٷ��콢�� ,zhi***@hkmanon.com ,��ֱ���µ������¶����Һ1.2L*2����ɱ������ˮ����ذ����,��������(9876) ,109.90 ,���׹ر� ,���ðٻ� ,123456 ,ABC9876 ,2021-06-01 00:10:22 ,
���� ,�㷢����������޹�˾ ,e-f***@gffunds.com.cn,��-����ת�� ,��� ,2.00 ,���׳ɹ� ,Ͷ������ ,123456 ,ABC9876 ,2021-05-30 23:43:37 ,
���� ,�㷢����������޹�˾ , ,��-2020.06.08-���淢�� ,�� ,0.11 ,���׳ɹ� ,Ͷ������ ,123456 , ,2020-06-09 02:57:13 ,
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyser/alipay/alipay.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (a Alipay) GetAccountsAndTags(o *ir.Order, cfg *config.Config, target, prov
}
}

if strings.HasPrefix(o.Item, "退款-") {
if strings.HasPrefix(o.Item, "退款-") && ir.TypeRecv != o.Type {
return resPlus, resMinus, extraAccounts, tags
}
return resMinus, resPlus, extraAccounts, tags
Expand Down

0 comments on commit d765283

Please sign in to comment.