fix: 供销协议折扣明细按供应商org过滤产品
- get_contract_discount_items: 改为根据合同的supplier_id查询供应商的orgid, 用供应商orgid过滤产品列表,而非用当前用户orgid过滤 - get_agreement_discount_items: ServerEnv()裸单例→request._run_ns.get_userorgid() 解决env.orgid永远为None导致回退到'0'的问题
This commit is contained in:
parent
e7a4535423
commit
de10fb00f3
Binary file not shown.
@ -949,10 +949,10 @@ async def get_agreement_discount_items(request):
|
||||
agreement_id = params_kw.get('agreement_id') or params_kw.get('id')
|
||||
if not agreement_id:
|
||||
return []
|
||||
userorgid = getattr(ServerEnv(), 'orgid', None) or '0'
|
||||
env = request._run_ns
|
||||
userorgid = await env.get_userorgid() or '0'
|
||||
# Get products from sage
|
||||
products = []
|
||||
env = request._run_ns
|
||||
async with get_sor_context(env, 'sage') as sor:
|
||||
rows = await sor.sqlExe(
|
||||
"""SELECT p.id as productid, p.product_name, p.product_code, p.price as sale_price,
|
||||
@ -993,15 +993,29 @@ async def get_agreement_discount_items(request):
|
||||
|
||||
|
||||
async def get_contract_discount_items(request):
|
||||
"""Return products with discount status for a supply contract."""
|
||||
"""Return products with discount status for a supply contract.
|
||||
|
||||
Products are filtered by the contract's supplier org_id — only products
|
||||
belonging to the supplier should appear in the supplier agreement.
|
||||
"""
|
||||
params_kw = getattr(request._run_ns, 'params_kw', {}) or {}
|
||||
contract_id = params_kw.get('contract_id') or params_kw.get('id')
|
||||
if not contract_id:
|
||||
return []
|
||||
userorgid = getattr(ServerEnv(), 'orgid', None) or '0'
|
||||
# Get products from sage
|
||||
products = []
|
||||
env = request._run_ns
|
||||
# Get supplier_orgid from the contract's supplier
|
||||
supplier_orgid = '0'
|
||||
async with get_sor_context(env, 'supplychain') as sor:
|
||||
rows = await sor.sqlExe(
|
||||
"SELECT s.orgid FROM suppliers s "
|
||||
"JOIN supply_contracts sc ON sc.supplier_id = s.id "
|
||||
"WHERE sc.id = ${cid}$",
|
||||
{'cid': contract_id}
|
||||
)
|
||||
if rows and rows[0].orgid:
|
||||
supplier_orgid = rows[0].orgid
|
||||
# Get products from sage — only this supplier's products
|
||||
products = []
|
||||
async with get_sor_context(env, 'sage') as sor:
|
||||
rows = await sor.sqlExe(
|
||||
"""SELECT p.id as productid, p.product_name, p.product_code, p.price as sale_price,
|
||||
@ -1010,7 +1024,7 @@ async def get_contract_discount_items(request):
|
||||
LEFT JOIN product_category pc ON p.category_id = pc.id
|
||||
WHERE p.status = '1' AND p.org_id = ${oid}$
|
||||
ORDER BY pc.sort_order, pc.name, p.sort_order, p.product_name""",
|
||||
{'oid': userorgid}
|
||||
{'oid': supplier_orgid}
|
||||
)
|
||||
for r in rows:
|
||||
products.append({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user