feat(performance): 직접 추가 쇼핑몰(수동 입력)·쇼핑몰 그룹·설정 드래그 순서
- 마이그레이션 009: perf_marketplaces.is_custom·is_group·parent_code - 설정: [+ 쇼핑몰 추가(수동 입력)]·[+ 그룹 추가], 이름 변경·삭제, 직접 추가 쇼핑몰 그룹 select - custom_ 코드는 registry.get_adapter 가 수동 입력 전용 어댑터(CustomManualAdapter)로 - 매출 실적 표: 그룹 열 = 보이는 하위 쇼핑몰 합계(일 합계엔 안 더함), ▾/▸ 하위 열 접기(localStorage) - 설정 표 ⠿ 드래그 → PUT /api/marketplace-order → sort_order, 화면 순서는 ordered_marketplaces 한 곳 - 테스트: test_custom_groups.py, perf_groups.browser.test.js Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -30,6 +30,10 @@ class ManualMigrationNeeded(Exception):
|
||||
"""수동 입력(마이그레이션 002: perf_marketplaces.manual_input · perf_manual_sales)이 아직 적용되지 않음."""
|
||||
|
||||
|
||||
class CustomMigrationNeeded(Exception):
|
||||
"""직접 추가 쇼핑몰·그룹(마이그레이션 009: perf_marketplaces.is_custom · is_group · parent_code)이 아직 적용되지 않음."""
|
||||
|
||||
|
||||
def _set_formulas(conn: Any, table: str, key_col: str, date_col: str,
|
||||
rows: list[tuple[str, date, str | None]]) -> None:
|
||||
"""날짜 칸 계산식(마이그레이션 008) 덮어쓰기 — 식이 없으면 지움. 008 미적용이면 조용히 건너뛴다
|
||||
@@ -103,6 +107,72 @@ class PerformanceDBStore:
|
||||
raise ManualMigrationNeeded() from None
|
||||
return {k: _iso(v) for k, v in row.items()} if row else None
|
||||
|
||||
# ── 직접 추가 쇼핑몰·그룹(마이그레이션 009) ──
|
||||
def add_custom_marketplace(self, code: str, name: str, *, is_group: bool) -> dict[str, Any]:
|
||||
"""맨 뒤 순서로 추가. 쇼핑몰 = 수동 입력 전용(manual_input), 그룹 = 매출 없음(include_in_sales 꺼 둠)."""
|
||||
try:
|
||||
with self._pool.connection() as conn:
|
||||
row = conn.execute(
|
||||
"INSERT INTO perf_marketplaces (code, name, sort_order, manual_input, include_in_sales, is_custom, is_group) "
|
||||
"SELECT %s, %s, COALESCE(MAX(sort_order), 0) + 10, %s, %s, TRUE, %s FROM perf_marketplaces RETURNING *",
|
||||
(code, name, not is_group, not is_group, is_group),
|
||||
).fetchone()
|
||||
except pg_errors.UndefinedColumn:
|
||||
raise CustomMigrationNeeded() from None
|
||||
return {k: _iso(v) for k, v in row.items()}
|
||||
|
||||
def rename_marketplace(self, code: str, name: str) -> dict[str, Any] | None:
|
||||
with self._pool.connection() as conn:
|
||||
row = conn.execute("UPDATE perf_marketplaces SET name = %s WHERE code = %s RETURNING *", (name, code)).fetchone()
|
||||
return {k: _iso(v) for k, v in row.items()} if row else None
|
||||
|
||||
def set_marketplace_parent(self, code: str, parent_code: str | None) -> dict[str, Any] | None:
|
||||
try:
|
||||
with self._pool.connection() as conn:
|
||||
row = conn.execute("UPDATE perf_marketplaces SET parent_code = %s WHERE code = %s RETURNING *",
|
||||
(parent_code, code)).fetchone()
|
||||
except pg_errors.UndefinedColumn:
|
||||
raise CustomMigrationNeeded() from None
|
||||
return {k: _iso(v) for k, v in row.items()} if row else None
|
||||
|
||||
def delete_custom_marketplace(self, code: str) -> bool:
|
||||
"""직접 추가 행 삭제 — 그 쇼핑몰 수동 입력·수수료·상태·(테스트) 매출 행도 함께, 그룹이면 하위 쇼핑몰은 그룹 없음으로.
|
||||
기본 쇼핑몰(is_custom = FALSE)은 지우지 않는다."""
|
||||
with self._pool.connection() as conn:
|
||||
with conn.transaction():
|
||||
row = conn.execute("SELECT is_custom FROM perf_marketplaces WHERE code = %s FOR UPDATE", (code,)).fetchone()
|
||||
if not row or not row.get("is_custom"):
|
||||
return False
|
||||
conn.execute("UPDATE perf_marketplaces SET parent_code = NULL WHERE parent_code = %s", (code,))
|
||||
for table in ("perf_manual_sales", "perf_commission_rates", "perf_credentials",
|
||||
"perf_connection_status", "perf_sales_events", "perf_sync_runs"):
|
||||
conn.execute(f"DELETE FROM {table} WHERE marketplace_code = %s", (code,))
|
||||
conn.execute("DELETE FROM perf_marketplaces WHERE code = %s", (code,))
|
||||
return True
|
||||
|
||||
def manual_day_count(self, code: str) -> int:
|
||||
"""수동 입력해 둔 날 수 — 직접 추가 쇼핑몰 삭제 확인 문구용."""
|
||||
try:
|
||||
with self._pool.connection() as conn:
|
||||
row = conn.execute("SELECT COUNT(*) AS n FROM perf_manual_sales WHERE marketplace_code = %s",
|
||||
(code,)).fetchone()
|
||||
except pg_errors.UndefinedTable:
|
||||
return 0
|
||||
return int(row["n"] or 0)
|
||||
|
||||
def reorder_marketplaces(self, codes: list[str]) -> None:
|
||||
"""설정 화면 드래그 순서 — 받은 순서대로 sort_order 10, 20, … (목록에 없는 행은 그 뒤 예전 순서)."""
|
||||
with self._pool.connection() as conn:
|
||||
with conn.transaction():
|
||||
rest = [r["code"] for r in conn.execute(
|
||||
"SELECT code FROM perf_marketplaces WHERE NOT (code = ANY(%s)) ORDER BY sort_order, code", (codes,)
|
||||
).fetchall()]
|
||||
with conn.cursor() as cur:
|
||||
cur.executemany(
|
||||
"UPDATE perf_marketplaces SET sort_order = %s WHERE code = %s AND sort_order IS DISTINCT FROM %s",
|
||||
[((i + 1) * 10, c, (i + 1) * 10) for i, c in enumerate([*codes, *rest])],
|
||||
)
|
||||
|
||||
# ════════════════════════════════════════════════════════════
|
||||
# 수수료율 이력
|
||||
# ════════════════════════════════════════════════════════════
|
||||
|
||||
Reference in New Issue
Block a user