feat(malaysia): 재고조사 확정 후 자동 비교 엑셀 다운로드 추가

마감재고 + 마감 다음날~오늘 일자별 순변동(IN-OUT±ADJUST±STOCKTAKE) = 계산값과
오늘 전산재고(current_stock)를 아이템별로 비교하는 엑셀(2시트: 비교/일자별순변동).
확정된 재고조사 상세 화면에 "자동 비교 엑셀 다운로드" 버튼으로 노출.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-20 21:14:45 +09:00
parent 85c7333e72
commit 0f00529761
3 changed files with 174 additions and 0 deletions
+36
View File
@@ -432,6 +432,42 @@ class MalaysiaStockStore:
for r in rows
]
def movement_net_totals_by_date(
self, *, warehouse_code: str, date_from: str, date_to: str
) -> list[dict[str, Any]]:
"""기간 내 일자 × 낱개 아이템별 '부호 포함 순변동' 합계.
`current_stock()` 과 동일한 부호 규칙: IN=+, OUT=-, ADJUST/STOCKTAKE 는
저장된 부호 그대로. 재고조사 확정 이후 순변동을 날짜별로 추적할 때 사용.
반환: [{"movement_date": "2026-09-10", "item_code": "MT-0750", "net_qty": -3}, ...]
"""
with self._pool.connection() as conn:
rows = conn.execute(
"""
SELECT movement_date, item_code,
SUM(CASE
WHEN movement_type = 'IN' THEN qty
WHEN movement_type = 'OUT' THEN -qty
ELSE qty -- ADJUST/STOCKTAKE 는 부호 포함 저장
END) AS net_qty
FROM stock_movement
WHERE warehouse_code = %s
AND movement_date >= %s
AND movement_date <= %s
GROUP BY movement_date, item_code
ORDER BY movement_date, item_code
""",
(warehouse_code, date_from, date_to),
).fetchall()
return [
{
"movement_date": str(r["movement_date"]),
"item_code": r["item_code"],
"net_qty": int(r["net_qty"] or 0),
}
for r in rows
]
def current_stock(self, *, warehouse_code: str) -> dict[str, int]:
"""창고별 현재고(낱개 아이템 기준).