supplychain/wwwroot/api/suppliers_create.dspy

55 lines
1.9 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': '', 'timeout': 3}}
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()
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:
raise Exception('供应商名称不能为空')
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)
# 开账accounting_orgid='0', 当前用户与供应商的往来账
await openRetailRelationshipAccounts(sor_sage, '0', new_orgid, user_orgid)
data['orgid'] = new_orgid
elif is_external == '0' and not orgid:
raise Exception('内部供应商必须选择所属机构')
async with DBPools().sqlorContext(dbname) as sor:
await sor.C('suppliers', data)
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '供应商创建成功,已完成开账', 'type': 'success', 'timeout': 3}}
except Exception as e:
debug(f'suppliers_create error: {format_exc()}')
result = {'widgettype': 'Error', 'options': {'title': '创建失败', 'message': str(e), 'timeout': 5}}
return result