[refactor] 공급유형 기준을 상품-협력사 매핑으로 전환

This commit is contained in:
minaChoi committed 2026-07-07 17:05:07 +09:00
1 parent 9ac8fe6363
commit d21e7c10b0
35 files changed
+157 -333

No files matched your search

@@ -1,8 +1,8 @@
"""앵커링 v1.2 — 견적 생성 시 칸(회사×협력사유형×가격구간) anchoring_value 로 앵커가를 박제하는지 검증.
"""앵커링 v1.2 — 견적 생성 시 칸(회사×상품-협력사 공급유형×가격구간) anchoring_value 로 앵커가를 박제하는지 검증.
이식 명세: schedules/anchoring/docs/인수인계.md §1.
- 앵커가 = 목표가 × (1000 − anchoring_value) // 1000 (정수 연산), anchoring_value 동시 박제
- 조정 이력 없음 / 유형 미지정 / anchoring 스키마 미적용 → 정적 테이블 시작값(10‰) 폴백,
- 조정 이력 없음 / 매핑 유형 미지정 / anchoring 스키마 미적용 → 정적 테이블 시작값(10‰) 폴백,
견적 생성은 실패하지 않는다(규칙 6)
- 재생성 라운드는 목표가만 상속하고 앵커는 생성 시점 anchoring_value 로 재계산(규칙 1 — 상속 폐지)
"""
@@ -22,12 +22,12 @@ BASE_VALUE = 10 # 정적 테이블 시작값(‰) — anchoring_base.json 전
async def test_create_without_anchoring_schema_falls_back_to_base_value(db_engine, company_id):
"""검증: anchoring 스키마가 아예 없는 DB 에서 supplier_type=1(유통) 견적 생성.
"""검증: anchoring 스키마가 아예 없는 DB 에서 supply_type=1(유통) 매핑으로 견적 생성.
기대결과: 조회 실패에도 생성 성공 + 앵커가=목표가×990‰(시작값), anchoring_value=10 박제."""
await _drop_anchoring(db_engine)
item = await _seed_item(db_engine, company_id, internet_lowest=100_000)
res = await _create(item_ids=[item], supplier_type=1)
res = await _create(db_engine, item_ids=[item], supply_type=1)
assert res.result.success is True
tp = int(100_000 * (1 - QuotationService.INTERNET_AVERAGE_FEE)) # 92,200
@@ -45,7 +45,7 @@ async def test_create_uses_latest_adjusted_value_per_cell(db_engine, company_id)
tp_miss = int(5_000 * (1 - QuotationService.INTERNET_AVERAGE_FEE))
await _seed_adjustment(db_engine, company_id, supplier_type=1, price_range=calc_price_range_index(tp_hit), value_after=50)
res = await _create(item_ids=[item_hit, item_miss], supplier_type=1)
res = await _create(db_engine, item_ids=[item_hit, item_miss], supply_type=1)
assert res.result.success is True
rows = await _session_anchor_rows(db_engine, res.qt_id)
@@ -53,15 +53,15 @@ async def test_create_uses_latest_adjusted_value_per_cell(db_engine, company_id)
assert rows[item_miss] == (tp_miss, tp_miss * 990 // 1000, BASE_VALUE)
async def test_supplier_type_unset_uses_base_value(db_engine, company_id):
"""검증: supplier_type 미지정(None) 견적 생성 — 칸(회사×유형×구간) 구성 불가.
async def test_supply_type_unset_uses_base_value(db_engine, company_id):
"""검증: supply_type 미지정(None) 매핑으로 견적 생성 — 칸(회사×유형×구간) 구성 불가.
기대결과: 같은 회사·구간에 조정 이력이 있어도 쓰지 않고 시작값 10‰ 박제."""
await _reset_anchoring(db_engine)
item = await _seed_item(db_engine, company_id, internet_lowest=100_000)
tp = int(100_000 * (1 - QuotationService.INTERNET_AVERAGE_FEE))
await _seed_adjustment(db_engine, company_id, supplier_type=1, price_range=calc_price_range_index(tp), value_after=50)
res = await _create(item_ids=[item], supplier_type=None)
res = await _create(db_engine, item_ids=[item], supply_type=None)
assert res.result.success is True
rows = await _session_anchor_rows(db_engine, res.qt_id)
@@ -75,7 +75,7 @@ async def test_regenerate_inherits_target_but_recomputes_anchor(db_engine, compa
item = await _seed_item(db_engine, company_id, internet_lowest=100_000)
supplier = uuid.uuid4()
res1 = await _create(item_ids=[item], supplier_type=1, supplier_ids=[supplier])
res1 = await _create(db_engine, item_ids=[item], supply_type=1, supplier_ids=[supplier])
assert res1.result.success is True
tp = int(100_000 * (1 - QuotationService.INTERNET_AVERAGE_FEE))
rows1 = await _session_anchor_rows(db_engine, res1.qt_id)
@@ -108,20 +108,40 @@ def _service():
return QuotationService(QuotationCRUD())
async def _create(*, item_ids, supplier_type, supplier_ids=None):
"""supplier_type 을 지정해 견적 1건 생성(공급사 기본 1곳)."""
async def _create(engine, *, item_ids, supply_type, supplier_ids=None):
"""supplier_items.supply_type 매핑을 시드한 뒤 견적 1건 생성(공급사 기본 1곳)."""
supplier_ids = supplier_ids or [uuid.uuid4()]
await _seed_supplier_items(engine, item_ids, supplier_ids, supply_type=supply_type)
req = Req_CreateQuotation(
qt_setting_id=uuid.uuid4(), # FK 미설정 — 세팅 없으면 율 0(앵커는 세팅과 무관해짐)
name="앵커링검증",
type=QuotationType.NEW_QUOTE.value,
end_time=FUTURE,
supplier_type=supplier_type,
item_ids=list(item_ids),
supplier_ids=supplier_ids or [uuid.uuid4()],
supplier_ids=supplier_ids,
)
return await _service().create_quotation(str(uuid.uuid4()), req)
async def _seed_supplier_items(engine, item_ids, supplier_ids, *, supply_type):
async with engine.begin() as conn:
for item_id in item_ids:
for supplier_id in supplier_ids:
await conn.execute(
text(
"INSERT INTO supplier_items "
"(supplier_item_id, supplier_id, item_id, supply_type) "
"VALUES (:id, :supplier_id, :item_id, :supply_type)"
),
{
"id": uuid.uuid4(),
"supplier_id": supplier_id,
"item_id": item_id,
"supply_type": supply_type if supply_type is not None else 0,
},
)
async def _seed_item(engine, company_id, *, internet_lowest):
"""상품 1건 시드(인터넷최저가만). NOT NULL 컬럼은 명시(ORM default 는 raw INSERT 에 안 먹음)."""
item_id = uuid.uuid4()