supplychain/wwwroot/api/get_agreement_discount_items.dspy
yumoqing 0107eebdcb feat: discount setting UI for agreement/contract items (like discount module pattern)
- agreement_discount_setting.ui: product list with UiFloat discount inputs
- contract_discount_setting.ui: same for supply contracts
- get_agreement_discount_items.dspy + Python function
- get_contract_discount_items.dspy + Python function
- save_agreement_discount.dspy: create/update/delete items on discount change
- save_contract_discount.dspy: same for supply contracts
- Updated distribution_agreements_list and supply_contracts_list subtables
2026-07-12 10:51:18 +08:00

35 lines
1.5 KiB
Plaintext

"""Return all products with their discount status in this distribution agreement."""
agreement_id = params_kw.get('agreement_id') or params_kw.get('id')
if not agreement_id:
return []
userorgid = (await get_userorgid()) or '0'
# Get products available to this org (own + authorized via product_org_auth)
async with DBPools().sqlorContext('sage') as sor:
rows = await sor.sqlExe(
"""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,
dai.id as item_id, dai.discount
FROM product p
LEFT JOIN product_category pc ON p.category_id = pc.id
LEFT JOIN distribution_agreement_items dai ON dai.productid = p.id AND dai.agreement_id = ${aid}$
WHERE p.status = '1'
AND (p.org_id = ${oid}$ OR p.id IN (SELECT product_id FROM product_org_auth WHERE org_id = ${oid}$))
ORDER BY pc.sort_order, pc.name, p.sort_order, p.product_name""",
{'aid': agreement_id, 'oid': userorgid}
)
result = []
for r in rows:
result.append({
'productid': r.productid,
'product_name': r.product_name,
'product_code': r.product_code,
'sale_price': str(r.sale_price) if r.sale_price else '',
'category_id': r.category_id or '',
'category_name': r.category_name or '',
'item_id': r.item_id or '',
'discount': str(r.discount) if r.discount else '1.0',
})
return result