2026-01-27 15:50:23 +08:00
|
|
|
|
from flask import Blueprint, request, jsonify
|
|
|
|
|
|
from app.services.inbound.buy_service import BuyInboundService
|
2026-03-10 17:16:57 +08:00
|
|
|
|
from app.utils.decorators import permission_required, audit_log
|
2026-01-27 15:50:23 +08:00
|
|
|
|
import traceback
|
|
|
|
|
|
|
2026-02-06 10:16:37 +08:00
|
|
|
|
inbound_buy_bp = Blueprint('stock_buy', __name__)
|
2026-01-27 15:50:23 +08:00
|
|
|
|
|
2026-02-11 08:38:12 +08:00
|
|
|
|
|
2026-02-27 11:48:33 +08:00
|
|
|
|
# ==============================================================================
|
|
|
|
|
|
# 辅助函数:获取当前用户的完整权限列表(基于角色查询)
|
|
|
|
|
|
# ==============================================================================
|
|
|
|
|
|
def get_current_user_permissions():
|
|
|
|
|
|
"""
|
|
|
|
|
|
返回当前用户拥有的所有权限码列表(包括菜单和元素)
|
|
|
|
|
|
此函数根据角色查询数据库得到权限。
|
|
|
|
|
|
"""
|
|
|
|
|
|
from flask_jwt_extended import get_jwt
|
|
|
|
|
|
from app.services.auth_service import AuthService
|
|
|
|
|
|
claims = get_jwt()
|
|
|
|
|
|
user_role = claims.get('role')
|
2026-07-13 15:12:22 +08:00
|
|
|
|
user_company = claims.get('company_name', '')
|
2026-02-27 11:48:33 +08:00
|
|
|
|
if not user_role:
|
|
|
|
|
|
return []
|
2026-02-27 17:04:22 +08:00
|
|
|
|
# 超级管理员返回所有字段权限 (忽略大小写)
|
2026-07-17 13:07:12 +08:00
|
|
|
|
from app.utils.constants import UserRole
|
|
|
|
|
|
if str(user_role).strip().upper() == UserRole.SUPER_ADMIN:
|
2026-02-27 11:48:33 +08:00
|
|
|
|
# 返回所有以 inbound_buy: 开头的权限码(这里我们返回一个特殊标记,表示全部)
|
|
|
|
|
|
# 为了简单,我们返回 ['inbound_buy:*'],在过滤函数中特殊处理
|
|
|
|
|
|
return ['inbound_buy:*']
|
2026-07-13 15:12:22 +08:00
|
|
|
|
perm_dict = AuthService.get_user_permissions(user_role, company_name=user_company)
|
2026-02-27 11:48:33 +08:00
|
|
|
|
# 合并菜单和元素权限
|
|
|
|
|
|
perms = perm_dict.get('menus', []) + perm_dict.get('elements', [])
|
|
|
|
|
|
return perms
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def filter_item_by_permissions(item_dict, user_permissions):
|
2026-07-17 13:07:12 +08:00
|
|
|
|
"""严格 Default Deny 字段过滤 (see app/utils/field_permissions.py)"""
|
|
|
|
|
|
from app.utils.field_permissions import apply_strict_rbac
|
|
|
|
|
|
return apply_strict_rbac(item_dict, 'StockBuy', user_permissions)
|
2026-02-27 11:48:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
2026-01-27 15:50:23 +08:00
|
|
|
|
# ------------------------------------------------------------------
|
2026-02-11 13:39:02 +08:00
|
|
|
|
# 0. 基础物料搜索
|
2026-01-27 15:50:23 +08:00
|
|
|
|
# ------------------------------------------------------------------
|
2026-01-28 11:22:08 +08:00
|
|
|
|
@inbound_buy_bp.route('/search-base', methods=['GET'])
|
2026-02-27 11:48:33 +08:00
|
|
|
|
@permission_required('inbound_buy')
|
2026-01-28 11:22:08 +08:00
|
|
|
|
def search_base():
|
2026-01-27 15:50:23 +08:00
|
|
|
|
try:
|
2026-01-28 11:22:08 +08:00
|
|
|
|
keyword = request.args.get('keyword', '')
|
2026-02-11 13:12:05 +08:00
|
|
|
|
page = request.args.get('page', 1, type=int)
|
|
|
|
|
|
# 固定每次加载50条
|
|
|
|
|
|
limit = 50
|
|
|
|
|
|
|
|
|
|
|
|
result = BuyInboundService.search_base_material(keyword, page, limit)
|
2026-02-11 08:38:12 +08:00
|
|
|
|
return jsonify({
|
|
|
|
|
|
"code": 200,
|
|
|
|
|
|
"msg": "success",
|
2026-02-11 13:12:05 +08:00
|
|
|
|
"data": result['items'],
|
|
|
|
|
|
"total": result['total'],
|
|
|
|
|
|
"has_next": result['has_next']
|
2026-02-11 08:38:12 +08:00
|
|
|
|
})
|
2026-01-27 15:50:23 +08:00
|
|
|
|
except Exception as e:
|
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
|
|
|
|
|
|
2026-02-11 08:38:12 +08:00
|
|
|
|
|
2026-01-28 11:22:08 +08:00
|
|
|
|
# ------------------------------------------------------------------
|
2026-03-02 15:39:32 +08:00
|
|
|
|
# 1. 获取列表 (修改:接收 category, material_type, orderByColumn, isAsc, advancedFilters)
|
2026-01-28 11:22:08 +08:00
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
|
@inbound_buy_bp.route('/list', methods=['GET'])
|
2026-02-27 11:48:33 +08:00
|
|
|
|
@permission_required('inbound_buy')
|
2026-01-28 11:22:08 +08:00
|
|
|
|
def get_list():
|
|
|
|
|
|
try:
|
|
|
|
|
|
page = request.args.get('page', 1, type=int)
|
|
|
|
|
|
limit = request.args.get('pageSize', 15, type=int)
|
2026-02-05 11:37:06 +08:00
|
|
|
|
keyword = request.args.get('keyword', '')
|
2026-03-09 17:29:24 +08:00
|
|
|
|
sku = request.args.get('sku', '')
|
2026-03-11 13:37:52 +08:00
|
|
|
|
search_field = request.args.get('searchField', 'all')
|
2026-02-11 08:38:12 +08:00
|
|
|
|
|
2026-02-11 13:39:02 +08:00
|
|
|
|
# 新增筛选参数
|
|
|
|
|
|
category = request.args.get('category', '')
|
|
|
|
|
|
material_type = request.args.get('material_type', '')
|
2026-02-27 15:58:55 +08:00
|
|
|
|
company = request.args.get('company', '')
|
2026-02-11 13:39:02 +08:00
|
|
|
|
|
2026-03-02 15:39:32 +08:00
|
|
|
|
# 排序参数
|
|
|
|
|
|
order_by = request.args.get('orderByColumn', '').strip()
|
|
|
|
|
|
is_asc = request.args.get('isAsc', '').strip()
|
|
|
|
|
|
|
|
|
|
|
|
# 高级筛选参数
|
|
|
|
|
|
advanced_filters_raw = request.args.get('advancedFilters', '[]')
|
|
|
|
|
|
import json
|
|
|
|
|
|
try:
|
|
|
|
|
|
advanced_filters = json.loads(advanced_filters_raw) if advanced_filters_raw else []
|
|
|
|
|
|
except json.JSONDecodeError:
|
|
|
|
|
|
advanced_filters = []
|
|
|
|
|
|
|
2026-02-11 13:39:02 +08:00
|
|
|
|
# 状态参数处理
|
2026-02-05 11:37:06 +08:00
|
|
|
|
statuses_str = request.args.get('statuses', '')
|
|
|
|
|
|
statuses = statuses_str.split(',') if statuses_str else []
|
|
|
|
|
|
|
2026-03-11 13:37:52 +08:00
|
|
|
|
result = BuyInboundService.get_list(page, limit, keyword, sku, search_field, statuses, category, material_type, company,
|
2026-03-02 15:39:32 +08:00
|
|
|
|
order_by, is_asc, advanced_filters)
|
2026-02-27 11:48:33 +08:00
|
|
|
|
# 字段级脱敏
|
|
|
|
|
|
user_permissions = get_current_user_permissions()
|
|
|
|
|
|
if result.get('items'):
|
|
|
|
|
|
result['items'] = [filter_item_by_permissions(item, user_permissions) for item in result['items']]
|
2026-01-28 11:22:08 +08:00
|
|
|
|
return jsonify({"code": 200, "msg": "success", "data": result})
|
|
|
|
|
|
except Exception as e:
|
2026-02-05 11:37:06 +08:00
|
|
|
|
traceback.print_exc()
|
2026-01-28 11:22:08 +08:00
|
|
|
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
2026-01-27 15:50:23 +08:00
|
|
|
|
|
2026-02-11 08:38:12 +08:00
|
|
|
|
|
2026-01-27 15:50:23 +08:00
|
|
|
|
# ------------------------------------------------------------------
|
2026-02-05 11:37:06 +08:00
|
|
|
|
# 2. 新增入库
|
2026-01-27 15:50:23 +08:00
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
|
@inbound_buy_bp.route('/submit', methods=['POST'])
|
2026-02-27 11:48:33 +08:00
|
|
|
|
@permission_required('inbound_buy:operation')
|
2026-03-10 17:16:57 +08:00
|
|
|
|
@audit_log(
|
|
|
|
|
|
module='采购入库',
|
|
|
|
|
|
action='新增',
|
|
|
|
|
|
get_target_name_fn=lambda: request.get_json().get('material_name') if request.get_json() else None
|
|
|
|
|
|
)
|
2026-01-27 15:50:23 +08:00
|
|
|
|
def submit():
|
|
|
|
|
|
try:
|
|
|
|
|
|
data = request.get_json()
|
|
|
|
|
|
if not data:
|
2026-01-28 11:22:08 +08:00
|
|
|
|
return jsonify({"code": 400, "msg": "No data"}), 400
|
2026-02-11 08:38:12 +08:00
|
|
|
|
|
2026-07-17 13:07:12 +08:00
|
|
|
|
# ★ 白名单模式:仅过滤价格敏感字段,其余全部放行
|
2026-02-27 15:03:44 +08:00
|
|
|
|
user_permissions = get_current_user_permissions()
|
|
|
|
|
|
if 'inbound_buy:*' not in user_permissions:
|
2026-07-17 13:07:12 +08:00
|
|
|
|
for field in ('unit_price', 'post_tax_unit_price', 'tax_rate', 'total_price',
|
|
|
|
|
|
'currency', 'exchange_rate'):
|
|
|
|
|
|
perm_code = f'inbound_buy:{field}'
|
|
|
|
|
|
if field in data and perm_code not in user_permissions:
|
2026-02-27 15:03:44 +08:00
|
|
|
|
data.pop(field, None)
|
|
|
|
|
|
|
2026-03-18 17:04:23 +08:00
|
|
|
|
# 库位必填校验(安全兜底)
|
|
|
|
|
|
location = data.get('warehouse_location', '').strip()
|
|
|
|
|
|
if not location:
|
|
|
|
|
|
return jsonify({"code": 400, "msg": "入库失败:库位为必填项,不能为空!"}), 400
|
|
|
|
|
|
|
2026-02-02 15:06:20 +08:00
|
|
|
|
new_stock = BuyInboundService.handle_inbound(data)
|
2026-02-11 08:38:12 +08:00
|
|
|
|
|
2026-07-16 11:26:05 +08:00
|
|
|
|
# ★ Fail-Closed: 入库成功响应剥离价格字段
|
|
|
|
|
|
resp = new_stock.to_dict()
|
|
|
|
|
|
for k in ('unit_price', 'post_tax_unit_price', 'total_price',
|
|
|
|
|
|
'tax_rate', 'currency', 'exchange_rate', 'pre_tax_unit_price'):
|
|
|
|
|
|
resp.pop(k, None)
|
|
|
|
|
|
|
2026-02-11 08:38:12 +08:00
|
|
|
|
return jsonify({
|
|
|
|
|
|
"code": 200,
|
|
|
|
|
|
"msg": "入库成功",
|
2026-07-16 11:26:05 +08:00
|
|
|
|
"data": resp
|
2026-02-11 08:38:12 +08:00
|
|
|
|
})
|
2026-01-27 15:50:23 +08:00
|
|
|
|
except Exception as e:
|
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
|
|
|
|
|
|
2026-02-11 08:38:12 +08:00
|
|
|
|
|
2026-01-27 15:50:23 +08:00
|
|
|
|
# ------------------------------------------------------------------
|
2026-01-28 11:22:08 +08:00
|
|
|
|
# 3. 更新入库
|
2026-01-27 15:50:23 +08:00
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
|
@inbound_buy_bp.route('/<int:id>', methods=['PUT'])
|
2026-02-27 11:48:33 +08:00
|
|
|
|
@permission_required('inbound_buy:operation')
|
2026-03-10 17:16:57 +08:00
|
|
|
|
@audit_log(
|
|
|
|
|
|
module='采购入库',
|
|
|
|
|
|
action='修改',
|
|
|
|
|
|
get_target_id_fn=lambda: request.view_args.get('id'),
|
|
|
|
|
|
get_target_name_fn=lambda: request.get_json().get('material_name') if request.get_json() else None
|
|
|
|
|
|
)
|
2026-01-27 15:50:23 +08:00
|
|
|
|
def update_buy(id):
|
|
|
|
|
|
try:
|
|
|
|
|
|
data = request.get_json()
|
2026-02-27 15:03:44 +08:00
|
|
|
|
# 数据清洗:移除用户没有权限的字段
|
|
|
|
|
|
user_permissions = get_current_user_permissions()
|
|
|
|
|
|
# 超级管理员不过滤
|
|
|
|
|
|
if 'inbound_buy:*' not in user_permissions:
|
|
|
|
|
|
field_to_perm = {
|
|
|
|
|
|
'id': 'inbound_buy:id',
|
|
|
|
|
|
'base_id': 'inbound_buy:base_id',
|
|
|
|
|
|
'global_print_id': 'inbound_buy:global_print_id',
|
|
|
|
|
|
'sku': 'inbound_buy:sku',
|
|
|
|
|
|
'barcode': 'inbound_buy:barcode',
|
|
|
|
|
|
'in_date': 'inbound_buy:in_date',
|
|
|
|
|
|
'serial_number': 'inbound_buy:serial_number',
|
|
|
|
|
|
'batch_number': 'inbound_buy:batch_number',
|
|
|
|
|
|
'status': 'inbound_buy:status',
|
|
|
|
|
|
'in_quantity': 'inbound_buy:in_quantity',
|
|
|
|
|
|
'stock_quantity': 'inbound_buy:stock_quantity',
|
|
|
|
|
|
'available_quantity': 'inbound_buy:available_quantity',
|
|
|
|
|
|
'inspection_status': 'inbound_buy:inspection_status',
|
|
|
|
|
|
'warehouse_location': 'inbound_buy:warehouse_location',
|
|
|
|
|
|
'unit_price': 'inbound_buy:unit_price',
|
2026-02-27 15:44:10 +08:00
|
|
|
|
'post_tax_unit_price': 'inbound_buy:post_tax_unit_price',
|
2026-02-27 15:03:44 +08:00
|
|
|
|
'tax_rate': 'inbound_buy:tax_rate',
|
|
|
|
|
|
'total_price': 'inbound_buy:total_price',
|
|
|
|
|
|
'currency': 'inbound_buy:currency',
|
|
|
|
|
|
'exchange_rate': 'inbound_buy:exchange_rate',
|
|
|
|
|
|
'supplier_name': 'inbound_buy:supplier_name',
|
|
|
|
|
|
'buyer_name': 'inbound_buy:buyer_name',
|
|
|
|
|
|
'buyer_email': 'inbound_buy:buyer_email',
|
|
|
|
|
|
'original_link': 'inbound_buy:original_link',
|
|
|
|
|
|
'detail_link': 'inbound_buy:detail_link',
|
|
|
|
|
|
'arrival_photo': 'inbound_buy:arrival_photo',
|
|
|
|
|
|
'inspection_report': 'inbound_buy:inspection_report',
|
|
|
|
|
|
'material_name': 'inbound_buy:material_name',
|
|
|
|
|
|
'spec_model': 'inbound_buy:spec_model',
|
|
|
|
|
|
'category': 'inbound_buy:category',
|
|
|
|
|
|
'unit': 'inbound_buy:unit',
|
|
|
|
|
|
'material_type': 'inbound_buy:material_type',
|
|
|
|
|
|
'company_name': 'inbound_buy:company_name',
|
|
|
|
|
|
}
|
|
|
|
|
|
# 复制一份,避免遍历时修改字典
|
|
|
|
|
|
for field in list(data.keys()):
|
|
|
|
|
|
perm_code = field_to_perm.get(field)
|
2026-07-17 16:57:46 +08:00
|
|
|
|
if not perm_code:
|
|
|
|
|
|
continue # 不在映射中的字段跳过(不参与权限过滤)
|
2026-04-14 15:09:15 +08:00
|
|
|
|
# 提取不带前缀的基础权限码(如 'serial_number')
|
|
|
|
|
|
base_perm_code = perm_code.split(':')[-1] if ':' in perm_code else perm_code
|
|
|
|
|
|
# 如果用户的权限列表中,既没有长格式,也没有短格式,才移除该字段
|
2026-07-17 16:57:46 +08:00
|
|
|
|
if perm_code not in user_permissions and base_perm_code not in user_permissions:
|
2026-02-27 15:03:44 +08:00
|
|
|
|
data.pop(field, None)
|
|
|
|
|
|
|
2026-01-27 15:50:23 +08:00
|
|
|
|
BuyInboundService.update_inbound(id, data)
|
|
|
|
|
|
return jsonify({"code": 200, "msg": "更新成功"})
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
|
|
|
|
|
|
2026-02-11 08:38:12 +08:00
|
|
|
|
|
2026-01-27 15:50:23 +08:00
|
|
|
|
# ------------------------------------------------------------------
|
2026-01-28 11:22:08 +08:00
|
|
|
|
# 4. 删除
|
2026-01-27 15:50:23 +08:00
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
|
@inbound_buy_bp.route('/<int:id>', methods=['DELETE'])
|
2026-02-27 11:48:33 +08:00
|
|
|
|
@permission_required('inbound_buy:operation')
|
2026-03-10 17:16:57 +08:00
|
|
|
|
@audit_log(
|
|
|
|
|
|
module='采购入库',
|
|
|
|
|
|
action='删除',
|
|
|
|
|
|
get_target_id_fn=lambda: request.view_args.get('id')
|
|
|
|
|
|
)
|
2026-01-27 15:50:23 +08:00
|
|
|
|
def delete_buy(id):
|
|
|
|
|
|
try:
|
2026-03-20 15:47:13 +08:00
|
|
|
|
material_name = BuyInboundService.delete_inbound(id)
|
|
|
|
|
|
return jsonify({"code": 200, "msg": "删除成功", "material_name": material_name})
|
2026-03-25 10:48:43 +08:00
|
|
|
|
except ValueError as ve:
|
|
|
|
|
|
# 捕获业务拦截的报错,返回友好的 msg
|
|
|
|
|
|
return jsonify({"code": 400, "msg": str(ve)})
|
2026-01-27 15:50:23 +08:00
|
|
|
|
except Exception as e:
|
2026-03-25 10:56:31 +08:00
|
|
|
|
import traceback
|
|
|
|
|
|
traceback.print_exc() # 在控制台打印真实错误堆栈
|
|
|
|
|
|
return jsonify({"code": 500, "msg": f"服务器内部错误详情: {str(e)}"}), 500
|
2026-02-05 11:37:06 +08:00
|
|
|
|
|
2026-02-11 08:38:12 +08:00
|
|
|
|
|
2026-02-10 13:51:19 +08:00
|
|
|
|
# ------------------------------------------------------------------
|
2026-02-11 13:39:02 +08:00
|
|
|
|
# 5. [新增] 获取筛选下拉选项 (修复404的关键)
|
|
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
|
@inbound_buy_bp.route('/options', methods=['GET'])
|
2026-02-27 11:48:33 +08:00
|
|
|
|
@permission_required('inbound_buy')
|
2026-02-11 13:39:02 +08:00
|
|
|
|
def get_options():
|
|
|
|
|
|
try:
|
|
|
|
|
|
data = BuyInboundService.get_filter_options()
|
|
|
|
|
|
return jsonify({"code": 200, "msg": "success", "data": data})
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
|
# 6. 获取关联的出库历史 (如果有)
|
2026-02-11 08:38:12 +08:00
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
|
@inbound_buy_bp.route('/<int:id>/history', methods=['GET'])
|
2026-02-27 11:48:33 +08:00
|
|
|
|
@permission_required('inbound_buy')
|
2026-02-11 08:38:12 +08:00
|
|
|
|
def get_history(id):
|
|
|
|
|
|
# 如果没有出库模块,这个接口可能为空,但为保持兼容性保留
|
|
|
|
|
|
return jsonify({"code": 200, "msg": "success", "data": []})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------
|
2026-02-11 13:39:02 +08:00
|
|
|
|
# 7. 供应商建议
|
2026-02-10 13:51:19 +08:00
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
|
@inbound_buy_bp.route('/suggestions/suppliers', methods=['GET'])
|
2026-02-27 11:48:33 +08:00
|
|
|
|
@permission_required('inbound_buy')
|
2026-02-10 13:51:19 +08:00
|
|
|
|
def get_supplier_suggestions():
|
|
|
|
|
|
base_id = request.args.get('base_id', type=int)
|
|
|
|
|
|
if not base_id:
|
|
|
|
|
|
return jsonify({"code": 400, "msg": "base_id required"}), 400
|
|
|
|
|
|
data = BuyInboundService.get_history_suppliers(base_id)
|
|
|
|
|
|
return jsonify({"code": 200, "msg": "success", "data": data})
|
|
|
|
|
|
|
2026-02-11 08:38:12 +08:00
|
|
|
|
|
2026-02-10 13:51:19 +08:00
|
|
|
|
# ------------------------------------------------------------------
|
2026-02-11 13:39:02 +08:00
|
|
|
|
# 8. 采购人建议 (全局)
|
2026-02-10 13:51:19 +08:00
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
|
@inbound_buy_bp.route('/suggestions/users', methods=['GET'])
|
2026-02-27 11:48:33 +08:00
|
|
|
|
@permission_required('inbound_buy')
|
2026-02-10 13:51:19 +08:00
|
|
|
|
def get_user_suggestions():
|
|
|
|
|
|
keyword = request.args.get('keyword', '')
|
2026-02-10 17:41:53 +08:00
|
|
|
|
data = BuyInboundService.get_history_purchasers(keyword)
|
2026-02-10 13:51:19 +08:00
|
|
|
|
return jsonify({"code": 200, "msg": "success", "data": data})
|
2026-02-10 17:20:06 +08:00
|
|
|
|
|
2026-02-11 13:12:05 +08:00
|
|
|
|
|
2026-02-10 17:20:06 +08:00
|
|
|
|
# ------------------------------------------------------------------
|
2026-02-11 13:39:02 +08:00
|
|
|
|
# 9. 链接建议
|
2026-02-10 17:20:06 +08:00
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
|
@inbound_buy_bp.route('/suggestions/links', methods=['GET'])
|
2026-02-27 11:48:33 +08:00
|
|
|
|
@permission_required('inbound_buy')
|
2026-02-10 17:20:06 +08:00
|
|
|
|
def get_link_suggestions():
|
|
|
|
|
|
base_id = request.args.get('base_id', type=int)
|
2026-02-11 13:12:05 +08:00
|
|
|
|
link_type = request.args.get('type', 'original') # original or detail
|
2026-02-10 17:20:06 +08:00
|
|
|
|
if not base_id:
|
|
|
|
|
|
return jsonify({"code": 400, "msg": "base_id required"}), 400
|
|
|
|
|
|
data = BuyInboundService.get_history_links(base_id, link_type)
|
2026-02-11 08:38:12 +08:00
|
|
|
|
return jsonify({"code": 200, "msg": "success", "data": data})
|
|
|
|
|
|
|
2026-02-11 13:12:05 +08:00
|
|
|
|
|
2026-02-11 08:38:12 +08:00
|
|
|
|
# ------------------------------------------------------------------
|
2026-02-11 13:39:02 +08:00
|
|
|
|
# 10. 库位建议
|
2026-02-11 08:38:12 +08:00
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
|
@inbound_buy_bp.route('/suggestions/locations', methods=['GET'])
|
2026-02-27 11:48:33 +08:00
|
|
|
|
@permission_required('inbound_buy')
|
2026-02-11 08:38:12 +08:00
|
|
|
|
def get_location_suggestions():
|
|
|
|
|
|
base_id = request.args.get('base_id', type=int)
|
|
|
|
|
|
if not base_id:
|
|
|
|
|
|
return jsonify({"code": 400, "msg": "base_id required"}), 400
|
|
|
|
|
|
data = BuyInboundService.get_history_locations(base_id)
|
2026-02-27 11:48:33 +08:00
|
|
|
|
return jsonify({"code": 200, "msg": "success", "data": data})
|
2026-04-08 17:32:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
|
# 11. 获取最近一次入库的库位(跨表查询)
|
|
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
|
@inbound_buy_bp.route('/last-location', methods=['GET'])
|
|
|
|
|
|
@permission_required('inbound_buy')
|
|
|
|
|
|
def get_last_location():
|
|
|
|
|
|
"""
|
|
|
|
|
|
获取指定物料最近一次入库的库位
|
|
|
|
|
|
查询顺序:采购入库 -> 成品入库 -> 半成品入库,返回最新入库的库位
|
|
|
|
|
|
"""
|
|
|
|
|
|
base_id = request.args.get('base_id', type=int)
|
|
|
|
|
|
if not base_id:
|
|
|
|
|
|
return jsonify({"code": 400, "msg": "base_id required"}), 400
|
|
|
|
|
|
|
|
|
|
|
|
location = BuyInboundService.get_last_location_by_base_id(base_id)
|
|
|
|
|
|
return jsonify({"code": 200, "msg": "success", "data": {"location": location}})
|