[feat] negosium·negodata: 협상 진행 중 거부 + 결렬 건 최종 제출가로 직접 낙찰
협력사가 단종·품절을 대화 도중 알아채도 봇의 결렬 선언을 기다려야 했고, 거부로 끝난 협상은 가격을 남겨도 낙찰 후보에서 빠져 계약으로 이어지지 않았다. negosium - 채팅 액션바에 협상 거부 진입점 — 대화가 끝나지 않고 입력을 기다리는 동안만 노출, 주 CTA 와 붙지 않게 넓은 화면은 우측 끝 고정·좁은 화면은 wrap - 거부 팝업은 목록 거부 팝업과 같은 어휘·규격, 대화 중이라 공급 희망 가격·의견을 더 받는다 - /reject 에 reject_price·opinion 추가 — sessions.reject_price 저장, 의견은 custom 병합 - 화면 문구 '거절' → '거부' 통일 (버튼·배지·탭·토스트·안내 팝업) negodata - 개찰 견적 직접 낙찰 후보 = 가격을 써낸 세션 — 투찰한 협상완료 + 공급 희망가를 남긴 협상거부 - 계약가 파생 _award_price/awardPrice — coalesce(투찰가, 거부 시 공급 희망가) - 통계 낙찰 세션 조인도 같은 기준 — 안 고치면 거부가로 낙찰한 건이 절감 집계에서 빠진다 - 세션 상태 탭 라벨 '거절사유/거절가격/거절배송방식' → '거부…' 자동 마감 판정(close_and_decide)은 그대로 — 자동 낙찰은 투찰가만 본다.
This commit is contained in:
1 parent
f1e924931f
commit
ac6366a898
21 files changed
+403
-63
No files matched your search
@@ -703,13 +703,14 @@ class QuotationCRUD(IQuotationCRUD):
|
||||
return ErrorType.DB_RUN_FAILED, 0
|
||||
|
||||
async def list_sessions_status(self, cdb: AsyncSession, qt_id) -> Tuple[ErrorType, list]:
|
||||
"""[마감 판정] 견적의 모든 세션 → (status, supplier_id, bid_price, name, target_price, anchoring_price). 삭제 제외.
|
||||
"""[마감 판정] 견적의 모든 세션 → (status, supplier_id, bid_price, name, target_price, anchoring_price, reject_price). 삭제 제외.
|
||||
공급사가 지워졌어도 세션 집계엔 포함되도록 outerjoin(이때 name 은 None).
|
||||
target/anchoring 은 마감 가격게이트 입력(견적당 상품 1개라 세션 공통값)."""
|
||||
target/anchoring 은 마감 가격게이트 입력(견적당 상품 1개라 세션 공통값).
|
||||
reject_price 는 거부 협력사의 공급 희망 가격 — 자동 마감 판정엔 안 쓰고 수동 직접 낙찰 후보에서만 본다."""
|
||||
try:
|
||||
query = (
|
||||
select(sessions.status, sessions.supplier_id, sessions.bid_price, suppliers.name,
|
||||
sessions.target_price, sessions.anchoring_price)
|
||||
sessions.target_price, sessions.anchoring_price, sessions.reject_price)
|
||||
.outerjoin(suppliers, suppliers.supplier_id == sessions.supplier_id)
|
||||
.where(sessions.quotation_id == qt_id, sessions.deleted == False) # noqa: E712
|
||||
)
|
||||
|
||||
@@ -76,14 +76,17 @@ class StatisticsCRUD(IStatisticsCRUD):
|
||||
async def winning_sessions(self, cdb: AsyncSession, company_id, owner, since) -> Tuple[ErrorType, list]:
|
||||
# 낙찰 마감 견적의 '낙찰 세션'(supplier_id=preferred_sp_id) 행 — 절감/추이/유형/카테고리/앵커도달률의 단일 원천.
|
||||
# 파생: 저장 안 하고 조회 때 조인. category 는 items LEFT JOIN(자유텍스트·NULL 허용).
|
||||
# 계약가는 coalesce(투찰가, 거부 시 공급 희망가) — 결렬 건을 담당자가 직접 낙찰하면 bid_price 가 없어
|
||||
# 절감 집계에서 통째로 빠지기 때문. 이름은 bid_price 로 유지해 statistics_service 는 그대로 쓴다.
|
||||
try:
|
||||
award_price = func.coalesce(sessions.bid_price, sessions.reject_price).label("bid_price")
|
||||
stmt = (
|
||||
select(
|
||||
quotations.updated_at,
|
||||
quotations.type,
|
||||
items.category,
|
||||
sessions.target_price,
|
||||
sessions.bid_price,
|
||||
award_price,
|
||||
sessions.anchoring_price,
|
||||
)
|
||||
.select_from(quotations)
|
||||
@@ -92,7 +95,7 @@ class StatisticsCRUD(IStatisticsCRUD):
|
||||
and_(
|
||||
sessions.quotation_id == quotations.qt_id,
|
||||
sessions.supplier_id == quotations.preferred_sp_id,
|
||||
sessions.bid_price.isnot(None),
|
||||
or_(sessions.bid_price.isnot(None), sessions.reject_price.isnot(None)),
|
||||
sessions.deleted == False, # noqa: E712
|
||||
),
|
||||
)
|
||||
|
||||
@@ -10,6 +10,17 @@ from router.v1.quotation.protocol import Res_Quotation
|
||||
from services.notification import create_notification
|
||||
|
||||
|
||||
def _award_price(row) -> Optional[int]:
|
||||
"""직접 낙찰 시 계약 기준가 — 타결했으면 투찰가, 협상이 거부로 끝났으면 그때 써낸 공급 희망 가격.
|
||||
둘 다 없으면(가격을 한 번도 안 낸 협력사) None → 낙찰 후보가 아니다.
|
||||
자동 마감 판정(close_and_decide)은 이 함수를 쓰지 않는다 — 자동 낙찰은 투찰가만 본다."""
|
||||
if row.status == SessionStatus.DONE.value and row.bid_price is not None:
|
||||
return int(row.bid_price)
|
||||
if row.status == SessionStatus.REJECTED.value and row.reject_price is not None:
|
||||
return int(row.reject_price)
|
||||
return None
|
||||
|
||||
|
||||
class ClosingMixin:
|
||||
@staticmethod
|
||||
def _pick_winner(done_rows) -> tuple[Optional[dict], Optional[dict]]:
|
||||
@@ -159,7 +170,9 @@ class ClosingMixin:
|
||||
|
||||
async def award_quotation(self, qt_id: str, company_id, user_id, role, winner_supplier_id) -> Res_Quotation:
|
||||
"""[프론트] 개찰(낙찰자 미정 마감) 견적을 담당자가 직접 낙찰 처리한다.
|
||||
투찰한 협상완료(DONE) 세션 중 고른 협력사를 낙찰자로 박고 close_reason 을 AWARDED 로 바꾼다(직접 낙찰).
|
||||
가격을 써낸 세션 중 고른 협력사를 낙찰자로 박고 close_reason 을 AWARDED 로 바꾼다(직접 낙찰).
|
||||
후보는 투찰한 협상완료(DONE) + 공급 희망 가격을 남긴 협상거부(REJECTED) — 협상이 결렬돼도
|
||||
마지막에 제출한 가격으로 계약을 진행하는 운영 방침을 시스템에서 그대로 처리하기 위함이다.
|
||||
자동 낙찰(close_and_decide)과 결과 컬럼은 같되, 알림에 manual 플래그로 '직접 낙찰'임을 남긴다.
|
||||
권한: 본인이 생성한 견적만. 단 최고관리자(OWNER)는 회사 내 남의 견적도 낙찰할 수 있다."""
|
||||
res = Res_Quotation()
|
||||
@@ -187,23 +200,20 @@ class ClosingMixin:
|
||||
res.msg = "개찰(낙찰자 미정) 상태의 견적만 직접 낙찰할 수 있습니다."
|
||||
return res
|
||||
|
||||
# 낙찰 후보 = 투찰한 협상완료(DONE) 세션. close_and_decide 와 같은 조회(list_sessions_status,
|
||||
# 공급사 삭제돼도 포함되는 outerjoin)를 써서 자동낙찰과 후보 집합을 일치시킨다.
|
||||
# 낙찰 후보 = 가격을 써낸 세션. close_and_decide 와 같은 조회(list_sessions_status,
|
||||
# 공급사 삭제돼도 포함되는 outerjoin)를 쓴다.
|
||||
err_type, rows = await DB_SESSION_MNG.execute_lambda(
|
||||
sessions.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: self.quotation_crud.list_sessions_status(s, qt_uuid),
|
||||
)
|
||||
rows = rows if err_type == ErrorType.SUCCESS else []
|
||||
winner = next(
|
||||
(r for r in rows
|
||||
if r.status == SessionStatus.DONE.value and r.bid_price is not None and r.supplier_id == sp_uuid),
|
||||
None,
|
||||
)
|
||||
winner = next((r for r in rows if r.supplier_id == sp_uuid and _award_price(r) is not None), None)
|
||||
if winner is None:
|
||||
res.result.SetResult(ErrorType.INVALID_REQUEST_DATA)
|
||||
res.msg = "선택한 협력사는 이 견적의 낙찰 후보(투찰한 협상완료 협력사)가 아닙니다."
|
||||
res.msg = "선택한 협력사는 이 견적의 낙찰 후보(가격을 제출한 협력사)가 아닙니다."
|
||||
return res
|
||||
winner_price = _award_price(winner)
|
||||
|
||||
# [동시 직접낙찰 가드] 개찰→낙찰 원자 선점. 실제로 전이한 호출자만 통과(재클릭·경합 방어).
|
||||
claim_err, claimed = await DB_SESSION_MNG.execute_lambda_claim(
|
||||
@@ -219,7 +229,7 @@ class ClosingMixin:
|
||||
await create_notification(
|
||||
original.user_id, NotificationType.SUCCESS,
|
||||
{"qt_name": original.name, "qt_number": original.number,
|
||||
"winner_name": winner.name, "winner_price": winner.bid_price, "manual": True},
|
||||
"winner_name": winner.name, "winner_price": winner_price, "manual": True},
|
||||
ref_qt_id=qt_uuid,
|
||||
)
|
||||
return await self.get_quotation(qt_id, company_id)
|
||||
Reference in new issue
Block a user