supplychain/wwwroot/api/supply_contract_items_create.dspy

38 lines
1.2 KiB
Plaintext

result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
try:
user_id = await get_user()
user_orgid = (await get_userorgid()) or '0'
dbname = get_module_dbname('supplychain')
data = dict(params_kw)
item_id = getID()
data['id'] = item_id
data['resellerid'] = user_orgid
data['created_at'] = timestampstr()
data['updated_at'] = timestampstr()
product_id = data.get('productid')
contract_id = data.get('contract_id')
async with DBPools().sqlorContext(dbname) as sor:
await sor.C('supply_contract_items', data)
# Sync product_org_auth
if product_id:
async with DBPools().sqlorContext('sage') as sor_sage:
await sor_sage.C('product_org_auth', {
'id': getID(),
'product_id': product_id,
'org_id': user_orgid,
'auth_source': 'supply_contract',
'auth_source_id': item_id,
})
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '供应合同项目创建成功', 'type': 'success'}}
except Exception as e:
result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'}
return result