- 新增 credit_limit 表定义和DDL - 修改 accounting_config.py 支持信用额度透支检查 - 新增 creditlimit.py 信用额度管理模块 - 新增信用额度管理界面和CRUD API - 支持设置/查询/更新客户信用额度
48 lines
1.1 KiB
Plaintext
48 lines
1.1 KiB
Plaintext
|
|
ns = params_kw.copy()
|
|
for k,v in ns.items():
|
|
if v == 'NaN' or v == 'null':
|
|
ns[k] = None
|
|
|
|
# Recalculate available_credit when credit_limit changes
|
|
if 'credit_limit' in ns and ns['credit_limit'] is not None:
|
|
credit_limit_val = float(ns['credit_limit'])
|
|
# Get current used_credit from DB
|
|
db = DBPools()
|
|
dbname = get_module_dbname('accounting')
|
|
async with db.sqlorContext(dbname) as sor:
|
|
recs = await sor.R('credit_limit', {'id': ns['id']})
|
|
if len(recs) > 0:
|
|
used = float(recs[0].get('used_credit', 0))
|
|
ns['available_credit'] = credit_limit_val - used
|
|
|
|
from datetime import datetime
|
|
ns['updated_at'] = datetime.now()
|
|
|
|
db = DBPools()
|
|
dbname = get_module_dbname('accounting')
|
|
async with db.sqlorContext(dbname) as sor:
|
|
r = await sor.U('credit_limit', ns)
|
|
debug('update credit_limit success')
|
|
return {
|
|
"widgettype":"Message",
|
|
"options":{
|
|
"title":"信用额度更新成功",
|
|
"cwidth":16,
|
|
"cheight":9,
|
|
"timeout":3,
|
|
"message":"ok"
|
|
}
|
|
}
|
|
|
|
return {
|
|
"widgettype":"Error",
|
|
"options":{
|
|
"title":"更新失败",
|
|
"cwidth":16,
|
|
"cheight":9,
|
|
"timeout":3,
|
|
"message":"failed"
|
|
}
|
|
}
|