[refactor] 공급유형 기준을 상품-협력사 매핑으로 전환
This commit is contained in:
1 parent
9ac8fe6363
commit
d21e7c10b0
35 files changed
+157
-333
No files matched your search
@@ -25,21 +25,23 @@ _current_values = table(
|
||||
)
|
||||
|
||||
|
||||
async def fetch_current_values(db: AsyncSession, company_ids: list, supplier_type: int) -> dict:
|
||||
"""칸별 현재 앵커링 값 일괄 조회. {(company_id, price_range_index): rate‰} 반환.
|
||||
async def fetch_current_values(db: AsyncSession, company_ids: list, supplier_types: list[int]) -> dict:
|
||||
"""칸별 현재 앵커링 값 일괄 조회. {(company_id, supplier_type, price_range_index): rate‰} 반환.
|
||||
|
||||
supplier_type 은 견적 단위로 하나뿐이라 키에 넣지 않는다.
|
||||
supplier_type 은 세션의 (item_id, supplier_id) 매핑에서 온 supply_type 이다.
|
||||
조정 이력이 없는 칸은 결과에 없다(호출측 정적 폴백). 조회 실패 시 빈 dict."""
|
||||
if not company_ids or supplier_type not in SAMPLEABLE_SUPPLIER_TYPES:
|
||||
valid_types = sorted({int(t) for t in supplier_types if t in SAMPLEABLE_SUPPLIER_TYPES})
|
||||
if not company_ids or not valid_types:
|
||||
return {}
|
||||
try:
|
||||
stmt = select(
|
||||
_current_values.c.company_id,
|
||||
_current_values.c.supplier_type,
|
||||
_current_values.c.price_range_index,
|
||||
_current_values.c.anchoring_value,
|
||||
).where(
|
||||
_current_values.c.company_id.in_(company_ids),
|
||||
_current_values.c.supplier_type == supplier_type,
|
||||
_current_values.c.supplier_type.in_(valid_types),
|
||||
)
|
||||
rows = (await db.execute(stmt)).all()
|
||||
except Exception as ex:
|
||||
@@ -47,9 +49,9 @@ async def fetch_current_values(db: AsyncSession, company_ids: list, supplier_typ
|
||||
return {}
|
||||
|
||||
out = {}
|
||||
for company_id, price_range_index, rate in rows:
|
||||
for company_id, supplier_type, price_range_index, rate in rows:
|
||||
if not ANCHORING_VALUE_MIN <= rate <= ANCHORING_VALUE_MAX: # 범위 밖 값은 오염 방어 — 버리고 정적 폴백
|
||||
LOG.w(f"[앵커링] rate 범위 밖 — 무시(정적 폴백): company={company_id} bracket={price_range_index} rate={rate}")
|
||||
LOG.w(f"[앵커링] rate 범위 밖 — 무시(정적 폴백): company={company_id} type={supplier_type} bracket={price_range_index} rate={rate}")
|
||||
continue
|
||||
out[(company_id, price_range_index)] = rate
|
||||
out[(company_id, supplier_type, price_range_index)] = rate
|
||||
return out
|
||||
@@ -135,7 +135,7 @@ class supplier_items(MainTableMixin, MAIN_BASE):
|
||||
supplier_item_id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
supplier_id = Column(UUID(as_uuid=True), nullable=False, index=True) # suppliers.supplier_id
|
||||
item_id = Column(UUID(as_uuid=True), nullable=False, index=True) # items.item_id
|
||||
# SupplierType: 이 협력사가 이 상품을 공급하는 방식(0=없음/1=유통/2=제조/3=총판). quotations.supplier_type 와 값은 같으나 의미 단위가 (협력사,상품)이라 컬럼명은 supply_type.
|
||||
# SupplierType: 이 협력사가 이 상품을 공급하는 방식(0=없음/1=유통/2=제조/3=총판).
|
||||
supply_type = Column(SmallInteger, nullable=False, server_default=text("0"), default=0)
|
||||
|
||||
|
||||
@@ -229,8 +229,6 @@ class quotations(MainTableMixin, MAIN_BASE):
|
||||
manager_contact_number = Column(String(20), nullable=True)
|
||||
memo = Column(String(100), nullable=True)
|
||||
md_price = Column(BigInteger, nullable=True)
|
||||
supplier_type = Column(SmallInteger, nullable=True)
|
||||
|
||||
iteration = Column(Integer, nullable=False, default=0)
|
||||
preferred_sp_yn = Column(Boolean, nullable=True)
|
||||
preferred_sp_id = Column(UUID(as_uuid=True), nullable=True)
|
||||
|
||||
@@ -237,8 +237,8 @@ class CardType(CodeEnum):
|
||||
|
||||
|
||||
class SupplierType(CodeEnum):
|
||||
"""quotations.supplier_type 코드값. 없음(0,미지정)/유통(1)/제조(2)/총판(3).
|
||||
없음은 프론트 폼에 '없음'으로 노출. KTC 앵커링 코드(기타=0)와 매핑 시 0↔없음 대응."""
|
||||
"""partner.supplier_items.supply_type 코드값. 없음(0,미지정)/유통(1)/제조(2)/총판(3).
|
||||
없음은 상품-협력사 매핑에서 유형 미지정 상태를 뜻한다."""
|
||||
|
||||
NONE = 0 # 없음(미지정)
|
||||
DISTRIBUTION = 1 # 유통
|
||||
|
||||
Reference in new issue
Block a user