feat: implement MRP kitting calculator for production simulation and shared component analysis
This commit is contained in:
@ -348,3 +348,39 @@ def get_bom_parents():
|
||||
except Exception as e:
|
||||
current_app.logger.error(f'获取BOM父件列表失败: {str(e)}')
|
||||
return jsonify({'code': 500, 'msg': '内部服务器错误'}), 500
|
||||
|
||||
|
||||
# ==============================================================================
|
||||
# MRP 齐套模拟计算
|
||||
# ==============================================================================
|
||||
@bom_bp.route('/calculate-kitting', methods=['POST'])
|
||||
@jwt_required()
|
||||
def calculate_kitting():
|
||||
"""
|
||||
MRP 齐套模拟计算
|
||||
|
||||
入参:
|
||||
[{"bom_no": "BOM-001", "target_qty": 10}, {"bom_no": "BOM-002", "target_qty": 5}]
|
||||
|
||||
算法:
|
||||
1. 展开所有 BOM 的子件,按 child_id 合并需求量(含损耗)
|
||||
2. 跨 StockBuy / StockSemi / StockProduct 聚合当前可用库存
|
||||
3. 计算 shortage = available_quantity - required_quantity
|
||||
|
||||
出参:
|
||||
[{base_id, material_name, spec, unit, required_qty, available_qty, shortage, bom_sources}]
|
||||
"""
|
||||
try:
|
||||
entries = request.get_json()
|
||||
if not entries or not isinstance(entries, list):
|
||||
return jsonify({'code': 400, 'msg': '参数格式错误,需要数组'}), 400
|
||||
|
||||
results = BomService.calculate_kitting(entries)
|
||||
return jsonify({
|
||||
'code': 200,
|
||||
'msg': '计算成功',
|
||||
'data': results
|
||||
})
|
||||
except Exception as e:
|
||||
current_app.logger.error(f'MRP齐套计算失败: {str(e)}')
|
||||
return jsonify({'code': 500, 'msg': f'计算失败: {str(e)}'}), 500
|
||||
|
||||
Reference in New Issue
Block a user