fix: 供应商创建同步org+开账,去json.dumps
This commit is contained in:
parent
7dbdcf1d2f
commit
0bdb019e29
@ -1,4 +1,4 @@
|
|||||||
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
|
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': '', 'timeout': 3}}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user_id = await get_user()
|
user_id = await get_user()
|
||||||
@ -12,15 +12,14 @@ try:
|
|||||||
data['created_at'] = timestampstr()
|
data['created_at'] = timestampstr()
|
||||||
data['updated_at'] = timestampstr()
|
data['updated_at'] = timestampstr()
|
||||||
|
|
||||||
# Handle external supplier: create new org
|
|
||||||
is_external = data.get('is_external', '1')
|
is_external = data.get('is_external', '1')
|
||||||
orgid = data.get('orgid')
|
orgid = data.get('orgid')
|
||||||
|
|
||||||
if is_external == '1' and not orgid:
|
if is_external == '1' and not orgid:
|
||||||
supplier_name = data.get('supplier_name')
|
supplier_name = data.get('supplier_name')
|
||||||
if not supplier_name:
|
if not supplier_name:
|
||||||
result['options'] = {'title': 'Error', 'message': '供应商名称不能为空', 'type': 'error'}
|
raise Exception('供应商名称不能为空')
|
||||||
return json.dumps(result, ensure_ascii=False)
|
|
||||||
new_orgid = getID()
|
new_orgid = getID()
|
||||||
now_org = timestampstr()
|
now_org = timestampstr()
|
||||||
org_rec = {
|
org_rec = {
|
||||||
@ -35,17 +34,21 @@ try:
|
|||||||
db = DBPools()
|
db = DBPools()
|
||||||
async with db.sqlorContext('sage') as sor_sage:
|
async with db.sqlorContext('sage') as sor_sage:
|
||||||
await sor_sage.C('organization', org_rec)
|
await sor_sage.C('organization', org_rec)
|
||||||
|
# 开账:accounting_orgid='0', 当前用户与供应商的往来账
|
||||||
|
await openRetailRelationshipAccounts(sor_sage, '0', new_orgid, user_orgid)
|
||||||
|
|
||||||
data['orgid'] = new_orgid
|
data['orgid'] = new_orgid
|
||||||
|
|
||||||
elif is_external == '0' and not orgid:
|
elif is_external == '0' and not orgid:
|
||||||
result['options'] = {'title': 'Error', 'message': '内部供应商必须选择所属机构', 'type': 'error'}
|
raise Exception('内部供应商必须选择所属机构')
|
||||||
return json.dumps(result, ensure_ascii=False)
|
|
||||||
|
|
||||||
async with DBPools().sqlorContext(dbname) as sor:
|
async with DBPools().sqlorContext(dbname) as sor:
|
||||||
await sor.C('suppliers', data)
|
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:
|
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user