feat(purchase): 物料搜索分页+价格半联动+图片必填校验
This commit is contained in:
@ -138,6 +138,49 @@ class PurchaseService:
|
||||
purchase = db.session.get(PurchaseRequest, purchase_id)
|
||||
return purchase.to_dict() if purchase else None
|
||||
|
||||
@staticmethod
|
||||
def search_base_material(keyword: str, page: int = 1, limit: int = 20):
|
||||
"""
|
||||
物料基础信息搜索,支持 name/spec_model/company_name 模糊匹配,返回分页结果
|
||||
用于采购申请弹窗的物料远程搜索
|
||||
"""
|
||||
from sqlalchemy import and_, or_
|
||||
|
||||
query = MaterialBase.query.filter(MaterialBase.is_enabled == True)
|
||||
|
||||
if keyword:
|
||||
k = keyword.strip()
|
||||
k_str = f'%{k}%'
|
||||
query = query.filter(or_(
|
||||
MaterialBase.name.ilike(k_str),
|
||||
MaterialBase.spec_model.ilike(k_str),
|
||||
MaterialBase.company_name.ilike(k_str)
|
||||
))
|
||||
|
||||
query = query.order_by(MaterialBase.id.desc())
|
||||
pagination = query.paginate(page=page, per_page=limit, error_out=False)
|
||||
|
||||
items = []
|
||||
for item in pagination.items:
|
||||
items.append({
|
||||
'id': item.id,
|
||||
'company_name': item.company_name,
|
||||
'name': item.name,
|
||||
'spec_model': item.spec_model,
|
||||
'category': item.category,
|
||||
'unit': item.unit,
|
||||
'type': item.material_type,
|
||||
'pinyin': getattr(item, 'pinyin', ''),
|
||||
'status': '启用'
|
||||
})
|
||||
|
||||
return {
|
||||
'items': items,
|
||||
'total': pagination.total,
|
||||
'page': page,
|
||||
'has_next': pagination.has_next
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def _notify_new_request(purchase):
|
||||
"""发送新申请邮件给审批人"""
|
||||
|
||||
Reference in New Issue
Block a user