[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

+20 -23
View File
@@ -8,7 +8,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from common.database.db_session_manager import DB_SESSION_MNG
from common.database.model.models import (
quotations, sessions, chats, nego_cards, wild_cards, items, suppliers, quotation_settings,
version_nego_cards, version_wild_cards, users,
version_nego_cards, version_wild_cards, users, supplier_items,
)
from common.enums import CloseReason, ErrorType, QuotationStatus, SessionStatus
from common.logger import LOG
@@ -44,7 +44,7 @@ class IQuotationCRUD(ABC):
pass
@abstractmethod
async def get_last_supplier_type(self, cdb: AsyncSession, supplier_id, company_id=None) -> Tuple[ErrorType, Optional[tuple]]:
async def get_supply_types(self, cdb: AsyncSession, item_ids, supplier_ids) -> Tuple[ErrorType, dict]:
pass
@abstractmethod
@@ -400,33 +400,30 @@ class QuotationCRUD(IQuotationCRUD):
LOG.e_no_callstack(ex)
return ErrorType.DB_RUN_FAILED, {}
async def get_last_supplier_type(self, cdb: AsyncSession, supplier_id, company_id=None) -> Tuple[ErrorType, Optional[tuple]]:
"""협력사의 직전 견적 supplier_type. (supplier_type, qt_number) | None.
sessions(supplier_id) ⨝ quotations 에서 supplier_type 가 있는 최신 견적 1건."""
async def get_supply_types(self, cdb: AsyncSession, item_ids, supplier_ids) -> Tuple[ErrorType, dict]:
"""(item_id, supplier_id) -> supplier_items.supply_type 매핑.
매핑이 없거나 supply_type 이 0/NULL 이면 호출측이 정적 앵커링 값으로 폴백한다.
"""
try:
conds = [
sessions.supplier_id == supplier_id,
quotations.supplier_type.isnot(None),
quotations.deleted == False, # noqa: E712
]
if company_id is not None:
conds.append(quotations.user_id.in_(select(users.user_id).where(users.company_id == company_id)))
query = (
select(quotations.supplier_type, quotations.number)
.join(sessions, sessions.quotation_id == quotations.qt_id)
.where(*conds)
.order_by(quotations.created_at.desc())
.limit(1)
if not item_ids or not supplier_ids:
return ErrorType.SUCCESS, {}
query = select(
supplier_items.item_id,
supplier_items.supplier_id,
supplier_items.supply_type,
).where(
supplier_items.item_id.in_(item_ids),
supplier_items.supplier_id.in_(supplier_ids),
supplier_items.deleted == False, # noqa: E712
)
err_type, rows = await DB_SESSION_MNG.execute(cdb, query)
if err_type != ErrorType.SUCCESS:
return err_type, None
if not rows:
return ErrorType.SUCCESS, None
return ErrorType.SUCCESS, (rows[0][0], rows[0][1])
return err_type, {}
return ErrorType.SUCCESS, {(r[0], r[1]): r[2] for r in rows}
except Exception as ex:
LOG.e_no_callstack(ex)
return ErrorType.DB_RUN_FAILED, None
return ErrorType.DB_RUN_FAILED, {}
async def get_setting_rates(self, cdb: AsyncSession, qt_setting_id) -> Tuple[ErrorType, dict]:
"""견적 세팅의 목표 마진율: {margin}. 목표가 산정 입력(인터넷 수수료는 상수).