fix: supply_contracts_create generates contract_code automatically
This commit is contained in:
parent
3c742c0674
commit
813882ff71
@ -1,23 +1,32 @@
|
|||||||
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
|
|
||||||
|
user_id = await get_user()
|
||||||
|
user_orgid = (await get_userorgid()) or '0'
|
||||||
|
dbname = get_module_dbname('supplychain')
|
||||||
|
|
||||||
|
data = dict(params_kw)
|
||||||
|
data['id'] = getID()
|
||||||
|
data['resellerid'] = user_orgid
|
||||||
|
data['created_by'] = user_id
|
||||||
|
data['created_at'] = timestampstr()
|
||||||
|
data['updated_at'] = timestampstr()
|
||||||
|
|
||||||
|
# Auto-generate contract_code
|
||||||
|
if not data.get('contract_code'):
|
||||||
|
today = curDateString().replace('-', '')
|
||||||
|
prefix = f'SC-{today}'
|
||||||
|
db = DBPools()
|
||||||
|
async with db.sqlorContext(dbname) as sor:
|
||||||
|
recs = await sor.sqlExe(
|
||||||
|
"SELECT COUNT(*) as cnt FROM supply_contracts WHERE resellerid = ${rid}$ AND contract_code LIKE ${p}$",
|
||||||
|
{"rid": user_orgid, "p": prefix + "%"}
|
||||||
|
)
|
||||||
|
seq = (recs[0].cnt if recs else 0) + 1
|
||||||
|
data['contract_code'] = f'{prefix}-{seq:04d}'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user_id = await get_user()
|
db = DBPools()
|
||||||
user_orgid = (await get_userorgid()) or '0'
|
async with db.sqlorContext(dbname) as sor:
|
||||||
dbname = get_module_dbname('supplychain')
|
|
||||||
|
|
||||||
data = dict(params_kw)
|
|
||||||
data['id'] = getID()
|
|
||||||
data['resellerid'] = user_orgid
|
|
||||||
data['created_by'] = user_id
|
|
||||||
data['created_at'] = timestampstr()
|
|
||||||
data['updated_at'] = timestampstr()
|
|
||||||
|
|
||||||
async with DBPools().sqlorContext(dbname) as sor:
|
|
||||||
await sor.C('supply_contracts', data)
|
await sor.C('supply_contracts', data)
|
||||||
|
return json.dumps({'widgettype':'Message','options':{'title':'Success','message':'供应合同创建成功'}}, ensure_ascii=False)
|
||||||
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '供应合同创建成功', 'type': 'success'}}
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'}
|
return json.dumps({'widgettype':'Error','options':{'title':'Error','message':f'创建失败: {e}'}}, ensure_ascii=False)
|
||||||
|
|
||||||
return json.dumps(result, ensure_ascii=False)
|
|
||||||
|
|||||||
@ -26,8 +26,8 @@ ns['resellerid'] = userorgid
|
|||||||
|
|
||||||
# Auto-generate contract_code if not provided
|
# Auto-generate contract_code if not provided
|
||||||
if not ns.get('contract_code'):
|
if not ns.get('contract_code'):
|
||||||
from datetime import datetime as _dt
|
_today = curDateString().replace('-', '')
|
||||||
_prefix = f"SC-{_dt.now().strftime('%Y%m%d')}"
|
_prefix = f"SC-{_today}"
|
||||||
async with DBPools().sqlorContext(get_module_dbname('supplychain')) as _sor:
|
async with DBPools().sqlorContext(get_module_dbname('supplychain')) as _sor:
|
||||||
_recs = await _sor.sqlExe(
|
_recs = await _sor.sqlExe(
|
||||||
"SELECT COUNT(*) as cnt FROM supply_contracts WHERE resellerid = ${rid}$ AND contract_code LIKE ${p}$",
|
"SELECT COUNT(*) as cnt FROM supply_contracts WHERE resellerid = ${rid}$ AND contract_code LIKE ${p}$",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user