fix: 사용약품만 쿼리에서 단위바코드 조회 누락 수정
문제: 대표바코드(CD_GOODS.BARCODE)가 비어있으면 '없음'으로 표시 원인: in_stock_only 쿼리에 CD_ITEM_UNIT_MEMBER OUTER APPLY 누락 수정: - in_stock_only 쿼리에 단위바코드 조회 추가 - animal_only 쿼리에도 동일하게 추가 - COALESCE(대표바코드, 단위바코드, '') 순서로 조회
This commit is contained in:
parent
27bb0b7b86
commit
e95c08ef59
@ -3335,11 +3335,12 @@ def api_products():
|
||||
# 제품 검색 쿼리 - 사용약품만 옵션에 따라 JOIN 방식 변경
|
||||
if in_stock_only:
|
||||
# 최적화된 쿼리: 재고 있는 제품만 (IM_total INNER JOIN)
|
||||
# 대표바코드(G.BARCODE) 없으면 단위바코드(CD_ITEM_UNIT_MEMBER) 사용
|
||||
products_query = text(f"""
|
||||
SELECT TOP {limit}
|
||||
G.DrugCode as drug_code,
|
||||
G.GoodsName as product_name,
|
||||
COALESCE(NULLIF(G.BARCODE, ''), '') as barcode,
|
||||
COALESCE(NULLIF(G.BARCODE, ''), U.CD_CD_BARCODE, '') as barcode,
|
||||
G.Saleprice as sale_price,
|
||||
G.Price as cost_price,
|
||||
ISNULL(G.SplName, '') as supplier,
|
||||
@ -3350,6 +3351,11 @@ def api_products():
|
||||
FROM CD_GOODS G
|
||||
INNER JOIN IM_total IT ON G.DrugCode = IT.DrugCode AND IT.IM_QT_sale_debit > 0
|
||||
LEFT JOIN CD_item_position POS ON G.DrugCode = POS.DrugCode
|
||||
OUTER APPLY (
|
||||
SELECT TOP 1 CD_CD_BARCODE
|
||||
FROM CD_ITEM_UNIT_MEMBER
|
||||
WHERE DRUGCODE = G.DrugCode AND CD_CD_BARCODE IS NOT NULL AND CD_CD_BARCODE != ''
|
||||
) U
|
||||
WHERE 1=1
|
||||
{animal_condition}
|
||||
{search_condition}
|
||||
@ -3363,7 +3369,7 @@ def api_products():
|
||||
SELECT TOP {limit}
|
||||
G.DrugCode as drug_code,
|
||||
G.GoodsName as product_name,
|
||||
COALESCE(NULLIF(G.BARCODE, ''), '') as barcode,
|
||||
COALESCE(NULLIF(G.BARCODE, ''), U.CD_CD_BARCODE, '') as barcode,
|
||||
G.Saleprice as sale_price,
|
||||
G.Price as cost_price,
|
||||
ISNULL(G.SplName, '') as supplier,
|
||||
@ -3374,6 +3380,11 @@ def api_products():
|
||||
FROM CD_GOODS G
|
||||
LEFT JOIN IM_total IT ON G.DrugCode = IT.DrugCode
|
||||
LEFT JOIN CD_item_position POS ON G.DrugCode = POS.DrugCode
|
||||
OUTER APPLY (
|
||||
SELECT TOP 1 CD_CD_BARCODE
|
||||
FROM CD_ITEM_UNIT_MEMBER
|
||||
WHERE DRUGCODE = G.DrugCode AND CD_CD_BARCODE IS NOT NULL AND CD_CD_BARCODE != ''
|
||||
) U
|
||||
WHERE G.POS_BOON = '010103'
|
||||
{search_condition}
|
||||
ORDER BY G.GoodsName
|
||||
|
||||
Loading…
Reference in New Issue
Block a user