fix: 供应商创建同步org+开账,去json.dumps

This commit is contained in:
yumoqing 2026-07-01 16:01:24 +08:00
parent 7dbdcf1d2f
commit 0bdb019e29

View File

@ -1,4 +1,4 @@
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': '', 'timeout': 3}}
try:
user_id = await get_user()
@ -12,15 +12,14 @@ try:
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)
raise Exception('供应商名称不能为空')
new_orgid = getID()
now_org = timestampstr()
org_rec = {
@ -35,17 +34,21 @@ try:
db = DBPools()
async with db.sqlorContext('sage') as sor_sage:
await sor_sage.C('organization', org_rec)
# 开账accounting_orgid='0', 当前用户与供应商的往来账
await openRetailRelationshipAccounts(sor_sage, '0', new_orgid, user_orgid)
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)
raise Exception('内部供应商必须选择所属机构')
async with DBPools().sqlorContext(dbname) as sor:
await sor.C('suppliers', data)
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '供应商创建成功', 'type': 'success'}}
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '供应商创建成功,已完成开账', 'type': 'success', 'timeout': 3}}
except Exception as e:
result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'}
debug(f'suppliers_create error: {format_exc()}')
result = {'widgettype': 'Error', 'options': {'title': '创建失败', 'message': str(e), 'timeout': 5}}
return json.dumps(result, ensure_ascii=False)
return result