From 72a912f36a1e1a61e31d73d7424e915439099b15 Mon Sep 17 00:00:00 2001 From: Xiaoyu Date: Sun, 2 Jul 2023 00:49:13 +0800 Subject: [PATCH] add ledger to deal obj --- absbox/local/china.py | 4 +++- absbox/local/component.py | 23 ++++++++++++++++++++++- absbox/local/generic.py | 4 +++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/absbox/local/china.py b/absbox/local/china.py index 439d933..6dee254 100644 --- a/absbox/local/china.py +++ b/absbox/local/china.py @@ -29,6 +29,7 @@ class SPV: 触发事件: dict = None 状态:str = "摊销" 自定义: dict = None + 科目: dict = None @classmethod def load(cls,p): @@ -82,7 +83,8 @@ def json(self): "custom": {cn:mkCustom(co) for cn,co in self.自定义.items()} if self.自定义 else None, "triggers": renameKs2(mapListValBy(self.触发事件,mkTrigger),chinaDealCycle) if self.触发事件 else None, "liqProvider": {ln: mkLiqProvider(ln, lo | {"起始日":defaultStartDate} ) - for ln,lo in self.流动性支持.items() } if self.流动性支持 else None + for ln,lo in self.流动性支持.items() } if self.流动性支持 else None, + "ledgers": {ln: mkLedger(ln, v) for ln,v in self.科目.items()} if self.科目 else None } _dealType = identify_deal_type(_r) diff --git a/absbox/local/component.py b/absbox/local/component.py index 3205663..234872e 100644 --- a/absbox/local/component.py +++ b/absbox/local/component.py @@ -157,6 +157,8 @@ def mkDs(x): return mkTag("AllAccBalance") case ("账户余额", *ans) | ("accountBalance", *ans): return mkTag(("AccBalance", ans)) + case ("账簿余额", *ans) | ("ledgerBalance", *ans): + return mkTag(("LedgerBalance", ans)) case ("债券待付利息", *bnds) | ("bondDueInt", *bnds): return mkTag(("CurrentDueBondInt", bnds)) case ("债券已付利息", *bnds) | ("lastBondIntPaid", *bnds): @@ -415,6 +417,8 @@ def mkTransferLimit(x): return mkTag(("Formula", "ABCD")) case {"公式": formula} | {"formula": formula}: return mkTag(("DS", mkDs(formula))) + case {"PDL贷记":an} | {"clearPDL":an}: + return mkTag(("ClearPDL", an)) case _: raise RuntimeError(f"Failed to match :{x}:mkTransferLimit") @@ -446,7 +450,6 @@ def isFloater(y): case _: raise RuntimeError(f"Failed to match :{rr,pr}:Interest Swap Type") - def mkRsBase(x): match x: case {"fixed":bal} | {"固定":bal}: @@ -475,6 +478,14 @@ def mkRateSwap(x): case _: raise RuntimeError(f"Failed to match :{x}:Interest Swap") +def mkBookLedgerType(x): + match x: + case ["PDL",defaults,ledgers]: + return mkTag(("PDL",[mkDs(defaults) + ,[ (ln,mkDs(ds)) for ln,ds in ledgers]])) + case _: + raise RuntimeError(f"Failed to match :{x}:mkBookLedgerType") + def mkAction(x): match x: @@ -482,6 +493,8 @@ def mkAction(x): return mkTag(("Transfer", [source, target])) case ["按公式账户转移", _limit, source, target] | ["transferBy", _limit, source, target]: return mkTag(("TransferBy", [mkTransferLimit(_limit), source, target])) + case ["簿记", bookLedgerType] | ["bookBy", bookLedgerType]: + return mkTag(("BookBy", mkBookLedgerType(bookLedgerType))) case ["计提费用", *feeNames] | ["calcFee", *feeNames]: return mkTag(("CalcFee", feeNames)) case ["计提利息", *bndNames] | ["calcInt", *bndNames]: @@ -1017,6 +1030,14 @@ def mkLiqProvider(n, x): if r is not None: return opt_fields | r +def mkLedger(n, x): + match x: + case {"balance":bal,"txn":_tx} | {"余额":bal,"记录":_tx}: + tx = mkAccTxn(_tx) + return {"ledgName":n,"ledgBalance":bal,"ledgStmt":tx} + case _: + raise RuntimeError(f"Failed to match Ledger:{x}") + def mkCf(x): if len(x) == 0: diff --git a/absbox/local/generic.py b/absbox/local/generic.py index 6a0d7a6..10d7c3c 100644 --- a/absbox/local/generic.py +++ b/absbox/local/generic.py @@ -25,6 +25,7 @@ class Generic: trigger:dict = None status:str = "Amortizing" custom: dict = None + ledgers:dict = None @property def json(self): @@ -55,7 +56,8 @@ def json(self): "custom": {cn:mkCustom(co) for cn,co in self.custom.items()} if self.custom else None , "triggers": renameKs2(mapListValBy(self.trigger,mkTrigger),englishDealCycle) if self.trigger else None, "liqProvider": {ln: mkLiqProvider(ln, lo | {"start":lastCloseDate} ) - for ln,lo in self.liqFacility.items() } if self.liqFacility else None + for ln,lo in self.liqFacility.items() } if self.liqFacility else None, + "ledgers": {ln: mkLedger(ln, v) for ln,v in self.ledgers.items()} if self.ledgers else None } _dealType = identify_deal_type(_r)