对于采购件的内容进行修改,使其填写更加便利加上库位自动加载上一次的逻辑

This commit is contained in:
dxc
2026-02-11 08:38:12 +08:00
parent d594ed7ef1
commit ec16ef8d20
4 changed files with 124 additions and 36 deletions

View File

@ -51,7 +51,8 @@ class BuyInboundService:
query = query.filter(
or_(
MaterialBase.name.ilike(f'%{keyword}%'),
MaterialBase.spec_model.ilike(f'%{keyword}%')
MaterialBase.spec_model.ilike(f'%{keyword}%'),
MaterialBase.pinyin.ilike(f'%{keyword}%')
)
)
query = query.order_by(MaterialBase.id.desc()).limit(20)
@ -336,22 +337,20 @@ class BuyInboundService:
# ============================================================
@staticmethod
def get_history_suppliers(base_id):
"""返回该物料在 stock_buy 表中关联的供应商列表"""
"""返回该物料关联的供应商列表(去重)"""
try:
# 去重查询
query = db.session.query(StockBuy.supplier_name).filter(
StockBuy.base_id == base_id,
StockBuy.supplier_name.isnot(None),
StockBuy.supplier_name != ''
).distinct().order_by(StockBuy.supplier_name)
suppliers = [row[0] for row in query.all()]
return suppliers
except Exception:
return []
# ============================================================
# 7. 采购人/邮箱历史查询 (全局, stock_buy 获取)
# 7. 采购人建议 (全局,基于 stock_buy )
# ============================================================
@staticmethod
def get_history_purchasers(keyword):
@ -371,7 +370,7 @@ class BuyInboundService:
StockBuy.buyer_email.ilike(kw)
))
# 按名字去重,取最新的记录(这里简单做 distinct,具体业务如果一个人有多个邮箱可能需要更复杂逻辑,这里简化为 distinct 组合
# 按名字去重,取最新的记录(这里简单做 distinct
results = query.distinct().limit(20).all()
users = []
@ -401,5 +400,24 @@ class BuyInboundService:
links = [row[0] for row in query.all()]
return links
except Exception:
return []
# ============================================================
# 9. [新增] 库位建议 (基于 base_id)
# ============================================================
@staticmethod
def get_history_locations(base_id):
"""查询该物料的历史存放库位,方便复用"""
try:
query = db.session.query(StockBuy.warehouse_location).filter(
StockBuy.base_id == base_id,
StockBuy.warehouse_location.isnot(None),
StockBuy.warehouse_location != ''
).distinct().limit(10)
# 简单去重列表
locs = [row[0] for row in query.all()]
return locs
except Exception:
return []