From 0bdb019e29e7bf69d5dd3273bacd6c648d1c569d Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 1 Jul 2026 16:01:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BE=9B=E5=BA=94=E5=95=86=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E5=90=8C=E6=AD=A5org+=E5=BC=80=E8=B4=A6,=E5=8E=BBjson?= =?UTF-8?q?.dumps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wwwroot/api/suppliers_create.dspy | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/wwwroot/api/suppliers_create.dspy b/wwwroot/api/suppliers_create.dspy index a4485c2..8b1e019 100644 --- a/wwwroot/api/suppliers_create.dspy +++ b/wwwroot/api/suppliers_create.dspy @@ -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