[feat] negodata: 낙찰 방식 구분(자동/직접) + 계약가·사유 저장 위치 재정리

직접 낙찰(담당자 오프라인 계약가)을 AI 자동 낙찰과 통계·화면에서 구분하기 위해
낙찰 방식을 전용 컬럼으로 박고, 계약가·사유를 성격대로 배치했다. 처음엔 계약가·사유를
sessions.custom.offline_award(JSONB) 한 뭉치에 넣었으나 성격이 갈려 정리한다.

DB (postgres-init: init.sql 정본 + alters/2026-08-11-award-type.sql 보정, 멱등)
- quotations.award_type SMALLINT — 낙찰 방식(1=자동/2=직접). 통계 조회·집계 축이라 컬럼
- quotations.custom JSONB — 직접 낙찰 사유·처리자·시각(award={reason,by,at}). 표시·감사용
- sessions.contract_price BIGINT — 직접 낙찰 계약가. bid_price/reject_price 와 같은 협력사
  가격 축이라 세션에. 자동 낙찰은 NULL(투찰가가 곧 계약가)
- 기존 offline_award(JSONB) 데이터를 컬럼·견적 custom 으로 이관 후 키 제거

backend
- 자동 낙찰(close_and_decide)=AUTO, 직접 낙찰(claim_for_award)=MANUAL 로 award_type 기록
- 직접 낙찰: 계약가→세션 contract_price, 사유·처리자·시각→견적 custom.award (한 트랜잭션)
- 통계 계약가 = coalesce(contract_price, bid_price) — JSONB 캐스팅 제거(컬럼끼리, 인덱스·타입 안전)
- QuotationData 에 award_type·custom, SessionData 에 contract_price 노출
- 안 쓰게 된 merge_session_custom 제거

front
- 견적 상세 결과 밴드에 '직접 낙찰' 배지 + 낙찰 사유 표시(견적 custom.award.reason).
  거부·미참여 낙찰은 이미 직접 낙찰을 함의하므로 '— 낙찰' 꼬리를 떼 중복 표기 제거
- 목록 결과 배지에 '낙찰(직접)' 표기 — AI 자동낙찰과 한눈에 구분
- offlineAward()→directAwardPrice()/awardMeta() 로 교체(세션 컬럼·견적 custom 에서 읽음)
- 협상현황 표: 부가정보(회사 필드)와 의견(custom.opinion)을 별도 컬럼으로 분리
- 미응찰 건 레일 4번 칸 라벨 '최저 투찰가'→'결과'(투찰 없을 때)

테스트: negodata 110건 통과. 프론트 tsc+eslint 통과. dev DB 적용·화면 확인.
This commit is contained in:
minaChoi committed 2026-08-12 10:25:26 +09:00
1 parent 6eb4dc26f8
commit 0e4ddf0f43
22 files changed
+292 -63

No files matched your search

