fix: use get_sor_context(env, dbname) — correct sqlor pattern for module Python

env = request._run_ns; get_sor_context(env, 'sage') for products
get_sor_context(env, 'supplychain') for agreement/contract items
This commit is contained in:
yumoqing 2026-07-12 23:05:24 +08:00
parent 49b6cbe85b
commit 41ccfcb301

View File

@ -8,7 +8,7 @@ from datetime import datetime, date
from appPublic.uniqueID import getID from appPublic.uniqueID import getID
from appPublic.jsonConfig import getConfig from appPublic.jsonConfig import getConfig
from appPublic.dictObject import DictObject from appPublic.dictObject import DictObject
from sqlor.dbpools import DBPools from sqlor.dbpools import DBPools, get_sor_context
from ahserver.serverenv import ServerEnv from ahserver.serverenv import ServerEnv
from ahserver.filestorage import FileStorage from ahserver.filestorage import FileStorage
from filemgr.filemgr import FileMgr, FileMgrResult from filemgr.filemgr import FileMgr, FileMgrResult
@ -952,7 +952,8 @@ async def get_agreement_discount_items(request):
userorgid = getattr(ServerEnv(), 'orgid', None) or '0' userorgid = getattr(ServerEnv(), 'orgid', None) or '0'
# Get products from sage # Get products from sage
products = [] products = []
async with DBPools().sqlorContext('sage') as sor: env = request._run_ns
async with get_sor_context(env, 'sage') as sor:
rows = await sor.sqlExe( rows = await sor.sqlExe(
"""SELECT p.id as productid, p.product_name, p.product_code, p.price as sale_price, """SELECT p.id as productid, p.product_name, p.product_code, p.price as sale_price,
pc.id as category_id, pc.name as category_name pc.id as category_id, pc.name as category_name
@ -970,10 +971,9 @@ async def get_agreement_discount_items(request):
'category_id': r.category_id or '', 'category_name': r.category_name or '', 'category_id': r.category_id or '', 'category_name': r.category_name or '',
}) })
# Get existing agreement items from supplychain # Get existing agreement items from supplychain
db, dbname = _get_sor()
items = {} items = {}
if products: if products:
async with db.sqlorContext(dbname) as sor: async with get_sor_context(env, 'supplychain') as sor:
rows = await sor.sqlExe( rows = await sor.sqlExe(
"SELECT id, productid, discount FROM distribution_agreement_items WHERE agreement_id = ${aid}$", "SELECT id, productid, discount FROM distribution_agreement_items WHERE agreement_id = ${aid}$",
{'aid': agreement_id} {'aid': agreement_id}
@ -1001,7 +1001,8 @@ async def get_contract_discount_items(request):
userorgid = getattr(ServerEnv(), 'orgid', None) or '0' userorgid = getattr(ServerEnv(), 'orgid', None) or '0'
# Get products from sage # Get products from sage
products = [] products = []
async with DBPools().sqlorContext('sage') as sor: env = request._run_ns
async with get_sor_context(env, 'sage') as sor:
rows = await sor.sqlExe( rows = await sor.sqlExe(
"""SELECT p.id as productid, p.product_name, p.product_code, p.price as sale_price, """SELECT p.id as productid, p.product_name, p.product_code, p.price as sale_price,
pc.id as category_id, pc.name as category_name pc.id as category_id, pc.name as category_name
@ -1018,10 +1019,9 @@ async def get_contract_discount_items(request):
'category_id': r.category_id or '', 'category_name': r.category_name or '', 'category_id': r.category_id or '', 'category_name': r.category_name or '',
}) })
# Get existing contract items from supplychain # Get existing contract items from supplychain
db, dbname = _get_sor()
items = {} items = {}
if products: if products:
async with db.sqlorContext(dbname) as sor: async with get_sor_context(env, 'supplychain') as sor:
rows = await sor.sqlExe( rows = await sor.sqlExe(
"SELECT id, productid, discount FROM supply_contract_items WHERE contract_id = ${cid}$", "SELECT id, productid, discount FROM supply_contract_items WHERE contract_id = ${cid}$",
{'cid': contract_id} {'cid': contract_id}