Merge branch 'main' into feature/negodata

Helped-By: Claude Opus 4.8뀨 <noreply@anthropic.com>
This commit is contained in:
minaChoi committed 2026-07-06 16:58:04 +09:00
commit 3176ec4262
55 files changed
+915 -771

No files matched your search

+22 -21
View File
@@ -7,10 +7,10 @@ from fastapi import Depends
from common.anchoring import (
SAMPLEABLE_SUPPLIER_TYPES,
calc_anchor_price,
calc_bracket_index,
fetch_current_rates,
get_base_rate_permille,
calc_anchoring_price,
calc_price_range_index,
fetch_current_values,
get_base_anchoring_value,
)
from common.database.db_session_manager import DB_SESSION_MNG
from common.database.model.models import quotations, sessions, chats, versions, version_nego_cards, version_wild_cards
@@ -186,7 +186,8 @@ class QuotationService:
res.candidates = [TargetCandidate(basis=b, label=self._CANDIDATE_LABELS.get(b, b), value=int(v)) for b, v in cands]
res.chosen_basis = None if is_inherited else chosen_basis
res.target_price = sess.target_price
res.target_anchoring_price = sess.target_anchoring_price
res.anchoring_price = sess.anchoring_price
res.anchoring_value = (sess.anchoring_value or 0) / 1000 # 세션 ‰ → 비율(main 프론트 '목표가×(1−값)' 표시용)
return res
async def list_quotations(self, company_id, owner, search, status, type_, start_from, start_to, pg: PageParams) -> Res_QuotationList:
@@ -415,8 +416,8 @@ class QuotationService:
rates = rates if _err == ErrorType.SUCCESS else {}
fee = self.INTERNET_AVERAGE_FEE # 인터넷가 차감 수수료율(상수)
margin = rates.get("margin") or 0.0 # 판매가 차감 목표마진율
# 앵커링가는 quotation_settings.anchoring_value 를 더 이상 쓰지 않는다(앵커링 v1.2) —
# 칸(회사×협력사유형×가격구간)별 조정 rate 로 계산한다. 아래 세션 생성부 ②.
# 앵커링가는 quotation_settings.anchoring_value(구 float 비율)를 더 이상 쓰지 않는다(앵커링 v1.2) —
# 칸(회사×협력사유형×가격구간)별 조정 anchoring_value(정수 ‰)로 계산한다. 아래 세션 생성부 ②.
# 선택 협상카드가 있으면 새 버전을 만들어 카드들을 묶고, quotation.version_id 로 연결한다.
# (quotation↔card 는 version → version_nego_cards/version_wild_cards 로 연결.)
@@ -489,32 +490,32 @@ class QuotationService:
res.result.SetResult(ErrorType.QUOTATION_TARGET_PRICE_UNAVAILABLE)
return res
# ② 앵커가 산출 — 칸(items.company_id × quotations.supplier_type × 목표가 구간) rate 조회 후
# ② 앵커가 산출 — 칸(items.company_id × quotations.supplier_type × 목표가 구간) anchoring_value 조회 후
# 정수 연산으로 박제(앵커링 v1.2, 인수인계.md §1.3). 유형 미지정/조정 이력 없음/조회 실패는
# 정적 테이블 시작값 폴백 — rate 조회 때문에 견적 생성이 실패하지 않는다(규칙 6).
# 정적 테이블 시작값 폴백 — 값 조회 때문에 견적 생성이 실패하지 않는다(규칙 6).
_err, item_companies = await DB_SESSION_MNG.execute_lambda(
quotations.DBType(),
DBWRType.DB_READ.value,
lambda s: self.quotation_crud.get_item_companies(s, item_ids),
)
item_companies = item_companies if _err == ErrorType.SUCCESS else {}
rate_map = {}
value_map = {}
if supplier_type in SAMPLEABLE_SUPPLIER_TYPES and item_companies:
rate_map = await DB_SESSION_MNG.execute_lambda(
value_map = await DB_SESSION_MNG.execute_lambda(
quotations.DBType(),
DBWRType.DB_READ.value,
lambda s: fetch_current_rates(s, list(set(item_companies.values())), supplier_type),
lambda s: fetch_current_values(s, list(set(item_companies.values())), supplier_type),
)
session_objs = []
for iid in item_ids:
tp = target_prices[iid]
bracket = calc_bracket_index(tp)
price_range = calc_price_range_index(tp)
company = item_companies.get(iid)
rate = rate_map.get((company, bracket)) if company is not None else None
if rate is None:
rate = get_base_rate_permille(bracket)
ap = calc_anchor_price(tp, rate) # 목표가×(1000−rate)//1000 — float 곱셈 금지(1원 내림 정확성)
value = value_map.get((company, price_range)) if company is not None else None
if value is None:
value = get_base_anchoring_value(price_range)
ap = calc_anchoring_price(tp, value) # 목표가×(1000−value)//1000 — float 곱셈 금지(1원 내림 정확성)
for sid in supplier_ids:
session_objs.append(
sessions(
@@ -526,8 +527,8 @@ class QuotationService:
qt_round=quotation.round,
qt_type=quotation.type,
target_price=tp,
target_anchoring_price=ap, # 박제 — 이후 수정 금지(협상 판정·앵커링 학습 기준값)
anchor_rate_permille=rate,
anchoring_price=ap, # 박제 — 이후 수정 금지(협상 판정·앵커링 학습 기준값)
anchoring_value=value,
status=SessionStatus.CREATED.value,
end_time=quotation.end_time,
)
@@ -645,7 +646,7 @@ class QuotationService:
mid_action = original.mid_action or PriceGateAction.AWARD.value
over_action = original.over_action or PriceGateAction.AWARD.value
target = next((r.target_price for r in rows if r.target_price is not None), None)
anchor = next((r.target_anchoring_price for r in rows if r.target_anchoring_price is not None), None)
anchor = next((r.anchoring_price for r in rows if r.anchoring_price is not None), None)
# 1) 단독 최저가가 낙찰 기준 통과 → 낙찰. 미달 → 개찰(가격).
if winner is not None:
@@ -797,7 +798,7 @@ class QuotationService:
qt_round=r.qt_round,
qt_type=r.qt_type,
target_price=r.target_price,
target_anchoring_price=r.target_anchoring_price,
anchoring_price=r.anchoring_price,
status=r.status,
bid_price=r.bid_price,
bid_at=r.bid_at,