+16 -10
View File
@@ -15,7 +15,7 @@ from datetime import datetime
import pytest_asyncio
from sqlalchemy import text
from common.enums import CloseReason, ErrorType, QuotationStatus, QuotationType, SessionStatus, UserRole
from common.enums import AwardType, CloseReason, ErrorType, QuotationStatus, QuotationType, SessionStatus, UserRole
from crud.quotation_crud import QuotationCRUD
from services.quotation import QuotationService
@@ -44,6 +44,7 @@ async def test_award_opened_sets_winner_and_notifies(clean):
assert res.result.success is True
row = await _quotation(engine, qt)
assert row.close_reason == CloseReason.AWARDED.value
assert row.award_type == AwardType.MANUAL.value # 직접 낙찰 — 통계에서 자동낙찰과 구분
assert row.preferred_sp_yn is True
assert str(row.preferred_sp_id) == str(supplier_a)
assert row.equal_bid_yn is False
@@ -141,9 +142,9 @@ async def test_award_allows_owner_role(clean):
assert len(await _notifications(engine, admin)) == 0
async def test_award_records_contract_price_on_session(clean):
async def test_award_records_contract_price_and_reason(clean):
"""검증: 협력사 제출가(100)와 다른 계약가(88)로 직접 낙찰 — 오프라인 재협상 결과 반영.
기대결과: 낙찰 세션 custom.offline_award 에 계약가·메모가 남고, 알림 winner_price 도 계약가."""
기대결과: 계약가는 낙찰 세션 contract_price 컬럼에, 사유·처리자는 견적 custom.award 에 남고, 알림 winner_price 도 계약가."""
engine = clean
user_id, supplier_a = uuid.uuid4(), uuid.uuid4()
qt = await _seed_opened(engine, user_id=user_id, number="A-OFFLINE", close_reason=CloseReason.OPEN_PRICE.value)
@@ -155,13 +156,18 @@ async def test_award_records_contract_price_on_session(clean):
assert res.result.success is True
async with engine.begin() as conn:
row = (await conn.execute(
text("SELECT custom FROM sessions WHERE quotation_id = :qt AND supplier_id = :sp"),
# 계약가 = 세션 컬럼(협력사 가격 — bid_price/reject_price 와 같은 축)
sess_price = (await conn.execute(
text("SELECT contract_price FROM sessions WHERE quotation_id = :qt AND supplier_id = :sp"),
{"qt": qt, "sp": supplier_a},
)).first()
award = row.custom["offline_award"]
assert award["price"] == 88
assert award["note"] == "오프라인 협상, 8/12 통화 합의"
)).scalar()
# 사유·처리자 = 견적 custom.award(견적 단위 결정)
qt_custom = (await conn.execute(
text("SELECT custom FROM quotations WHERE qt_id = :qt"), {"qt": qt},
)).scalar()
assert sess_price == 88
award = qt_custom["award"]
assert award["reason"] == "오프라인 협상, 8/12 통화 합의"
assert award["by"] == str(user_id)
notis = await _notifications(engine, user_id)
assert notis[0][1]["winner_price"] == 88
@@ -245,7 +251,7 @@ async def _quotation(engine, qt_id):
"""견적 1행(마감 결과 컬럼 확인용)."""
async with engine.begin() as conn:
return (await conn.execute(
text("SELECT close_reason, preferred_sp_yn, preferred_sp_id, equal_bid_yn "
text("SELECT close_reason, award_type, preferred_sp_yn, preferred_sp_id, equal_bid_yn "
"FROM quotations WHERE qt_id = :qt_id"),
{"qt_id": qt_id},
)).one()
+3 -2
View File
@@ -20,7 +20,7 @@ from apscheduler.schedulers.asyncio import AsyncIOScheduler
from apscheduler.triggers.interval import IntervalTrigger
from sqlalchemy import text
from common.enums import QuotationStatus, QuotationType, SessionStatus
from common.enums import AwardType, QuotationStatus, QuotationType, SessionStatus
from scheduler import jobs
PAST = datetime(2020, 1, 1) # 마감시각이 이미 지난 시점(잡①의 마감 대상)
@@ -95,6 +95,7 @@ async def test_award_single_lowest(clean):
assert row.status == QuotationStatus.CLOSED.value
assert row.preferred_sp_yn is True # 낙찰자 있음
assert str(row.preferred_sp_id) == str(winner) # 최저가가 단독이라 그 공급사로 확정
assert row.award_type == AwardType.AUTO.value # 자동 낙찰(투찰가 기준)
async def test_rejected_just_closes(clean):
@@ -205,6 +206,6 @@ async def _quotation_row(engine, qt_id):
"""견적 1건을 다시 읽어온다(마감 후 status·낙찰자 확인용)."""
async with engine.begin() as conn:
return (await conn.execute(
text("SELECT status, preferred_sp_yn, preferred_sp_id FROM quotations WHERE qt_id = :id"),
text("SELECT status, preferred_sp_yn, preferred_sp_id, award_type FROM quotations WHERE qt_id = :id"),
{"id": qt_id},
)).first()