supplychain/wwwroot/api/suppliers_create.dspy
Hermes Agent 2ff2ca7685 feat: 供应商表增加机构ID、内外部标识、结算周期/日、付款方式字段
- models/suppliers.json: 新增 orgid, is_external, settlement_cycle, settlement_day, payment_type
- 外部供应商创建时自动在sage库开设机构
- 内部供应商通过机构名称搜索选择机构ID
- suppliers_create.dspy: 处理is_external逻辑
- get_search_orgid.dspy: 机构名称搜索API
- load_path.py: 注册新API路由
2026-06-17 18:59:51 +08:00

52 lines
1.9 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)
data['id'] = getID()
data['resellerid'] = user_orgid
data['created_by'] = user_id
data['created_at'] = timestampstr()
data['updated_at'] = timestampstr()
# Handle external supplier: create new org
is_external = data.get('is_external', '1')
orgid = data.get('orgid')
if is_external == '1' and not orgid:
supplier_name = data.get('supplier_name')
if not supplier_name:
result['options'] = {'title': 'Error', 'message': '供应商名称不能为空', 'type': 'error'}
return json.dumps(result, ensure_ascii=False)
new_orgid = getID()
now_org = timestampstr()
org_rec = {
'id': new_orgid,
'orgname': supplier_name,
'orgtype': 'supplier',
'status': '1',
'created_by': user_id,
'created_at': now_org,
'updated_at': now_org
}
db = DBPools()
async with db.sqlorContext('sage') as sor_sage:
await sor_sage.C('organization', org_rec)
data['orgid'] = new_orgid
elif is_external == '0' and not orgid:
result['options'] = {'title': 'Error', 'message': '内部供应商必须选择所属机构', 'type': 'error'}
return json.dumps(result, ensure_ascii=False)
async with DBPools().sqlorContext(dbname) as sor:
await sor.C('suppliers', data)
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '供应商创建成功', 'type': 'success'}}
except Exception as e:
result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'}
return json.dumps(result, ensure_ascii=False)