fix: rewrite all create dspy files to use pre-loaded functions
- Removed all imports (json, ServerEnv, datetime, getID) - Replaced datetime.now().strftime with timestampstr() - Added id=getID(), created_at=timestampstr(), updated_at=timestampstr() - Added resellerid from user org context - Used DBPools().sqlorContext pattern - Pass data dict directly to sor.C() without field filtering - Fixed: suppliers, sub_distributors, sub_resellers, distribution_agreements, distribution_agreement_items, supply_contracts, supply_contract_items, platform_supply_products, platform_supply_relations, product_supplier_mapping, sales_ledger, supplychain_accounting
This commit is contained in:
parent
047ec1800a
commit
2dd2953757
@ -1,2 +1,23 @@
|
|||||||
result = await create_distribution_agreement_items(request, params_kw)
|
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
|
||||||
return json.loads(result) if isinstance(result, str) else result
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
async with DBPools().sqlorContext(dbname) as sor:
|
||||||
|
await sor.C('distribution_agreement_items', data)
|
||||||
|
|
||||||
|
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '分销协议项目创建成功', 'type': 'success'}}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'}
|
||||||
|
|
||||||
|
return json.dumps(result, ensure_ascii=False)
|
||||||
|
|||||||
@ -1,2 +1,23 @@
|
|||||||
result = await create_distribution_agreements(request, params_kw)
|
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
|
||||||
return json.loads(result) if isinstance(result, str) else result
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
async with DBPools().sqlorContext(dbname) as sor:
|
||||||
|
await sor.C('distribution_agreements', data)
|
||||||
|
|
||||||
|
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '分销协议创建成功', 'type': 'success'}}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'}
|
||||||
|
|
||||||
|
return json.dumps(result, ensure_ascii=False)
|
||||||
|
|||||||
@ -1,5 +1,23 @@
|
|||||||
create_func = create_platform_supply_products
|
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
|
||||||
if create_func is None:
|
|
||||||
return json.dumps({"status": "error", "message": "create_platform_supply_products not registered"})
|
try:
|
||||||
result = await create_func(request, params_kw)
|
user_id = await get_user()
|
||||||
return result
|
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()
|
||||||
|
|
||||||
|
async with DBPools().sqlorContext(dbname) as sor:
|
||||||
|
await sor.C('platform_supply_products', data)
|
||||||
|
|
||||||
|
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '平台供应产品创建成功', 'type': 'success'}}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'}
|
||||||
|
|
||||||
|
return json.dumps(result, ensure_ascii=False)
|
||||||
|
|||||||
@ -1,5 +1,23 @@
|
|||||||
create_func = create_platform_supply_relations
|
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
|
||||||
if create_func is None:
|
|
||||||
return json.dumps({"status": "error", "message": "create_platform_supply_relations not registered"})
|
try:
|
||||||
result = await create_func(request, params_kw)
|
user_id = await get_user()
|
||||||
return result
|
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()
|
||||||
|
|
||||||
|
async with DBPools().sqlorContext(dbname) as sor:
|
||||||
|
await sor.C('platform_supply_relations', data)
|
||||||
|
|
||||||
|
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '平台供应关系创建成功', 'type': 'success'}}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'}
|
||||||
|
|
||||||
|
return json.dumps(result, ensure_ascii=False)
|
||||||
|
|||||||
@ -1,5 +1,23 @@
|
|||||||
create_func = create_product_supplier_mapping
|
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
|
||||||
if create_func is None:
|
|
||||||
return json.dumps({"status": "error", "message": "create_product_supplier_mapping not registered"})
|
try:
|
||||||
result = await create_func(request, params_kw)
|
user_id = await get_user()
|
||||||
return result
|
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()
|
||||||
|
|
||||||
|
async with DBPools().sqlorContext(dbname) as sor:
|
||||||
|
await sor.C('product_supplier_mapping', data)
|
||||||
|
|
||||||
|
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '产品供应商映射创建成功', 'type': 'success'}}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'}
|
||||||
|
|
||||||
|
return json.dumps(result, ensure_ascii=False)
|
||||||
|
|||||||
@ -1,9 +1,23 @@
|
|||||||
import json
|
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
|
||||||
from ahserver.serverenv import ServerEnv
|
|
||||||
env = ServerEnv()
|
try:
|
||||||
create_func = getattr(env, 'create_sales_ledger', None)
|
user_id = await get_user()
|
||||||
if create_func is None:
|
user_orgid = (await get_userorgid()) or '0'
|
||||||
print(json.dumps({"status": "error", "message": "create_sales_ledger function not found"}))
|
dbname = get_module_dbname('supplychain')
|
||||||
else:
|
|
||||||
result = await create_func(request, params_kw)
|
data = dict(params_kw)
|
||||||
print(result)
|
data['id'] = getID()
|
||||||
|
data['resellerid'] = user_orgid
|
||||||
|
data['created_by'] = user_id
|
||||||
|
data['created_at'] = timestampstr()
|
||||||
|
data['updated_at'] = timestampstr()
|
||||||
|
|
||||||
|
async with DBPools().sqlorContext(dbname) as sor:
|
||||||
|
await sor.C('sales_ledger', data)
|
||||||
|
|
||||||
|
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '销售台账创建成功', 'type': 'success'}}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'}
|
||||||
|
|
||||||
|
return json.dumps(result, ensure_ascii=False)
|
||||||
|
|||||||
@ -1,2 +1,23 @@
|
|||||||
result = await create_sub_distributors(request, params_kw)
|
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
|
||||||
return json.loads(result) if isinstance(result, str) else result
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
async with DBPools().sqlorContext(dbname) as sor:
|
||||||
|
await sor.C('sub_distributors', data)
|
||||||
|
|
||||||
|
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '分销商创建成功', 'type': 'success'}}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'}
|
||||||
|
|
||||||
|
return json.dumps(result, ensure_ascii=False)
|
||||||
|
|||||||
@ -1,9 +1,23 @@
|
|||||||
import json
|
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
|
||||||
from ahserver.serverenv import ServerEnv
|
|
||||||
env = ServerEnv()
|
try:
|
||||||
create_func = getattr(env, 'create_sub_resellers', None)
|
user_id = await get_user()
|
||||||
if create_func is None:
|
user_orgid = (await get_userorgid()) or '0'
|
||||||
print(json.dumps({"status": "error", "message": "create_sub_resellers function not found"}))
|
dbname = get_module_dbname('supplychain')
|
||||||
else:
|
|
||||||
result = await create_func(request, params_kw)
|
data = dict(params_kw)
|
||||||
print(result)
|
data['id'] = getID()
|
||||||
|
data['resellerid'] = user_orgid
|
||||||
|
data['created_by'] = user_id
|
||||||
|
data['created_at'] = timestampstr()
|
||||||
|
data['updated_at'] = timestampstr()
|
||||||
|
|
||||||
|
async with DBPools().sqlorContext(dbname) as sor:
|
||||||
|
await sor.C('sub_resellers', data)
|
||||||
|
|
||||||
|
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '经销商创建成功', 'type': 'success'}}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'}
|
||||||
|
|
||||||
|
return json.dumps(result, ensure_ascii=False)
|
||||||
|
|||||||
@ -1,9 +1,23 @@
|
|||||||
import json
|
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
|
||||||
from ahserver.serverenv import ServerEnv
|
|
||||||
env = ServerEnv()
|
try:
|
||||||
create_func = getattr(env, 'create_suppliers', None)
|
user_id = await get_user()
|
||||||
if create_func is None:
|
user_orgid = (await get_userorgid()) or '0'
|
||||||
print(json.dumps({"status": "error", "message": "create_suppliers function not found"}))
|
dbname = get_module_dbname('supplychain')
|
||||||
else:
|
|
||||||
result = await create_func(request, params_kw)
|
data = dict(params_kw)
|
||||||
print(result)
|
data['id'] = getID()
|
||||||
|
data['resellerid'] = user_orgid
|
||||||
|
data['created_by'] = user_id
|
||||||
|
data['created_at'] = timestampstr()
|
||||||
|
data['updated_at'] = timestampstr()
|
||||||
|
|
||||||
|
async with DBPools().sqlorContext(dbname) as sor:
|
||||||
|
await sor.C('suppliers', data)
|
||||||
|
|
||||||
|
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '供应商创建成功', 'type': 'success'}}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'}
|
||||||
|
|
||||||
|
return json.dumps(result, ensure_ascii=False)
|
||||||
|
|||||||
@ -1,2 +1,23 @@
|
|||||||
result = await create_supply_contract_items(request, params_kw)
|
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
|
||||||
return json.loads(result) if isinstance(result, str) else result
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
async with DBPools().sqlorContext(dbname) as sor:
|
||||||
|
await sor.C('supply_contract_items', data)
|
||||||
|
|
||||||
|
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '供应合同项目创建成功', 'type': 'success'}}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'}
|
||||||
|
|
||||||
|
return json.dumps(result, ensure_ascii=False)
|
||||||
|
|||||||
@ -1,2 +1,23 @@
|
|||||||
result = await create_supply_contracts(request, params_kw)
|
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
|
||||||
return json.loads(result) if isinstance(result, str) else result
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
async with DBPools().sqlorContext(dbname) as sor:
|
||||||
|
await sor.C('supply_contracts', data)
|
||||||
|
|
||||||
|
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '供应合同创建成功', 'type': 'success'}}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'}
|
||||||
|
|
||||||
|
return json.dumps(result, ensure_ascii=False)
|
||||||
|
|||||||
@ -1,24 +1,23 @@
|
|||||||
import json
|
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
|
||||||
from appPublic.uniqueID import getID
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
async def main(request, params_kw):
|
try:
|
||||||
"""Create a new supplychain_accounting record."""
|
|
||||||
user_id = await get_user()
|
user_id = await get_user()
|
||||||
user_orgid = await get_userorgid()
|
user_orgid = (await get_userorgid()) or '0'
|
||||||
dbname = get_module_dbname('supplychain')
|
dbname = get_module_dbname('supplychain')
|
||||||
|
|
||||||
data = params_kw.get("data", "{}")
|
data = dict(params_kw)
|
||||||
if isinstance(data, str):
|
data['id'] = getID()
|
||||||
data = json.loads(data)
|
data['resellerid'] = user_orgid
|
||||||
|
data['created_by'] = user_id
|
||||||
|
data['created_at'] = timestampstr()
|
||||||
|
data['updated_at'] = timestampstr()
|
||||||
|
|
||||||
data["id"] = getID()
|
async with DBPools().sqlorContext(dbname) as sor:
|
||||||
data["resellerid"] = user_orgid
|
await sor.C('supplychain_accounting', data)
|
||||||
data["created_by"] = user_id
|
|
||||||
data["created_at"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
||||||
|
|
||||||
config = getConfig(".")
|
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '供应链记账创建成功', 'type': 'success'}}
|
||||||
DBPools(config.databases)
|
|
||||||
async with db.sqlorContext(dbname) as sor:
|
except Exception as e:
|
||||||
await sor.C("supplychain_accounting", data)
|
result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'}
|
||||||
return json.dumps({"status": "ok", "data": data})
|
|
||||||
|
return json.dumps(result, ensure_ascii=False)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user