fix: OTC 라벨 검색 시 CD_ITEM_UNIT_MEMBER 바코드 포함

- CD_GOODS.Barcode가 없어도 CD_ITEM_UNIT_MEMBER에서 바코드 조회
- 바코드 없는 제품도 검색 결과에 포함
This commit is contained in:
thug0bin 2026-03-02 17:35:13 +09:00
parent 007b37e6c6
commit 4713395557

View File

@ -5606,17 +5606,22 @@ def api_search_mssql_drug():
mssql_session = db_manager.get_session('PM_DRUG')
# 바코드 또는 이름으로 검색
# 바코드 또는 이름으로 검색 (CD_ITEM_UNIT_MEMBER 바코드 포함)
sql = text("""
SELECT TOP 20
DrugCode, Barcode, GoodsName, Saleprice
FROM CD_GOODS
WHERE (Barcode LIKE :query OR GoodsName LIKE :query)
AND Barcode IS NOT NULL
AND Barcode != ''
G.DrugCode,
COALESCE(NULLIF(G.Barcode, ''),
(SELECT TOP 1 CD_CD_BARCODE FROM CD_ITEM_UNIT_MEMBER WHERE DrugCode = G.DrugCode)
) AS Barcode,
G.GoodsName,
G.Saleprice
FROM CD_GOODS G
WHERE G.GoodsName LIKE :query
OR G.Barcode LIKE :query
OR G.DrugCode IN (SELECT DrugCode FROM CD_ITEM_UNIT_MEMBER WHERE CD_CD_BARCODE LIKE :query)
ORDER BY
CASE WHEN Barcode = :exact THEN 0 ELSE 1 END,
GoodsName
CASE WHEN G.Barcode = :exact THEN 0 ELSE 1 END,
G.GoodsName
""")
rows = mssql_session.execute(sql, {