supplychain/wwwroot/api/supplier_resource_price_create.dspy

35 lines
1.3 KiB
Plaintext

result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
try:
dbname = get_module_dbname('supplychain')
data = dict(params_kw)
data['id'] = getID()
data['created_at'] = timestampstr()
data['updated_at'] = timestampstr()
if 'status' not in data:
data['status'] = '1'
if 'unit_price' not in data:
data['unit_price'] = '0'
if 'currency' not in data:
data['currency'] = 'CNY'
if not data.get('supplier_org_id'):
raise ValueError('供应商ID不能为空')
if not data.get('resource_type'):
raise ValueError('资源类型不能为空')
if not data.get('resource_ref_id'):
raise ValueError('资源引用ID不能为空')
if not data.get('price_unit'):
raise ValueError('价格单位不能为空')
if not data.get('effective_date'):
raise ValueError('生效日期不能为空')
async with DBPools().sqlorContext(dbname) as sor:
await sor.C('supplier_resource_price', data)
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '定价创建成功', 'type': 'success'}}
except Exception as e:
result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'}
return result