Skip to content

Commit

Permalink
add ledger to deal obj
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowbean committed Jul 1, 2023
1 parent 1a08f76 commit 72a912f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
4 changes: 3 additions & 1 deletion absbox/local/china.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class SPV:
触发事件: dict = None
状态:str = "摊销"
自定义: dict = None
科目: dict = None

@classmethod
def load(cls,p):
Expand Down Expand Up @@ -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)
Expand Down
23 changes: 22 additions & 1 deletion absbox/local/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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}:
Expand Down Expand Up @@ -475,13 +478,23 @@ 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:
case ["账户转移", source, target] | ["transfer", source, target]:
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]:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion absbox/local/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Generic:
trigger:dict = None
status:str = "Amortizing"
custom: dict = None
ledgers:dict = None

@property
def json(self):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 72a912f

Please sign in to comment.