- add_supply_contracts.dspy: 自动生成contract_code(SC-YYYYMMDD-NNNN) - add_supply_contracts.dspy: 自动填充created_by/created_at/updated_at - delete_supply_contracts.dspy: 删除协议时级联删除产品折扣明细
66 lines
1.5 KiB
Plaintext
66 lines
1.5 KiB
Plaintext
|
|
ns = params_kw.copy()
|
|
for k,v in ns.items():
|
|
if v == 'NaN' or v == 'null':
|
|
ns[k] = None
|
|
id = params_kw.id
|
|
if not id or len(id) > 32:
|
|
id = uuid()
|
|
ns['id'] = id
|
|
|
|
|
|
|
|
userorgid = await get_userorgid()
|
|
if not userorgid:
|
|
return {
|
|
"widgettype":"Error",
|
|
"options":{
|
|
"title":"Authorization Error",
|
|
"timeout":3,
|
|
"cwidth":16,
|
|
"cheight":9,
|
|
"message":"Please login"
|
|
}
|
|
}
|
|
ns['resellerid'] = userorgid
|
|
|
|
# Auto-generate contract_code if not provided
|
|
if not ns.get('contract_code'):
|
|
from datetime import datetime as _dt
|
|
_prefix = f"SC-{_dt.now().strftime('%Y%m%d')}"
|
|
async with DBPools().sqlorContext(get_module_dbname('supplychain')) as _sor:
|
|
_recs = await _sor.sqlExe(
|
|
"SELECT COUNT(*) as cnt FROM supply_contracts WHERE resellerid = ${rid}$ AND contract_code LIKE ${p}$",
|
|
{"rid": userorgid, "p": _prefix + "%"}
|
|
)
|
|
_seq = (_recs[0].cnt if _recs else 0) + 1
|
|
ns['contract_code'] = f"{_prefix}-{_seq:04d}"
|
|
ns['created_by'] = userorgid
|
|
ns['created_at'] = timestampstr()
|
|
ns['updated_at'] = timestampstr()
|
|
|
|
db = DBPools()
|
|
dbname = get_module_dbname('supplychain')
|
|
async with db.sqlorContext(dbname) as sor:
|
|
r = await sor.C('supply_contracts', ns.copy())
|
|
return {
|
|
"widgettype":"Message",
|
|
"options":{
|
|
"cwidth":16,
|
|
"cheight":9,
|
|
"title":"Add Success",
|
|
"timeout":3,
|
|
"message":"ok"
|
|
}
|
|
}
|
|
|
|
return {
|
|
"widgettype":"Error",
|
|
"options":{
|
|
"title":"Add Error",
|
|
"cwidth":16,
|
|
"cheight":9,
|
|
"timeout":3,
|
|
"message":"failed"
|
|
}
|
|
} |