feat(malaysia): 이동 이력 일자별 낱개 수량 엑셀 다운로드
기간 전체를 일자 x 낱개 아이템 피벗으로 내려받는 /movements/export-daily 추가. 콤보(세트) 출고는 등록 시 이미 BOM 으로 분해돼 구성 낱개 OUT movement 로 저장되므로 별도 분해 없이 낱개 기준 합계에 포함된다. - db.movement_totals_by_date(): 기간/종류별 일자 x 아이템 합계 - 시트 '일자별'(행=날짜, 열=아이템, 합계 행/열) + '상세'(긴 형식, 자동필터) - 이동 이력 카드에 종류/기간 선택 + 다운로드 버튼 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -388,6 +388,50 @@ class MalaysiaStockStore:
|
||||
).fetchall()
|
||||
return {r["item_code"]: int(r["qty"] or 0) for r in rows}
|
||||
|
||||
def movement_totals_by_date(
|
||||
self,
|
||||
*,
|
||||
warehouse_code: str,
|
||||
movement_type: str,
|
||||
date_from: str | None = None,
|
||||
date_to: str | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""기간 내 일자 × 낱개 아이템별 합계 수량.
|
||||
|
||||
세트(콤보) 출고는 생성 시 이미 구성품 OUT movement 로 분해 저장되므로
|
||||
(`create_set_out`) 여기서 별도 분해 없이 낱개 기준으로 합산된다.
|
||||
반환: [{"movement_date": "2026-09-09", "item_code": "MT-0750", "qty": 12}, ...]
|
||||
"""
|
||||
if movement_type not in store.MOVEMENT_TYPES:
|
||||
raise ValueError(f"허용되지 않는 이동 종류: {movement_type}")
|
||||
clauses = ["warehouse_code = %s", "movement_type = %s"]
|
||||
params: list[Any] = [warehouse_code, movement_type]
|
||||
if date_from:
|
||||
clauses.append("movement_date >= %s")
|
||||
params.append(date_from)
|
||||
if date_to:
|
||||
clauses.append("movement_date <= %s")
|
||||
params.append(date_to)
|
||||
with self._pool.connection() as conn:
|
||||
rows = conn.execute(
|
||||
f"""
|
||||
SELECT movement_date, item_code, SUM(qty) AS qty
|
||||
FROM stock_movement
|
||||
WHERE {" AND ".join(clauses)}
|
||||
GROUP BY movement_date, item_code
|
||||
ORDER BY movement_date, item_code
|
||||
""",
|
||||
params,
|
||||
).fetchall()
|
||||
return [
|
||||
{
|
||||
"movement_date": str(r["movement_date"]),
|
||||
"item_code": r["item_code"],
|
||||
"qty": int(r["qty"] or 0),
|
||||
}
|
||||
for r in rows
|
||||
]
|
||||
|
||||
def current_stock(self, *, warehouse_code: str) -> dict[str, int]:
|
||||
"""창고별 현재고(낱개 아이템 기준).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user