修改半成品和成品新增时候搜索下拉框显示问题,新增负责人和生产人历史记录功能
This commit is contained in:
@ -4,132 +4,68 @@ from app.services.inbound.product_service import ProductInboundService
|
|||||||
from app.utils.decorators import permission_required
|
from app.utils.decorators import permission_required
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
# === 这一行非常关键,绝对不能丢!===
|
||||||
inbound_product_bp = Blueprint('stock_product', __name__)
|
inbound_product_bp = Blueprint('stock_product', __name__)
|
||||||
|
|
||||||
|
|
||||||
# ==============================================================================
|
|
||||||
# 辅助函数:获取当前用户的完整权限列表(基于角色查询)
|
|
||||||
# ==============================================================================
|
|
||||||
def get_current_user_permissions():
|
def get_current_user_permissions():
|
||||||
"""
|
|
||||||
返回当前用户拥有的所有权限码列表(包括菜单和元素)
|
|
||||||
此函数根据角色查询数据库得到权限。
|
|
||||||
"""
|
|
||||||
from flask_jwt_extended import get_jwt
|
from flask_jwt_extended import get_jwt
|
||||||
from app.services.auth_service import AuthService
|
from app.services.auth_service import AuthService
|
||||||
claims = get_jwt()
|
claims = get_jwt()
|
||||||
user_role = claims.get('role')
|
user_role = claims.get('role')
|
||||||
if not user_role:
|
if not user_role: return []
|
||||||
return []
|
if user_role.upper() == 'SUPER_ADMIN': return ['inbound_product:*']
|
||||||
# 超级管理员返回所有字段权限 (忽略大小写)
|
|
||||||
if user_role.upper() == 'SUPER_ADMIN':
|
|
||||||
# 返回所有以 inbound_product: 开头的权限码(这里我们返回一个特殊标记,表示全部)
|
|
||||||
# 为了简单,我们返回 ['inbound_product:*'],在过滤函数中特殊处理
|
|
||||||
return ['inbound_product:*']
|
|
||||||
perm_dict = AuthService.get_user_permissions(user_role)
|
perm_dict = AuthService.get_user_permissions(user_role)
|
||||||
# 合并菜单和元素权限
|
return perm_dict.get('menus', []) + perm_dict.get('elements', [])
|
||||||
perms = perm_dict.get('menus', []) + perm_dict.get('elements', [])
|
|
||||||
return perms
|
|
||||||
|
|
||||||
|
|
||||||
def filter_item_by_permissions(item_dict, user_permissions):
|
def filter_item_by_permissions(item_dict, user_permissions):
|
||||||
"""
|
|
||||||
根据用户权限过滤 item 字典,无权限的字段值置为 None
|
|
||||||
"""
|
|
||||||
# 字段名到权限码的映射(与前端 permissionMap 保持一致)
|
|
||||||
field_to_perm = {
|
field_to_perm = {
|
||||||
'id': 'inbound_product:id',
|
'id': 'inbound_product:id', 'base_id': 'inbound_product:base_id', 'company_name': 'inbound_product:company_name',
|
||||||
'base_id': 'inbound_product:base_id',
|
'material_name': 'inbound_product:material_name', 'category': 'inbound_product:category',
|
||||||
'company_name': 'inbound_product:company_name',
|
'material_type': 'inbound_product:material_type', 'spec_model': 'inbound_product:spec_model',
|
||||||
'material_name': 'inbound_product:material_name',
|
'unit': 'inbound_product:unit', 'sku': 'inbound_product:sku', 'inbound_date': 'inbound_product:inbound_date',
|
||||||
'category': 'inbound_product:category',
|
'barcode': 'inbound_product:barcode', 'serial_number': 'inbound_product:serial_number',
|
||||||
'material_type': 'inbound_product:material_type',
|
'status': 'inbound_product:status', 'quality_status': 'inbound_product:quality_status',
|
||||||
'spec_model': 'inbound_product:spec_model',
|
'in_quantity': 'inbound_product:in_quantity', 'stock_quantity': 'inbound_product:stock_quantity',
|
||||||
'unit': 'inbound_product:unit',
|
'available_quantity': 'inbound_product:available_quantity', 'warehouse_location': 'inbound_product:warehouse_location',
|
||||||
'sku': 'inbound_product:sku',
|
'bom_code': 'inbound_product:bom_code', 'bom_version': 'inbound_product:bom_version',
|
||||||
'inbound_date': 'inbound_product:inbound_date',
|
'work_order_code': 'inbound_product:work_order_code', 'order_id': 'inbound_product:order_id',
|
||||||
'barcode': 'inbound_product:barcode',
|
'production_manager': 'inbound_product:production_manager', 'production_start_time': 'inbound_product:production_start_time',
|
||||||
'serial_number': 'inbound_product:serial_number',
|
'production_end_time': 'inbound_product:production_end_time', 'raw_material_cost': 'inbound_product:raw_material_cost',
|
||||||
'status': 'inbound_product:status',
|
'manual_cost': 'inbound_product:manual_cost', 'sale_price': 'inbound_product:sale_price',
|
||||||
'quality_status': 'inbound_product:quality_status',
|
'product_photo': 'inbound_product:product_photo', 'quality_report_link': 'inbound_product:quality_report_link',
|
||||||
'in_quantity': 'inbound_product:in_quantity',
|
'inspection_report_link': 'inbound_product:inspection_report_link', 'detail_link': 'inbound_product:detail_link',
|
||||||
'stock_quantity': 'inbound_product:stock_quantity',
|
|
||||||
'available_quantity': 'inbound_product:available_quantity',
|
|
||||||
'warehouse_location': 'inbound_product:warehouse_location',
|
|
||||||
'bom_code': 'inbound_product:bom_code',
|
|
||||||
'bom_version': 'inbound_product:bom_version',
|
|
||||||
'work_order_code': 'inbound_product:work_order_code',
|
|
||||||
'order_id': 'inbound_product:order_id',
|
|
||||||
'production_manager': 'inbound_product:production_manager',
|
|
||||||
'production_start_time': 'inbound_product:production_start_time',
|
|
||||||
'production_end_time': 'inbound_product:production_end_time',
|
|
||||||
'raw_material_cost': 'inbound_product:raw_material_cost',
|
|
||||||
'manual_cost': 'inbound_product:manual_cost',
|
|
||||||
'sale_price': 'inbound_product:sale_price',
|
|
||||||
'product_photo': 'inbound_product:product_photo',
|
|
||||||
'quality_report_link': 'inbound_product:quality_report_link',
|
|
||||||
'inspection_report_link': 'inbound_product:inspection_report_link',
|
|
||||||
'detail_link': 'inbound_product:detail_link',
|
|
||||||
}
|
}
|
||||||
# 如果用户是超级管理员且有 'inbound_product:*',则不过滤
|
if 'inbound_product:*' in user_permissions: return item_dict
|
||||||
if 'inbound_product:*' in user_permissions:
|
|
||||||
return item_dict
|
|
||||||
for field, perm_code in field_to_perm.items():
|
for field, perm_code in field_to_perm.items():
|
||||||
if field in item_dict and perm_code not in user_permissions:
|
if field in item_dict and perm_code not in user_permissions: item_dict[field] = None
|
||||||
item_dict[field] = None
|
|
||||||
return item_dict
|
return item_dict
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# 0. 基础物料搜索 (关键接口:配合 Service 实现自动回填)
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
@inbound_product_bp.route('/search-base', methods=['GET'])
|
@inbound_product_bp.route('/search-base', methods=['GET'])
|
||||||
@permission_required('inbound_product')
|
@permission_required('inbound_product')
|
||||||
def search_base():
|
def search_base():
|
||||||
"""
|
|
||||||
对应前端 API: /inbound/product/search-base
|
|
||||||
功能: 模糊搜索基础物料,返回 spec, unit, category, type 等详细信息
|
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
keyword = request.args.get('keyword', '')
|
keyword = request.args.get('keyword', '')
|
||||||
page = request.args.get('page', 1, type=int)
|
page = request.args.get('page', 1, type=int)
|
||||||
# 调用 Service 层已修复的 search_base_material 方法
|
|
||||||
result = ProductInboundService.search_base_material(keyword, page)
|
result = ProductInboundService.search_base_material(keyword, page)
|
||||||
# 字段级脱敏
|
|
||||||
user_permissions = get_current_user_permissions()
|
user_permissions = get_current_user_permissions()
|
||||||
if result.get('items'):
|
if result.get('items'):
|
||||||
result['items'] = [filter_item_by_permissions(item, user_permissions) for item in result['items']]
|
result['items'] = [filter_item_by_permissions(item, user_permissions) for item in result['items']]
|
||||||
return jsonify({"code": 200, "msg": "success", "data": result})
|
return jsonify({"code": 200, "msg": "success", "data": result})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# 捕获异常并打印堆栈,方便调试
|
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# 0.5 [新增] BOM 搜索接口
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
@inbound_product_bp.route('/search-bom', methods=['GET'])
|
@inbound_product_bp.route('/search-bom', methods=['GET'])
|
||||||
@permission_required('inbound_product')
|
@permission_required('inbound_product')
|
||||||
def search_bom():
|
def search_bom():
|
||||||
"""
|
|
||||||
供前端下拉框远程搜索使用 (搜索BOM)
|
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
keyword = request.args.get('keyword', '')
|
keyword = request.args.get('keyword', '')
|
||||||
data = ProductInboundService.search_bom_options(keyword)
|
data = ProductInboundService.search_bom_options(keyword)
|
||||||
return jsonify({
|
return jsonify({"code": 200, "msg": "success", "data": data})
|
||||||
"code": 200,
|
|
||||||
"msg": "success",
|
|
||||||
"data": data
|
|
||||||
})
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# 1. 获取列表 (支持 status 多选筛选)
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
@inbound_product_bp.route('/list', methods=['GET'])
|
@inbound_product_bp.route('/list', methods=['GET'])
|
||||||
@permission_required('inbound_product')
|
@permission_required('inbound_product')
|
||||||
def get_list():
|
def get_list():
|
||||||
@ -137,21 +73,12 @@ def get_list():
|
|||||||
page = request.args.get('page', 1, type=int)
|
page = request.args.get('page', 1, type=int)
|
||||||
limit = request.args.get('pageSize', 15, type=int)
|
limit = request.args.get('pageSize', 15, type=int)
|
||||||
keyword = request.args.get('keyword', '')
|
keyword = request.args.get('keyword', '')
|
||||||
|
|
||||||
# 接收状态参数 (逗号分隔字符串 -> 列表)
|
|
||||||
statuses_str = request.args.get('statuses', '')
|
statuses_str = request.args.get('statuses', '')
|
||||||
statuses = statuses_str.split(',') if statuses_str else []
|
statuses = statuses_str.split(',') if statuses_str else []
|
||||||
|
|
||||||
# 接收新增筛选参数
|
|
||||||
category = request.args.get('category', '')
|
category = request.args.get('category', '')
|
||||||
material_type = request.args.get('material_type', '')
|
material_type = request.args.get('material_type', '')
|
||||||
company = request.args.get('company', '')
|
company = request.args.get('company', '')
|
||||||
|
result = ProductInboundService.get_list(page, limit, keyword, statuses, category, material_type, company)
|
||||||
result = ProductInboundService.get_list(
|
|
||||||
page, limit, keyword, statuses,
|
|
||||||
category, material_type, company
|
|
||||||
)
|
|
||||||
# 字段级脱敏
|
|
||||||
user_permissions = get_current_user_permissions()
|
user_permissions = get_current_user_permissions()
|
||||||
if result.get('items'):
|
if result.get('items'):
|
||||||
result['items'] = [filter_item_by_permissions(item, user_permissions) for item in result['items']]
|
result['items'] = [filter_item_by_permissions(item, user_permissions) for item in result['items']]
|
||||||
@ -160,138 +87,41 @@ def get_list():
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# 2. 新增入库
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
@inbound_product_bp.route('/submit', methods=['POST'])
|
@inbound_product_bp.route('/submit', methods=['POST'])
|
||||||
@permission_required('inbound_product:operation')
|
@permission_required('inbound_product:operation')
|
||||||
def submit():
|
def submit():
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
if not data:
|
if not data: return jsonify({"code": 400, "msg": "No data"}), 400
|
||||||
return jsonify({"code": 400, "msg": "No data"}), 400
|
|
||||||
|
|
||||||
# 数据清洗:移除用户没有权限的字段
|
|
||||||
user_permissions = get_current_user_permissions()
|
user_permissions = get_current_user_permissions()
|
||||||
# 超级管理员不过滤
|
|
||||||
if 'inbound_product:*' not in user_permissions:
|
if 'inbound_product:*' not in user_permissions:
|
||||||
field_to_perm = {
|
field_to_perm = {'id': 'inbound_product:id', 'base_id': 'inbound_product:base_id', 'company_name': 'inbound_product:company_name', 'material_name': 'inbound_product:material_name', 'category': 'inbound_product:category', 'material_type': 'inbound_product:material_type', 'spec_model': 'inbound_product:spec_model', 'unit': 'inbound_product:unit', 'sku': 'inbound_product:sku', 'inbound_date': 'inbound_product:inbound_date', 'barcode': 'inbound_product:barcode', 'serial_number': 'inbound_product:serial_number', 'status': 'inbound_product:status', 'quality_status': 'inbound_product:quality_status', 'in_quantity': 'inbound_product:in_quantity', 'stock_quantity': 'inbound_product:stock_quantity', 'available_quantity': 'inbound_product:available_quantity', 'warehouse_location': 'inbound_product:warehouse_location', 'bom_code': 'inbound_product:bom_code', 'bom_version': 'inbound_product:bom_version', 'work_order_code': 'inbound_product:work_order_code', 'order_id': 'inbound_product:order_id', 'production_manager': 'inbound_product:production_manager', 'production_start_time': 'inbound_product:production_start_time', 'production_end_time': 'inbound_product:production_end_time', 'raw_material_cost': 'inbound_product:raw_material_cost', 'manual_cost': 'inbound_product:manual_cost', 'sale_price': 'inbound_product:sale_price', 'product_photo': 'inbound_product:product_photo', 'quality_report_link': 'inbound_product:quality_report_link', 'inspection_report_link': 'inbound_product:inspection_report_link', 'detail_link': 'inbound_product:detail_link'}
|
||||||
'id': 'inbound_product:id',
|
|
||||||
'base_id': 'inbound_product:base_id',
|
|
||||||
'company_name': 'inbound_product:company_name',
|
|
||||||
'material_name': 'inbound_product:material_name',
|
|
||||||
'category': 'inbound_product:category',
|
|
||||||
'material_type': 'inbound_product:material_type',
|
|
||||||
'spec_model': 'inbound_product:spec_model',
|
|
||||||
'unit': 'inbound_product:unit',
|
|
||||||
'sku': 'inbound_product:sku',
|
|
||||||
'inbound_date': 'inbound_product:inbound_date',
|
|
||||||
'barcode': 'inbound_product:barcode',
|
|
||||||
'serial_number': 'inbound_product:serial_number',
|
|
||||||
'status': 'inbound_product:status',
|
|
||||||
'quality_status': 'inbound_product:quality_status',
|
|
||||||
'in_quantity': 'inbound_product:in_quantity',
|
|
||||||
'stock_quantity': 'inbound_product:stock_quantity',
|
|
||||||
'available_quantity': 'inbound_product:available_quantity',
|
|
||||||
'warehouse_location': 'inbound_product:warehouse_location',
|
|
||||||
'bom_code': 'inbound_product:bom_code',
|
|
||||||
'bom_version': 'inbound_product:bom_version',
|
|
||||||
'work_order_code': 'inbound_product:work_order_code',
|
|
||||||
'order_id': 'inbound_product:order_id',
|
|
||||||
'production_manager': 'inbound_product:production_manager',
|
|
||||||
'production_start_time': 'inbound_product:production_start_time',
|
|
||||||
'production_end_time': 'inbound_product:production_end_time',
|
|
||||||
'raw_material_cost': 'inbound_product:raw_material_cost',
|
|
||||||
'manual_cost': 'inbound_product:manual_cost',
|
|
||||||
'sale_price': 'inbound_product:sale_price',
|
|
||||||
'product_photo': 'inbound_product:product_photo',
|
|
||||||
'quality_report_link': 'inbound_product:quality_report_link',
|
|
||||||
'inspection_report_link': 'inbound_product:inspection_report_link',
|
|
||||||
'detail_link': 'inbound_product:detail_link',
|
|
||||||
}
|
|
||||||
# 复制一份,避免遍历时修改字典
|
|
||||||
for field in list(data.keys()):
|
for field in list(data.keys()):
|
||||||
perm_code = field_to_perm.get(field)
|
perm_code = field_to_perm.get(field)
|
||||||
if perm_code and perm_code not in user_permissions:
|
if perm_code and perm_code not in user_permissions: data.pop(field, None)
|
||||||
data.pop(field, None)
|
|
||||||
|
|
||||||
# 调用 Service 处理入库,获取新创建的对象
|
|
||||||
new_stock = ProductInboundService.handle_inbound(data)
|
new_stock = ProductInboundService.handle_inbound(data)
|
||||||
|
return jsonify({"code": 200, "msg": "入库成功", "data": new_stock.to_dict()})
|
||||||
# 返回成功信息以及新创建的数据(包含生成的ID和SKU),供前端自动打印使用
|
|
||||||
return jsonify({
|
|
||||||
"code": 200,
|
|
||||||
"msg": "入库成功",
|
|
||||||
"data": new_stock.to_dict()
|
|
||||||
})
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# 3. 更新入库
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
@inbound_product_bp.route('/<int:id>', methods=['PUT'])
|
@inbound_product_bp.route('/<int:id>', methods=['PUT'])
|
||||||
@permission_required('inbound_product:operation')
|
@permission_required('inbound_product:operation')
|
||||||
def update(id):
|
def update(id):
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
# 数据清洗:移除用户没有权限的字段
|
|
||||||
user_permissions = get_current_user_permissions()
|
user_permissions = get_current_user_permissions()
|
||||||
# 超级管理员不过滤
|
|
||||||
if 'inbound_product:*' not in user_permissions:
|
if 'inbound_product:*' not in user_permissions:
|
||||||
field_to_perm = {
|
field_to_perm = {'id': 'inbound_product:id', 'base_id': 'inbound_product:base_id', 'company_name': 'inbound_product:company_name', 'material_name': 'inbound_product:material_name', 'category': 'inbound_product:category', 'material_type': 'inbound_product:material_type', 'spec_model': 'inbound_product:spec_model', 'unit': 'inbound_product:unit', 'sku': 'inbound_product:sku', 'inbound_date': 'inbound_product:inbound_date', 'barcode': 'inbound_product:barcode', 'serial_number': 'inbound_product:serial_number', 'status': 'inbound_product:status', 'quality_status': 'inbound_product:quality_status', 'in_quantity': 'inbound_product:in_quantity', 'stock_quantity': 'inbound_product:stock_quantity', 'available_quantity': 'inbound_product:available_quantity', 'warehouse_location': 'inbound_product:warehouse_location', 'bom_code': 'inbound_product:bom_code', 'bom_version': 'inbound_product:bom_version', 'work_order_code': 'inbound_product:work_order_code', 'order_id': 'inbound_product:order_id', 'production_manager': 'inbound_product:production_manager', 'production_start_time': 'inbound_product:production_start_time', 'production_end_time': 'inbound_product:production_end_time', 'raw_material_cost': 'inbound_product:raw_material_cost', 'manual_cost': 'inbound_product:manual_cost', 'sale_price': 'inbound_product:sale_price', 'product_photo': 'inbound_product:product_photo', 'quality_report_link': 'inbound_product:quality_report_link', 'inspection_report_link': 'inbound_product:inspection_report_link', 'detail_link': 'inbound_product:detail_link'}
|
||||||
'id': 'inbound_product:id',
|
|
||||||
'base_id': 'inbound_product:base_id',
|
|
||||||
'company_name': 'inbound_product:company_name',
|
|
||||||
'material_name': 'inbound_product:material_name',
|
|
||||||
'category': 'inbound_product:category',
|
|
||||||
'material_type': 'inbound_product:material_type',
|
|
||||||
'spec_model': 'inbound_product:spec_model',
|
|
||||||
'unit': 'inbound_product:unit',
|
|
||||||
'sku': 'inbound_product:sku',
|
|
||||||
'inbound_date': 'inbound_product:inbound_date',
|
|
||||||
'barcode': 'inbound_product:barcode',
|
|
||||||
'serial_number': 'inbound_product:serial_number',
|
|
||||||
'status': 'inbound_product:status',
|
|
||||||
'quality_status': 'inbound_product:quality_status',
|
|
||||||
'in_quantity': 'inbound_product:in_quantity',
|
|
||||||
'stock_quantity': 'inbound_product:stock_quantity',
|
|
||||||
'available_quantity': 'inbound_product:available_quantity',
|
|
||||||
'warehouse_location': 'inbound_product:warehouse_location',
|
|
||||||
'bom_code': 'inbound_product:bom_code',
|
|
||||||
'bom_version': 'inbound_product:bom_version',
|
|
||||||
'work_order_code': 'inbound_product:work_order_code',
|
|
||||||
'order_id': 'inbound_product:order_id',
|
|
||||||
'production_manager': 'inbound_product:production_manager',
|
|
||||||
'production_start_time': 'inbound_product:production_start_time',
|
|
||||||
'production_end_time': 'inbound_product:production_end_time',
|
|
||||||
'raw_material_cost': 'inbound_product:raw_material_cost',
|
|
||||||
'manual_cost': 'inbound_product:manual_cost',
|
|
||||||
'sale_price': 'inbound_product:sale_price',
|
|
||||||
'product_photo': 'inbound_product:product_photo',
|
|
||||||
'quality_report_link': 'inbound_product:quality_report_link',
|
|
||||||
'inspection_report_link': 'inbound_product:inspection_report_link',
|
|
||||||
'detail_link': 'inbound_product:detail_link',
|
|
||||||
}
|
|
||||||
# 复制一份,避免遍历时修改字典
|
|
||||||
for field in list(data.keys()):
|
for field in list(data.keys()):
|
||||||
perm_code = field_to_perm.get(field)
|
perm_code = field_to_perm.get(field)
|
||||||
if perm_code and perm_code not in user_permissions:
|
if perm_code and perm_code not in user_permissions: data.pop(field, None)
|
||||||
data.pop(field, None)
|
|
||||||
|
|
||||||
ProductInboundService.update_inbound(id, data)
|
ProductInboundService.update_inbound(id, data)
|
||||||
return jsonify({"code": 200, "msg": "更新成功"})
|
return jsonify({"code": 200, "msg": "更新成功"})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# 4. 删除
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
@inbound_product_bp.route('/<int:id>', methods=['DELETE'])
|
@inbound_product_bp.route('/<int:id>', methods=['DELETE'])
|
||||||
@permission_required('inbound_product:operation')
|
@permission_required('inbound_product:operation')
|
||||||
def delete(id):
|
def delete(id):
|
||||||
@ -302,10 +132,6 @@ def delete(id):
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# 5. 获取出库历史
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
@inbound_product_bp.route('/<int:id>/history', methods=['GET'])
|
@inbound_product_bp.route('/<int:id>/history', methods=['GET'])
|
||||||
@permission_required('inbound_product')
|
@permission_required('inbound_product')
|
||||||
def get_history(id):
|
def get_history(id):
|
||||||
@ -316,10 +142,6 @@ def get_history(id):
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# 6. 系统用户建议
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
@inbound_product_bp.route('/suggestions/users', methods=['GET'])
|
@inbound_product_bp.route('/suggestions/users', methods=['GET'])
|
||||||
@permission_required('inbound_product')
|
@permission_required('inbound_product')
|
||||||
def get_user_suggestions():
|
def get_user_suggestions():
|
||||||
@ -327,10 +149,6 @@ def get_user_suggestions():
|
|||||||
data = ProductInboundService.search_system_users(keyword)
|
data = ProductInboundService.search_system_users(keyword)
|
||||||
return jsonify({"code": 200, "msg": "success", "data": data})
|
return jsonify({"code": 200, "msg": "success", "data": data})
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# 7. 获取筛选选项
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
@inbound_product_bp.route('/options', methods=['GET'])
|
@inbound_product_bp.route('/options', methods=['GET'])
|
||||||
@permission_required('inbound_product')
|
@permission_required('inbound_product')
|
||||||
def get_options():
|
def get_options():
|
||||||
@ -340,18 +158,12 @@ def get_options():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# 8. 获取历史生产负责人建议 (新增)
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
@inbound_product_bp.route('/suggestions/managers', methods=['GET'])
|
@inbound_product_bp.route('/suggestions/managers', methods=['GET'])
|
||||||
@permission_required('inbound_product')
|
@permission_required('inbound_product')
|
||||||
def get_manager_history():
|
def get_manager_history():
|
||||||
base_id = request.args.get('base_id', type=int)
|
keyword = request.args.get('keyword', '')
|
||||||
if not base_id:
|
|
||||||
return jsonify({"code": 400, "msg": "缺少 base_id"}), 400
|
|
||||||
try:
|
try:
|
||||||
data = ProductInboundService.get_history_managers(base_id)
|
data = ProductInboundService.get_history_managers(keyword)
|
||||||
return jsonify({"code": 200, "msg": "success", "data": data})
|
return jsonify({"code": 200, "msg": "success", "data": data})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|||||||
@ -4,151 +4,49 @@ from app.services.inbound.semi_service import SemiInboundService
|
|||||||
from app.utils.decorators import permission_required
|
from app.utils.decorators import permission_required
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
# 定义蓝图
|
# === 这一行非常关键,绝对不能丢!===
|
||||||
inbound_semi_bp = Blueprint('stock_semi', __name__)
|
inbound_semi_bp = Blueprint('stock_semi', __name__)
|
||||||
|
|
||||||
|
|
||||||
# ==============================================================================
|
|
||||||
# 辅助函数:获取当前用户的完整权限列表(基于角色查询)
|
|
||||||
# ==============================================================================
|
|
||||||
def get_current_user_permissions():
|
def get_current_user_permissions():
|
||||||
"""
|
|
||||||
返回当前用户拥有的所有权限码列表(包括菜单和元素)
|
|
||||||
此函数根据角色查询数据库得到权限。
|
|
||||||
"""
|
|
||||||
from flask_jwt_extended import get_jwt
|
from flask_jwt_extended import get_jwt
|
||||||
from app.services.auth_service import AuthService
|
from app.services.auth_service import AuthService
|
||||||
claims = get_jwt()
|
claims = get_jwt()
|
||||||
user_role = claims.get('role')
|
user_role = claims.get('role')
|
||||||
if not user_role:
|
if not user_role: return []
|
||||||
return []
|
if user_role.upper() == 'SUPER_ADMIN': return ['inbound_semi:*']
|
||||||
# 超级管理员返回所有字段权限 (忽略大小写)
|
|
||||||
if user_role.upper() == 'SUPER_ADMIN':
|
|
||||||
# 返回所有以 inbound_semi: 开头的权限码(这里我们返回一个特殊标记,表示全部)
|
|
||||||
# 为了简单,我们返回 ['inbound_semi:*'],在过滤函数中特殊处理
|
|
||||||
return ['inbound_semi:*']
|
|
||||||
perm_dict = AuthService.get_user_permissions(user_role)
|
perm_dict = AuthService.get_user_permissions(user_role)
|
||||||
# 合并菜单和元素权限
|
return perm_dict.get('menus', []) + perm_dict.get('elements', [])
|
||||||
perms = perm_dict.get('menus', []) + perm_dict.get('elements', [])
|
|
||||||
return perms
|
|
||||||
|
|
||||||
|
|
||||||
def filter_item_by_permissions(item_dict, user_permissions):
|
def filter_item_by_permissions(item_dict, user_permissions):
|
||||||
"""
|
|
||||||
根据用户权限过滤 item 字典,无权限的字段值置为 None
|
|
||||||
"""
|
|
||||||
# 字段名到权限码的映射(与前端 permissionMap 保持一致)
|
|
||||||
field_to_perm = {
|
field_to_perm = {
|
||||||
'id': 'inbound_semi:id',
|
'id': 'inbound_semi:id', 'base_id': 'inbound_semi:base_id', 'company_name': 'inbound_semi:company_name',
|
||||||
'base_id': 'inbound_semi:base_id',
|
'material_name': 'inbound_semi:material_name', 'category': 'inbound_semi:category',
|
||||||
'company_name': 'inbound_semi:company_name',
|
'material_type': 'inbound_semi:material_type', 'spec_model': 'inbound_semi:spec_model',
|
||||||
'material_name': 'inbound_semi:material_name',
|
'unit': 'inbound_semi:unit', 'sku': 'inbound_semi:sku', 'inbound_date': 'inbound_semi:inbound_date',
|
||||||
'category': 'inbound_semi:category',
|
'barcode': 'inbound_semi:barcode', 'serial_number': 'inbound_semi:serial_number',
|
||||||
'material_type': 'inbound_semi:material_type',
|
'batch_number': 'inbound_semi:batch_number', 'status': 'inbound_semi:status',
|
||||||
'spec_model': 'inbound_semi:spec_model',
|
'quality_status': 'inbound_semi:quality_status', 'in_quantity': 'inbound_semi:in_quantity',
|
||||||
'unit': 'inbound_semi:unit',
|
'stock_quantity': 'inbound_semi:stock_quantity', 'available_quantity': 'inbound_semi:available_quantity',
|
||||||
'sku': 'inbound_semi:sku',
|
'warehouse_location': 'inbound_semi:warehouse_location', 'bom_code': 'inbound_semi:bom_code',
|
||||||
'inbound_date': 'inbound_semi:inbound_date',
|
'bom_version': 'inbound_semi:bom_version', 'work_order_code': 'inbound_semi:work_order_code',
|
||||||
'barcode': 'inbound_semi:barcode',
|
'raw_material_cost': 'inbound_semi:raw_material_cost', 'manual_cost': 'inbound_semi:manual_cost',
|
||||||
'serial_number': 'inbound_semi:serial_number',
|
'unit_total_cost': 'inbound_semi:unit_total_cost', 'production_manager': 'inbound_semi:production_manager',
|
||||||
'batch_number': 'inbound_semi:batch_number',
|
'production_start_time': 'inbound_semi:production_start_time', 'production_end_time': 'inbound_semi:production_end_time',
|
||||||
'status': 'inbound_semi:status',
|
'arrival_photo': 'inbound_semi:arrival_photo', 'quality_report_link': 'inbound_semi:quality_report_link',
|
||||||
'quality_status': 'inbound_semi:quality_status',
|
|
||||||
'in_quantity': 'inbound_semi:in_quantity',
|
|
||||||
'stock_quantity': 'inbound_semi:stock_quantity',
|
|
||||||
'available_quantity': 'inbound_semi:available_quantity',
|
|
||||||
'warehouse_location': 'inbound_semi:warehouse_location',
|
|
||||||
'bom_code': 'inbound_semi:bom_code',
|
|
||||||
'bom_version': 'inbound_semi:bom_version',
|
|
||||||
'work_order_code': 'inbound_semi:work_order_code',
|
|
||||||
'raw_material_cost': 'inbound_semi:raw_material_cost',
|
|
||||||
'manual_cost': 'inbound_semi:manual_cost',
|
|
||||||
'unit_total_cost': 'inbound_semi:unit_total_cost',
|
|
||||||
'production_manager': 'inbound_semi:production_manager',
|
|
||||||
'production_start_time': 'inbound_semi:production_start_time',
|
|
||||||
'production_end_time': 'inbound_semi:production_end_time',
|
|
||||||
'arrival_photo': 'inbound_semi:arrival_photo',
|
|
||||||
'quality_report_link': 'inbound_semi:quality_report_link',
|
|
||||||
'detail_link': 'inbound_semi:detail_link',
|
'detail_link': 'inbound_semi:detail_link',
|
||||||
}
|
}
|
||||||
# 如果用户是超级管理员且有 'inbound_semi:*',则不过滤
|
if 'inbound_semi:*' in user_permissions: return item_dict
|
||||||
if 'inbound_semi:*' in user_permissions:
|
|
||||||
return item_dict
|
|
||||||
for field, perm_code in field_to_perm.items():
|
for field, perm_code in field_to_perm.items():
|
||||||
if field in item_dict and perm_code not in user_permissions:
|
if field in item_dict and perm_code not in user_permissions: item_dict[field] = None
|
||||||
item_dict[field] = None
|
|
||||||
return item_dict
|
return item_dict
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# 0. 基础物料搜索 (复用逻辑)
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
@inbound_semi_bp.route('/search-base', methods=['GET'])
|
@inbound_semi_bp.route('/search-base', methods=['GET'])
|
||||||
@permission_required('inbound_semi')
|
@permission_required('inbound_semi')
|
||||||
def search_base():
|
def search_base():
|
||||||
"""
|
|
||||||
供前端下拉框远程搜索使用 (搜索半成品类型的基础物料)
|
|
||||||
Query Param: keyword (名称或规格)
|
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
keyword = request.args.get('keyword', '')
|
keyword = request.args.get('keyword', '')
|
||||||
page = request.args.get('page', 1, type=int)
|
page = request.args.get('page', 1, type=int)
|
||||||
# 这里复用 Service 中的搜索逻辑 (已修改接收 page)
|
|
||||||
result = SemiInboundService.search_base_material(keyword, page)
|
result = SemiInboundService.search_base_material(keyword, page)
|
||||||
# 字段级脱敏
|
|
||||||
user_permissions = get_current_user_permissions()
|
|
||||||
if result.get('items'):
|
|
||||||
result['items'] = [filter_item_by_permissions(item, user_permissions) for item in result['items']]
|
|
||||||
return jsonify({
|
|
||||||
"code": 200,
|
|
||||||
"msg": "success",
|
|
||||||
"data": result
|
|
||||||
})
|
|
||||||
except Exception as e:
|
|
||||||
traceback.print_exc()
|
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# 0.5 [新增] BOM 搜索接口
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
@inbound_semi_bp.route('/search-bom', methods=['GET'])
|
|
||||||
@permission_required('inbound_semi')
|
|
||||||
def search_bom():
|
|
||||||
"""
|
|
||||||
供前端下拉框远程搜索使用 (搜索BOM)
|
|
||||||
Query Param: keyword (编号或父件规格)
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
keyword = request.args.get('keyword', '')
|
|
||||||
data = SemiInboundService.search_bom_options(keyword)
|
|
||||||
return jsonify({
|
|
||||||
"code": 200,
|
|
||||||
"msg": "success",
|
|
||||||
"data": data
|
|
||||||
})
|
|
||||||
except Exception as e:
|
|
||||||
traceback.print_exc()
|
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# 1. 获取半成品列表
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
@inbound_semi_bp.route('/list', methods=['GET'])
|
|
||||||
@permission_required('inbound_semi')
|
|
||||||
def get_list():
|
|
||||||
try:
|
|
||||||
page = request.args.get('page', 1, type=int)
|
|
||||||
limit = request.args.get('pageSize', 15, type=int)
|
|
||||||
# 支持按关键字搜索:BOM号、工单号、SN、批号等
|
|
||||||
keyword = request.args.get('keyword', '')
|
|
||||||
|
|
||||||
# [修改] 获取状态列表参数
|
|
||||||
statuses_str = request.args.get('statuses', '')
|
|
||||||
statuses = statuses_str.split(',') if statuses_str else []
|
|
||||||
|
|
||||||
result = SemiInboundService.get_list(page, limit, keyword, statuses)
|
|
||||||
# 字段级脱敏
|
|
||||||
user_permissions = get_current_user_permissions()
|
user_permissions = get_current_user_permissions()
|
||||||
if result.get('items'):
|
if result.get('items'):
|
||||||
result['items'] = [filter_item_by_permissions(item, user_permissions) for item in result['items']]
|
result['items'] = [filter_item_by_permissions(item, user_permissions) for item in result['items']]
|
||||||
@ -157,137 +55,70 @@ def get_list():
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
|
@inbound_semi_bp.route('/search-bom', methods=['GET'])
|
||||||
|
@permission_required('inbound_semi')
|
||||||
|
def search_bom():
|
||||||
|
try:
|
||||||
|
keyword = request.args.get('keyword', '')
|
||||||
|
data = SemiInboundService.search_bom_options(keyword)
|
||||||
|
return jsonify({"code": 200, "msg": "success", "data": data})
|
||||||
|
except Exception as e:
|
||||||
|
traceback.print_exc()
|
||||||
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
|
@inbound_semi_bp.route('/list', methods=['GET'])
|
||||||
|
@permission_required('inbound_semi')
|
||||||
|
def get_list():
|
||||||
|
try:
|
||||||
|
page = request.args.get('page', 1, type=int)
|
||||||
|
limit = request.args.get('pageSize', 15, type=int)
|
||||||
|
keyword = request.args.get('keyword', '')
|
||||||
|
statuses_str = request.args.get('statuses', '')
|
||||||
|
statuses = statuses_str.split(',') if statuses_str else []
|
||||||
|
result = SemiInboundService.get_list(page, limit, keyword, statuses)
|
||||||
|
user_permissions = get_current_user_permissions()
|
||||||
|
if result.get('items'):
|
||||||
|
result['items'] = [filter_item_by_permissions(item, user_permissions) for item in result['items']]
|
||||||
|
return jsonify({"code": 200, "msg": "success", "data": result})
|
||||||
|
except Exception as e:
|
||||||
|
traceback.print_exc()
|
||||||
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# 2. 新增半成品入库 (修改:返回创建的对象数据)
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
@inbound_semi_bp.route('/submit', methods=['POST'])
|
@inbound_semi_bp.route('/submit', methods=['POST'])
|
||||||
@permission_required('inbound_semi:operation')
|
@permission_required('inbound_semi:operation')
|
||||||
def submit():
|
def submit():
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
if not data:
|
if not data: return jsonify({"code": 400, "msg": "No data"}), 400
|
||||||
return jsonify({"code": 400, "msg": "No data"}), 400
|
|
||||||
|
|
||||||
# 数据清洗:移除用户没有权限的字段
|
|
||||||
user_permissions = get_current_user_permissions()
|
user_permissions = get_current_user_permissions()
|
||||||
# 超级管理员不过滤
|
|
||||||
if 'inbound_semi:*' not in user_permissions:
|
if 'inbound_semi:*' not in user_permissions:
|
||||||
# 字段名到权限码的映射(与前端 permissionMap 保持一致)
|
field_to_perm = {'id': 'inbound_semi:id', 'base_id': 'inbound_semi:base_id', 'company_name': 'inbound_semi:company_name', 'material_name': 'inbound_semi:material_name', 'category': 'inbound_semi:category', 'material_type': 'inbound_semi:material_type', 'spec_model': 'inbound_semi:spec_model', 'unit': 'inbound_semi:unit', 'sku': 'inbound_semi:sku', 'inbound_date': 'inbound_semi:inbound_date', 'barcode': 'inbound_semi:barcode', 'serial_number': 'inbound_semi:serial_number', 'batch_number': 'inbound_semi:batch_number', 'status': 'inbound_semi:status', 'quality_status': 'inbound_semi:quality_status', 'in_quantity': 'inbound_semi:in_quantity', 'stock_quantity': 'inbound_semi:stock_quantity', 'available_quantity': 'inbound_semi:available_quantity', 'warehouse_location': 'inbound_semi:warehouse_location', 'bom_code': 'inbound_semi:bom_code', 'bom_version': 'inbound_semi:bom_version', 'work_order_code': 'inbound_semi:work_order_code', 'raw_material_cost': 'inbound_semi:raw_material_cost', 'manual_cost': 'inbound_semi:manual_cost', 'unit_total_cost': 'inbound_semi:unit_total_cost', 'production_manager': 'inbound_semi:production_manager', 'production_start_time': 'inbound_semi:production_start_time', 'production_end_time': 'inbound_semi:production_end_time', 'arrival_photo': 'inbound_semi:arrival_photo', 'quality_report_link': 'inbound_semi:quality_report_link', 'detail_link': 'inbound_semi:detail_link'}
|
||||||
field_to_perm = {
|
|
||||||
'id': 'inbound_semi:id',
|
|
||||||
'base_id': 'inbound_semi:base_id',
|
|
||||||
'company_name': 'inbound_semi:company_name',
|
|
||||||
'material_name': 'inbound_semi:material_name',
|
|
||||||
'category': 'inbound_semi:category',
|
|
||||||
'material_type': 'inbound_semi:material_type',
|
|
||||||
'spec_model': 'inbound_semi:spec_model',
|
|
||||||
'unit': 'inbound_semi:unit',
|
|
||||||
'sku': 'inbound_semi:sku',
|
|
||||||
'inbound_date': 'inbound_semi:inbound_date',
|
|
||||||
'barcode': 'inbound_semi:barcode',
|
|
||||||
'serial_number': 'inbound_semi:serial_number',
|
|
||||||
'batch_number': 'inbound_semi:batch_number',
|
|
||||||
'status': 'inbound_semi:status',
|
|
||||||
'quality_status': 'inbound_semi:quality_status',
|
|
||||||
'in_quantity': 'inbound_semi:in_quantity',
|
|
||||||
'stock_quantity': 'inbound_semi:stock_quantity',
|
|
||||||
'available_quantity': 'inbound_semi:available_quantity',
|
|
||||||
'warehouse_location': 'inbound_semi:warehouse_location',
|
|
||||||
'bom_code': 'inbound_semi:bom_code',
|
|
||||||
'bom_version': 'inbound_semi:bom_version',
|
|
||||||
'work_order_code': 'inbound_semi:work_order_code',
|
|
||||||
'raw_material_cost': 'inbound_semi:raw_material_cost',
|
|
||||||
'manual_cost': 'inbound_semi:manual_cost',
|
|
||||||
'unit_total_cost': 'inbound_semi:unit_total_cost',
|
|
||||||
'production_manager': 'inbound_semi:production_manager',
|
|
||||||
'production_start_time': 'inbound_semi:production_start_time',
|
|
||||||
'production_end_time': 'inbound_semi:production_end_time',
|
|
||||||
'arrival_photo': 'inbound_semi:arrival_photo',
|
|
||||||
'quality_report_link': 'inbound_semi:quality_report_link',
|
|
||||||
'detail_link': 'inbound_semi:detail_link',
|
|
||||||
}
|
|
||||||
# 复制一份,避免遍历时修改字典
|
|
||||||
for field in list(data.keys()):
|
for field in list(data.keys()):
|
||||||
perm_code = field_to_perm.get(field)
|
perm_code = field_to_perm.get(field)
|
||||||
if perm_code and perm_code not in user_permissions:
|
if perm_code and perm_code not in user_permissions: data.pop(field, None)
|
||||||
data.pop(field, None)
|
|
||||||
|
|
||||||
# 修改:调用 Service 处理入库,获取新创建的对象
|
|
||||||
new_stock = SemiInboundService.handle_inbound(data)
|
new_stock = SemiInboundService.handle_inbound(data)
|
||||||
|
return jsonify({"code": 200, "msg": "入库成功", "data": new_stock.to_dict()})
|
||||||
# 修改:返回成功信息以及新创建的数据(包含生成的ID和SKU),供前端打印使用
|
|
||||||
return jsonify({
|
|
||||||
"code": 200,
|
|
||||||
"msg": "入库成功",
|
|
||||||
"data": new_stock.to_dict()
|
|
||||||
})
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# 3. 更新半成品入库信息
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
@inbound_semi_bp.route('/<int:id>', methods=['PUT'])
|
@inbound_semi_bp.route('/<int:id>', methods=['PUT'])
|
||||||
@permission_required('inbound_semi:operation')
|
@permission_required('inbound_semi:operation')
|
||||||
def update_semi(id):
|
def update_semi(id):
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
# 数据清洗:移除用户没有权限的字段
|
|
||||||
user_permissions = get_current_user_permissions()
|
user_permissions = get_current_user_permissions()
|
||||||
# 超级管理员不过滤
|
|
||||||
if 'inbound_semi:*' not in user_permissions:
|
if 'inbound_semi:*' not in user_permissions:
|
||||||
field_to_perm = {
|
field_to_perm = {'id': 'inbound_semi:id', 'base_id': 'inbound_semi:base_id', 'company_name': 'inbound_semi:company_name', 'material_name': 'inbound_semi:material_name', 'category': 'inbound_semi:category', 'material_type': 'inbound_semi:material_type', 'spec_model': 'inbound_semi:spec_model', 'unit': 'inbound_semi:unit', 'sku': 'inbound_semi:sku', 'inbound_date': 'inbound_semi:inbound_date', 'barcode': 'inbound_semi:barcode', 'serial_number': 'inbound_semi:serial_number', 'batch_number': 'inbound_semi:batch_number', 'status': 'inbound_semi:status', 'quality_status': 'inbound_semi:quality_status', 'in_quantity': 'inbound_semi:in_quantity', 'stock_quantity': 'inbound_semi:stock_quantity', 'available_quantity': 'inbound_semi:available_quantity', 'warehouse_location': 'inbound_semi:warehouse_location', 'bom_code': 'inbound_semi:bom_code', 'bom_version': 'inbound_semi:bom_version', 'work_order_code': 'inbound_semi:work_order_code', 'raw_material_cost': 'inbound_semi:raw_material_cost', 'manual_cost': 'inbound_semi:manual_cost', 'unit_total_cost': 'inbound_semi:unit_total_cost', 'production_manager': 'inbound_semi:production_manager', 'production_start_time': 'inbound_semi:production_start_time', 'production_end_time': 'inbound_semi:production_end_time', 'arrival_photo': 'inbound_semi:arrival_photo', 'quality_report_link': 'inbound_semi:quality_report_link', 'detail_link': 'inbound_semi:detail_link'}
|
||||||
'id': 'inbound_semi:id',
|
|
||||||
'base_id': 'inbound_semi:base_id',
|
|
||||||
'company_name': 'inbound_semi:company_name',
|
|
||||||
'material_name': 'inbound_semi:material_name',
|
|
||||||
'category': 'inbound_semi:category',
|
|
||||||
'material_type': 'inbound_semi:material_type',
|
|
||||||
'spec_model': 'inbound_semi:spec_model',
|
|
||||||
'unit': 'inbound_semi:unit',
|
|
||||||
'sku': 'inbound_semi:sku',
|
|
||||||
'inbound_date': 'inbound_semi:inbound_date',
|
|
||||||
'barcode': 'inbound_semi:barcode',
|
|
||||||
'serial_number': 'inbound_semi:serial_number',
|
|
||||||
'batch_number': 'inbound_semi:batch_number',
|
|
||||||
'status': 'inbound_semi:status',
|
|
||||||
'quality_status': 'inbound_semi:quality_status',
|
|
||||||
'in_quantity': 'inbound_semi:in_quantity',
|
|
||||||
'stock_quantity': 'inbound_semi:stock_quantity',
|
|
||||||
'available_quantity': 'inbound_semi:available_quantity',
|
|
||||||
'warehouse_location': 'inbound_semi:warehouse_location',
|
|
||||||
'bom_code': 'inbound_semi:bom_code',
|
|
||||||
'bom_version': 'inbound_semi:bom_version',
|
|
||||||
'work_order_code': 'inbound_semi:work_order_code',
|
|
||||||
'raw_material_cost': 'inbound_semi:raw_material_cost',
|
|
||||||
'manual_cost': 'inbound_semi:manual_cost',
|
|
||||||
'unit_total_cost': 'inbound_semi:unit_total_cost',
|
|
||||||
'production_manager': 'inbound_semi:production_manager',
|
|
||||||
'production_start_time': 'inbound_semi:production_start_time',
|
|
||||||
'production_end_time': 'inbound_semi:production_end_time',
|
|
||||||
'arrival_photo': 'inbound_semi:arrival_photo',
|
|
||||||
'quality_report_link': 'inbound_semi:quality_report_link',
|
|
||||||
'detail_link': 'inbound_semi:detail_link',
|
|
||||||
}
|
|
||||||
# 复制一份,避免遍历时修改字典
|
|
||||||
for field in list(data.keys()):
|
for field in list(data.keys()):
|
||||||
perm_code = field_to_perm.get(field)
|
perm_code = field_to_perm.get(field)
|
||||||
if perm_code and perm_code not in user_permissions:
|
if perm_code and perm_code not in user_permissions: data.pop(field, None)
|
||||||
data.pop(field, None)
|
|
||||||
|
|
||||||
SemiInboundService.update_inbound(id, data)
|
SemiInboundService.update_inbound(id, data)
|
||||||
return jsonify({"code": 200, "msg": "更新成功"})
|
return jsonify({"code": 200, "msg": "更新成功"})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# 4. 删除半成品入库记录
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
@inbound_semi_bp.route('/<int:id>', methods=['DELETE'])
|
@inbound_semi_bp.route('/<int:id>', methods=['DELETE'])
|
||||||
@permission_required('inbound_semi:operation')
|
@permission_required('inbound_semi:operation')
|
||||||
def delete_semi(id):
|
def delete_semi(id):
|
||||||
@ -298,28 +129,16 @@ def delete_semi(id):
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# 5. [新增] 获取关联出库历史
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
@inbound_semi_bp.route('/<int:id>/history', methods=['GET'])
|
@inbound_semi_bp.route('/<int:id>/history', methods=['GET'])
|
||||||
@permission_required('inbound_semi')
|
@permission_required('inbound_semi')
|
||||||
def get_history(id):
|
def get_history(id):
|
||||||
try:
|
try:
|
||||||
data = SemiInboundService.get_outbound_history(id)
|
data = SemiInboundService.get_outbound_history(id)
|
||||||
return jsonify({
|
return jsonify({"code": 200, "msg": "success", "data": data})
|
||||||
"code": 200,
|
|
||||||
"msg": "success",
|
|
||||||
"data": data
|
|
||||||
})
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# 6. 系统用户建议
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
@inbound_semi_bp.route('/suggestions/users', methods=['GET'])
|
@inbound_semi_bp.route('/suggestions/users', methods=['GET'])
|
||||||
@permission_required('inbound_semi')
|
@permission_required('inbound_semi')
|
||||||
def get_user_suggestions():
|
def get_user_suggestions():
|
||||||
@ -327,10 +146,6 @@ def get_user_suggestions():
|
|||||||
data = SemiInboundService.search_system_users(keyword)
|
data = SemiInboundService.search_system_users(keyword)
|
||||||
return jsonify({"code": 200, "msg": "success", "data": data})
|
return jsonify({"code": 200, "msg": "success", "data": data})
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# 7. 获取筛选选项
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
@inbound_semi_bp.route('/options', methods=['GET'])
|
@inbound_semi_bp.route('/options', methods=['GET'])
|
||||||
@permission_required('inbound_semi')
|
@permission_required('inbound_semi')
|
||||||
def get_options():
|
def get_options():
|
||||||
@ -340,17 +155,12 @@ def get_options():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# 8. 获取历史生产负责人建议 (新增)
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
@inbound_semi_bp.route('/suggestions/managers', methods=['GET'])
|
@inbound_semi_bp.route('/suggestions/managers', methods=['GET'])
|
||||||
@permission_required('inbound_semi')
|
@permission_required('inbound_semi')
|
||||||
def get_manager_history():
|
def get_manager_history():
|
||||||
base_id = request.args.get('base_id', type=int)
|
keyword = request.args.get('keyword', '')
|
||||||
if not base_id:
|
|
||||||
return jsonify({"code": 400, "msg": "缺少 base_id"}), 400
|
|
||||||
try:
|
try:
|
||||||
data = SemiInboundService.get_history_managers(base_id)
|
data = SemiInboundService.get_history_managers(keyword)
|
||||||
return jsonify({"code": 200, "msg": "success", "data": data})
|
return jsonify({"code": 200, "msg": "success", "data": data})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|||||||
@ -399,17 +399,19 @@ class ProductInboundService:
|
|||||||
return {"categories": [], "types": [], "companies": []}
|
return {"categories": [], "types": [], "companies": []}
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
# 8. 获取历史负责人建议 (新增)
|
# 8. 获取历史负责人建议 (修改为全局查询)
|
||||||
# ============================================================
|
# ============================================================
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_history_managers(base_id):
|
def get_history_managers(keyword=None):
|
||||||
from app.models.inbound.product import StockProduct
|
from app.models.inbound.product import StockProduct
|
||||||
try:
|
try:
|
||||||
records = db.session.query(StockProduct.production_manager).filter(
|
query = db.session.query(StockProduct.production_manager).filter(
|
||||||
StockProduct.base_id == base_id,
|
|
||||||
StockProduct.production_manager.isnot(None),
|
StockProduct.production_manager.isnot(None),
|
||||||
StockProduct.production_manager != ''
|
StockProduct.production_manager != ''
|
||||||
).distinct().all()
|
)
|
||||||
|
if keyword:
|
||||||
|
query = query.filter(StockProduct.production_manager.ilike(f'%{keyword}%'))
|
||||||
|
records = query.distinct().all()
|
||||||
return [r[0] for r in records if r[0]]
|
return [r[0] for r in records if r[0]]
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|||||||
@ -487,17 +487,19 @@ class SemiInboundService:
|
|||||||
return {"categories": [], "types": [], "companies": []}
|
return {"categories": [], "types": [], "companies": []}
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
# 8. 获取历史生产负责人 (新增)
|
# 8. 获取历史生产负责人 (修改为全局查询)
|
||||||
# ============================================================
|
# ============================================================
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_history_managers(base_id):
|
def get_history_managers(keyword=None):
|
||||||
from app.models.inbound.semi import StockSemi
|
from app.models.inbound.semi import StockSemi
|
||||||
try:
|
try:
|
||||||
records = db.session.query(StockSemi.production_manager).filter(
|
query = db.session.query(StockSemi.production_manager).filter(
|
||||||
StockSemi.base_id == base_id,
|
|
||||||
StockSemi.production_manager.isnot(None),
|
StockSemi.production_manager.isnot(None),
|
||||||
StockSemi.production_manager != ''
|
StockSemi.production_manager != ''
|
||||||
).distinct().all()
|
)
|
||||||
|
if keyword:
|
||||||
|
query = query.filter(StockSemi.production_manager.ilike(f'%{keyword}%'))
|
||||||
|
records = query.distinct().all()
|
||||||
return [r[0] for r in records if r[0]]
|
return [r[0] for r in records if r[0]]
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|||||||
@ -108,8 +108,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #default="scope" v-else-if="col.prop === 'company_name'">
|
<template #default="scope" v-else-if="col.prop === 'company_name'">
|
||||||
<el-tag v-if="scope.row.company_name" type="info" effect="plain" size="small" style="font-weight: bold;">{{ scope.row.company_name }}</el-tag>
|
<span>{{ scope.row.company_name || '-' }}</span>
|
||||||
<span v-else>-</span>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #default="scope" v-else-if="['serial_number'].includes(col.prop)">
|
<template #default="scope" v-else-if="['serial_number'].includes(col.prop)">
|
||||||
@ -192,7 +191,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
<el-row :gutter="24" v-if="dialogStatus === 'create'" style="margin-bottom: 20px;">
|
<el-row :gutter="24" v-if="dialogStatus === 'create'" style="margin-bottom: 20px;">
|
||||||
<el-col :span="10">
|
<el-col :span="12">
|
||||||
<el-form-item label="物料搜索" prop="base_id" class="highlight-label">
|
<el-form-item label="物料搜索" prop="base_id" class="highlight-label">
|
||||||
<el-select
|
<el-select
|
||||||
v-model="form.base_id"
|
v-model="form.base_id"
|
||||||
@ -200,7 +199,7 @@
|
|||||||
remote
|
remote
|
||||||
reserve-keyword
|
reserve-keyword
|
||||||
clearable
|
clearable
|
||||||
placeholder="搜名称/规格..."
|
placeholder="请输入名称或规格进行检索..."
|
||||||
:remote-method="handleSearchMaterial"
|
:remote-method="handleSearchMaterial"
|
||||||
@visible-change="handleMaterialDropdownVisible"
|
@visible-change="handleMaterialDropdownVisible"
|
||||||
:loading="searchLoading"
|
:loading="searchLoading"
|
||||||
@ -232,9 +231,9 @@
|
|||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="14" style="display: flex; align-items: center;">
|
<el-col :span="12" style="display: flex; align-items: center;">
|
||||||
<span class="search-tip">
|
<span class="search-tip">
|
||||||
<el-icon><InfoFilled /></el-icon> 未输入时展示最新物料;输入关键词进行精确搜索。
|
<el-icon><InfoFilled /></el-icon> 支持名称、规格型号、公司名称模糊搜索
|
||||||
</span>
|
</span>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
@ -469,7 +468,7 @@ import {
|
|||||||
deleteProductInbound,
|
deleteProductInbound,
|
||||||
searchMaterialBase,
|
searchMaterialBase,
|
||||||
searchBom,
|
searchBom,
|
||||||
getFilterOptions, // [新增]
|
getFilterOptions,
|
||||||
getManagerHistory // [新增]
|
getManagerHistory // [新增]
|
||||||
} from '@/api/inbound/product'
|
} from '@/api/inbound/product'
|
||||||
import { uploadFile, deleteFile } from '@/api/inbound/buy'
|
import { uploadFile, deleteFile } from '@/api/inbound/buy'
|
||||||
@ -798,16 +797,14 @@ const onMaterialSelected = (val: number) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
// Autocomplete (Manager) - 后端历史记录驱动 (已修改)
|
// Autocomplete (Manager) - 后端历史记录驱动 (已修改为全局)
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
const querySearchManager = async (query: string, cb: any) => {
|
const querySearchManager = async (query: string, cb: any) => {
|
||||||
if (!form.base_id) { cb([]); return }
|
|
||||||
try {
|
try {
|
||||||
const res: any = await getManagerHistory({ base_id: form.base_id })
|
const res: any = await getManagerHistory({ keyword: query })
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
const managers = (res.data || []).map((name: string) => ({ value: name }))
|
const managers = (res.data || []).map((name: string) => ({ value: name }))
|
||||||
const filtered = query ? managers.filter((item: any) => item.value.toLowerCase().includes(query.toLowerCase())) : managers
|
cb(managers)
|
||||||
cb(filtered)
|
|
||||||
} else { cb([]) }
|
} else { cb([]) }
|
||||||
} catch (e) { cb([]) }
|
} catch (e) { cb([]) }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -119,8 +119,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #default="scope" v-else-if="col.prop === 'company_name'">
|
<template #default="scope" v-else-if="col.prop === 'company_name'">
|
||||||
<el-tag v-if="scope.row.company_name" type="info" effect="plain" size="small" style="font-weight: bold;">{{ scope.row.company_name }}</el-tag>
|
<span>{{ scope.row.company_name || '-' }}</span>
|
||||||
<span v-else>-</span>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #default="scope" v-else-if="col.prop === 'sn_bn'">
|
<template #default="scope" v-else-if="col.prop === 'sn_bn'">
|
||||||
@ -755,16 +754,14 @@ const handleBomSelect = (val: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
// Autocomplete & Search Logic (后端 API 驱动) (已修改)
|
// Autocomplete & Search Logic (后端 API 驱动,全局检索)
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
const querySearchManager = async (query: string, cb: any) => {
|
const querySearchManager = async (query: string, cb: any) => {
|
||||||
if (!form.base_id) { cb([]); return }
|
|
||||||
try {
|
try {
|
||||||
const res: any = await getManagerHistory({ base_id: form.base_id })
|
const res: any = await getManagerHistory({ keyword: query })
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
const managers = (res.data || []).map((name: string) => ({ value: name }))
|
const managers = (res.data || []).map((name: string) => ({ value: name }))
|
||||||
const filtered = query ? managers.filter((item: any) => item.value.toLowerCase().includes(query.toLowerCase())) : managers
|
cb(managers)
|
||||||
cb(filtered)
|
|
||||||
} else { cb([]) }
|
} else { cb([]) }
|
||||||
} catch (e) { cb([]) }
|
} catch (e) { cb([]) }
|
||||||
}
|
}
|
||||||
@ -773,7 +770,7 @@ const handleManagerSelect = (item: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
// Material Search (Matches Buy.vue) (已修改)
|
// Material Search (Matches Buy.vue)
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
const handleMaterialDropdownVisible = (visible: boolean) => { if (visible && materialOptions.value.length === 0) handleSearchMaterialDebounced('') }
|
const handleMaterialDropdownVisible = (visible: boolean) => { if (visible && materialOptions.value.length === 0) handleSearchMaterialDebounced('') }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user