修改半成品和成品新增时候搜索下拉框显示问题,新增负责人和生产人历史记录功能
This commit is contained in:
@ -7,7 +7,6 @@ from sqlalchemy import or_, func, text, and_
|
||||
import traceback
|
||||
import json
|
||||
|
||||
|
||||
class SemiInboundService:
|
||||
|
||||
# ============================================================
|
||||
@ -36,10 +35,10 @@ class SemiInboundService:
|
||||
raise ValueError(f"该物料已存在批号【{batch_number}】,请勿重复建单,建议在原批次上追加库存。")
|
||||
|
||||
# ============================================================
|
||||
# 1. 基础物料搜索
|
||||
# 1. 基础物料搜索 (已修改支持分页)
|
||||
# ============================================================
|
||||
@staticmethod
|
||||
def search_base_material(keyword):
|
||||
def search_base_material(keyword, page=1, limit=50):
|
||||
try:
|
||||
query = MaterialBase.query.filter(MaterialBase.is_enabled == True)
|
||||
if keyword:
|
||||
@ -51,9 +50,10 @@ class SemiInboundService:
|
||||
MaterialBase.company_name.ilike(kw) # [新增] 支持搜公司
|
||||
)
|
||||
)
|
||||
query = query.order_by(MaterialBase.id.desc()).limit(20)
|
||||
query = query.order_by(MaterialBase.id.desc())
|
||||
pagination = query.paginate(page=page, per_page=limit, error_out=False)
|
||||
results = []
|
||||
for item in query.all():
|
||||
for item in pagination.items:
|
||||
results.append({
|
||||
'id': item.id,
|
||||
'company_name': item.company_name, # [新增]
|
||||
@ -64,10 +64,15 @@ class SemiInboundService:
|
||||
'type': item.material_type,
|
||||
'status': '启用'
|
||||
})
|
||||
return results
|
||||
return {
|
||||
"items": results,
|
||||
"total": pagination.total,
|
||||
"page": page,
|
||||
"has_next": pagination.has_next
|
||||
}
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
return []
|
||||
return {"items": [], "total": 0, "page": 1, "has_next": False}
|
||||
|
||||
# ============================================================
|
||||
# 1.5 BOM 搜索逻辑
|
||||
@ -479,4 +484,21 @@ class SemiInboundService:
|
||||
except Exception:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return {"categories": [], "types": [], "companies": []}
|
||||
return {"categories": [], "types": [], "companies": []}
|
||||
|
||||
# ============================================================
|
||||
# 8. 获取历史生产负责人 (新增)
|
||||
# ============================================================
|
||||
@staticmethod
|
||||
def get_history_managers(base_id):
|
||||
from app.models.inbound.semi import StockSemi
|
||||
try:
|
||||
records = db.session.query(StockSemi.production_manager).filter(
|
||||
StockSemi.base_id == base_id,
|
||||
StockSemi.production_manager.isnot(None),
|
||||
StockSemi.production_manager != ''
|
||||
).distinct().all()
|
||||
return [r[0] for r in records if r[0]]
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
return []
|
||||
Reference in New Issue
Block a user