成品入库与出库相关联
This commit is contained in:
@ -19,7 +19,7 @@ def search_base():
|
|||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# 1. 获取列表
|
# 1. 获取列表 (修改:支持状态筛选)
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
@inbound_product_bp.route('/list', methods=['GET'])
|
@inbound_product_bp.route('/list', methods=['GET'])
|
||||||
def get_list():
|
def get_list():
|
||||||
@ -27,14 +27,19 @@ 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', '')
|
||||||
result = ProductInboundService.get_list(page, limit, keyword)
|
|
||||||
|
# 获取状态列表参数
|
||||||
|
statuses_str = request.args.get('statuses', '')
|
||||||
|
statuses = statuses_str.split(',') if statuses_str else []
|
||||||
|
|
||||||
|
result = ProductInboundService.get_list(page, limit, keyword, statuses)
|
||||||
return jsonify({"code": 200, "msg": "success", "data": result})
|
return jsonify({"code": 200, "msg": "success", "data": result})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# 2. 新增入库 (修改:返回创建的对象数据,用于打印)
|
# 2. 新增入库
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
@inbound_product_bp.route('/submit', methods=['POST'])
|
@inbound_product_bp.route('/submit', methods=['POST'])
|
||||||
def submit():
|
def submit():
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.models.base import MaterialBase
|
from app.models.base import MaterialBase
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from sqlalchemy import or_, func, text
|
from sqlalchemy import or_, func, text, and_ # Added and_
|
||||||
import traceback
|
import traceback
|
||||||
import json
|
import json
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ class ProductInboundService:
|
|||||||
barcode=final_barcode,
|
barcode=final_barcode,
|
||||||
serial_number=data.get('serial_number'),
|
serial_number=data.get('serial_number'),
|
||||||
|
|
||||||
status='在库',
|
status=data.get('status', '在库'),
|
||||||
warehouse_location=data.get('warehouse_location'),
|
warehouse_location=data.get('warehouse_location'),
|
||||||
|
|
||||||
in_quantity=in_qty,
|
in_quantity=in_qty,
|
||||||
@ -154,9 +154,8 @@ class ProductInboundService:
|
|||||||
|
|
||||||
if 'in_quantity' in data:
|
if 'in_quantity' in data:
|
||||||
new_qty = float(data['in_quantity'])
|
new_qty = float(data['in_quantity'])
|
||||||
old_qty = float(stock.in_quantity)
|
diff = new_qty - float(stock.in_quantity)
|
||||||
if new_qty != old_qty:
|
if diff != 0:
|
||||||
diff = new_qty - old_qty
|
|
||||||
stock.in_quantity = new_qty
|
stock.in_quantity = new_qty
|
||||||
stock.stock_quantity = float(stock.stock_quantity) + diff
|
stock.stock_quantity = float(stock.stock_quantity) + diff
|
||||||
stock.available_quantity = float(stock.available_quantity) + diff
|
stock.available_quantity = float(stock.available_quantity) + diff
|
||||||
@ -190,11 +189,12 @@ class ProductInboundService:
|
|||||||
raise e
|
raise e
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_list(page, limit, keyword=None):
|
def get_list(page, limit, keyword=None, statuses=None):
|
||||||
from app.models.inbound.product import StockProduct
|
from app.models.inbound.product import StockProduct
|
||||||
try:
|
try:
|
||||||
query = db.session.query(StockProduct).outerjoin(MaterialBase, StockProduct.base_id == MaterialBase.id)
|
query = db.session.query(StockProduct).outerjoin(MaterialBase, StockProduct.base_id == MaterialBase.id)
|
||||||
|
|
||||||
|
# 1. 关键词搜索
|
||||||
if keyword:
|
if keyword:
|
||||||
query = query.filter(or_(
|
query = query.filter(or_(
|
||||||
MaterialBase.name.ilike(f'%{keyword}%'),
|
MaterialBase.name.ilike(f'%{keyword}%'),
|
||||||
@ -205,26 +205,55 @@ class ProductInboundService:
|
|||||||
StockProduct.sku.ilike(f'%{keyword}%')
|
StockProduct.sku.ilike(f'%{keyword}%')
|
||||||
))
|
))
|
||||||
|
|
||||||
|
# 2. 状态筛选与零库存隐藏逻辑
|
||||||
|
if not statuses:
|
||||||
|
statuses = ['在库', '借库']
|
||||||
|
|
||||||
|
# 如果筛选包含'已出库',则显示所有数量;否则隐藏 stock_quantity <= 0 的记录
|
||||||
|
if '已出库' in statuses:
|
||||||
|
query = query.filter(StockProduct.status.in_(statuses))
|
||||||
|
else:
|
||||||
|
query = query.filter(
|
||||||
|
and_(
|
||||||
|
StockProduct.status.in_(statuses),
|
||||||
|
StockProduct.stock_quantity > 0
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
pagination = query.order_by(StockProduct.id.desc()).paginate(page=page, per_page=limit, error_out=False)
|
pagination = query.order_by(StockProduct.id.desc()).paginate(page=page, per_page=limit, error_out=False)
|
||||||
|
|
||||||
|
# 3. 数据组装 (移除聚合逻辑,改为单行数据)
|
||||||
current_items = pagination.items
|
current_items = pagination.items
|
||||||
base_ids = list(set([i.base_id for i in current_items]))
|
|
||||||
stock_map = {}
|
# 移除聚合查询代码...
|
||||||
if base_ids:
|
|
||||||
aggs = db.session.query(
|
def parse_img(json_str):
|
||||||
StockProduct.base_id,
|
if not json_str: return []
|
||||||
func.sum(StockProduct.stock_quantity).label('s'),
|
try:
|
||||||
func.sum(StockProduct.available_quantity).label('a')
|
return json.loads(json_str) if json_str.startswith('[') else [json_str]
|
||||||
).filter(StockProduct.base_id.in_(base_ids)).group_by(StockProduct.base_id).all()
|
except:
|
||||||
for a in aggs:
|
return []
|
||||||
stock_map[a.base_id] = {'s': float(a.s or 0), 'a': float(a.a or 0)}
|
|
||||||
|
|
||||||
items = []
|
items = []
|
||||||
for item in current_items:
|
for item in current_items:
|
||||||
d = item.to_dict()
|
d = item.to_dict()
|
||||||
stats = stock_map.get(item.base_id, {'s': 0, 'a': 0})
|
|
||||||
d['sum_stock'] = stats['s']
|
# 直接使用当前行的库存,不再聚合
|
||||||
d['sum_available'] = stats['a']
|
d['qty_stock'] = float(item.stock_quantity or 0)
|
||||||
|
d['qty_available'] = float(item.available_quantity or 0)
|
||||||
|
|
||||||
|
# 兼容前端字段 key
|
||||||
|
d['sum_stock'] = d['qty_stock']
|
||||||
|
d['sum_available'] = d['qty_available']
|
||||||
|
|
||||||
|
# 图片/链接解析
|
||||||
|
d['product_photo'] = parse_img(item.product_photo)
|
||||||
|
d['quality_report_link'] = parse_img(item.quality_report_link)
|
||||||
|
d['inspection_report_link'] = parse_img(item.inspection_report_link)
|
||||||
|
|
||||||
|
# 打印ID
|
||||||
|
d['global_print_id'] = item.global_print_id
|
||||||
|
|
||||||
items.append(d)
|
items.append(d)
|
||||||
|
|
||||||
return {"total": pagination.total, "items": items}
|
return {"total": pagination.total, "items": items}
|
||||||
|
|||||||
@ -2,10 +2,32 @@
|
|||||||
<div class="product-module">
|
<div class="product-module">
|
||||||
<div class="header-tools">
|
<div class="header-tools">
|
||||||
<div class="left-tools">
|
<div class="left-tools">
|
||||||
<el-input v-model="queryParams.keyword" placeholder="🔍 搜索物料 / SN / 工单 / 订单号..." class="search-input" clearable @clear="fetchData" @keyup.enter="fetchData">
|
<el-input
|
||||||
|
v-model="queryParams.keyword"
|
||||||
|
placeholder="🔍 搜索物料 / SN / 工单 / 订单号..."
|
||||||
|
class="search-input"
|
||||||
|
clearable
|
||||||
|
@clear="fetchData"
|
||||||
|
@keyup.enter="fetchData"
|
||||||
|
style="width: 300px; margin-right: 10px;"
|
||||||
|
>
|
||||||
<template #append><el-button :icon="Search" @click="fetchData" /></template>
|
<template #append><el-button :icon="Search" @click="fetchData" /></template>
|
||||||
</el-input>
|
</el-input>
|
||||||
|
|
||||||
|
<el-select
|
||||||
|
v-model="queryParams.statuses"
|
||||||
|
multiple
|
||||||
|
collapse-tags
|
||||||
|
placeholder="状态筛选"
|
||||||
|
style="width: 220px;"
|
||||||
|
@change="fetchData"
|
||||||
|
>
|
||||||
|
<el-option label="在库" value="在库" />
|
||||||
|
<el-option label="借库" value="借库" />
|
||||||
|
<el-option label="已出库" value="已出库" />
|
||||||
|
</el-select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="right-tools">
|
<div class="right-tools">
|
||||||
<el-button type="primary" :icon="Plus" @click="handleCreate" class="action-btn">成品入库登记</el-button>
|
<el-button type="primary" :icon="Plus" @click="handleCreate" class="action-btn">成品入库登记</el-button>
|
||||||
<el-button :icon="Refresh" @click="fetchData" class="action-btn">刷新</el-button>
|
<el-button :icon="Refresh" @click="fetchData" class="action-btn">刷新</el-button>
|
||||||
@ -45,12 +67,15 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #default="scope" v-else-if="['serial_number'].includes(col.prop)">
|
<template #default="scope" v-else-if="['serial_number'].includes(col.prop)">
|
||||||
<span v-if="scope.row[col.prop]" class="tag-sn">{{ scope.row[col.prop] }}</span>
|
<div v-if="scope.row.serial_number" class="id-cell">
|
||||||
|
<span class="prefix-tag sn">SN</span>
|
||||||
|
<span class="id-text">{{ scope.row.serial_number }}</span>
|
||||||
|
</div>
|
||||||
<span v-else class="text-placeholder">-</span>
|
<span v-else class="text-placeholder">-</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #default="scope" v-else-if="col.prop === 'qty_stock'">
|
<template #default="scope" v-else-if="col.prop === 'qty_stock'">
|
||||||
<span class="stock-num">{{ scope.row.sum_stock }}</span><el-tag size="small" type="info" effect="plain" class="sum-tag">总</el-tag>
|
<span class="stock-num">{{ scope.row.qty_stock }}</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #default="scope" v-else-if="col.prop === 'status'">
|
<template #default="scope" v-else-if="col.prop === 'status'">
|
||||||
@ -184,6 +209,17 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-row :gutter="24" style="margin-top:15px">
|
<el-row :gutter="24" style="margin-top:15px">
|
||||||
|
<template v-if="dialogStatus === 'update'">
|
||||||
|
<el-col :span="6">
|
||||||
|
<el-form-item label="库存状态" prop="status">
|
||||||
|
<el-select v-model="form.status" style="width:100%">
|
||||||
|
<el-option label="在库" value="在库"/>
|
||||||
|
<el-option label="借库" value="借库"/>
|
||||||
|
<el-option label="已出库" value="已出库"/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
</template>
|
||||||
<el-col :span="6">
|
<el-col :span="6">
|
||||||
<el-form-item label="质量状态">
|
<el-form-item label="质量状态">
|
||||||
<el-select v-model="form.quality_status" style="width:100%">
|
<el-select v-model="form.quality_status" style="width:100%">
|
||||||
@ -191,7 +227,7 @@
|
|||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="18">
|
<el-col :span="dialogStatus === 'update' ? 12 : 18">
|
||||||
<el-form-item label="成品实拍" prop="product_photo">
|
<el-form-item label="成品实拍" prop="product_photo">
|
||||||
<div class="upload-container">
|
<div class="upload-container">
|
||||||
<el-upload
|
<el-upload
|
||||||
@ -367,7 +403,12 @@ const dialogStatus = ref<'create' | 'update'>('create')
|
|||||||
const tableData = ref([])
|
const tableData = ref([])
|
||||||
const total = ref(0)
|
const total = ref(0)
|
||||||
const formRef = ref()
|
const formRef = ref()
|
||||||
const queryParams = reactive({ page: 1, pageSize: 15, keyword: '' })
|
const queryParams = reactive({
|
||||||
|
page: 1,
|
||||||
|
pageSize: 15,
|
||||||
|
keyword: '',
|
||||||
|
statuses: ['在库', '借库']
|
||||||
|
})
|
||||||
const materialOptions = ref<any[]>([])
|
const materialOptions = ref<any[]>([])
|
||||||
|
|
||||||
// 打印相关变量
|
// 打印相关变量
|
||||||
@ -420,7 +461,7 @@ const defaultVisibleCols = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
// 表头持久化
|
// 表头持久化
|
||||||
const STORAGE_KEY = 'stock_product_visible_columns'
|
const STORAGE_KEY = 'stock_product_visible_columns_v2' // Changed key
|
||||||
const getSavedColumns = () => {
|
const getSavedColumns = () => {
|
||||||
try {
|
try {
|
||||||
const saved = localStorage.getItem(STORAGE_KEY)
|
const saved = localStorage.getItem(STORAGE_KEY)
|
||||||
@ -467,7 +508,17 @@ const mixedSearch = (qs: string, tableField: string, storageKey: string, cb: any
|
|||||||
const querySearchManager = (qs: string, cb: any) => mixedSearch(qs, 'production_manager', HISTORY_KEYS.PRODUCTION_MANAGER, cb)
|
const querySearchManager = (qs: string, cb: any) => mixedSearch(qs, 'production_manager', HISTORY_KEYS.PRODUCTION_MANAGER, cb)
|
||||||
const handleManagerSelect = (item: any) => saveToHistory(HISTORY_KEYS.PRODUCTION_MANAGER, item.value)
|
const handleManagerSelect = (item: any) => saveToHistory(HISTORY_KEYS.PRODUCTION_MANAGER, item.value)
|
||||||
|
|
||||||
const fetchData = async () => { loading.value = true; try { const res: any = await getProductList(queryParams); tableData.value = res.data.items || []; total.value = res.data.total || 0 } finally { loading.value = false } }
|
const fetchData = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
const params = { ...queryParams, statuses: queryParams.statuses.join(',') }
|
||||||
|
const res: any = await getProductList(params);
|
||||||
|
tableData.value = res.data.items || [];
|
||||||
|
total.value = res.data.total || 0
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleMaterialDropdownVisible = (visible: boolean) => { if (visible && materialOptions.value.length === 0) handleSearchMaterial('') }
|
const handleMaterialDropdownVisible = (visible: boolean) => { if (visible && materialOptions.value.length === 0) handleSearchMaterial('') }
|
||||||
const handleSearchMaterial = async (query: string) => { searchLoading.value = true; try { const res: any = await searchMaterialBase(query); const apiResults = (res.data || []).map((i: any) => ({ ...i, isHistory: false })); if (!query) { const history = getMaterialHistory(); const historyIds = new Set(history.map((h: any) => h.id)); const filteredApi = apiResults.filter((apiItem: any) => !historyIds.has(apiItem.id)); materialOptions.value = [...history, ...filteredApi] } else { materialOptions.value = apiResults } } finally { searchLoading.value = false } }
|
const handleSearchMaterial = async (query: string) => { searchLoading.value = true; try { const res: any = await searchMaterialBase(query); const apiResults = (res.data || []).map((i: any) => ({ ...i, isHistory: false })); if (!query) { const history = getMaterialHistory(); const historyIds = new Set(history.map((h: any) => h.id)); const filteredApi = apiResults.filter((apiItem: any) => !historyIds.has(apiItem.id)); materialOptions.value = [...history, ...filteredApi] } else { materialOptions.value = apiResults } } finally { searchLoading.value = false } }
|
||||||
@ -633,7 +684,7 @@ const resetForm = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const getStatusType = (s:string) => ({'在库':'success','出库':'info','损耗':'danger'}[s]||'warning')
|
const getStatusType = (s:string) => ({'在库':'success','出库':'info','借库':'warning','损耗':'danger'}[s]||'warning')
|
||||||
const getQualityType = (s:string) => ({'合格':'success','不合格':'danger','待检':'info'}[s]||'info')
|
const getQualityType = (s:string) => ({'合格':'success','不合格':'danger','待检':'info'}[s]||'info')
|
||||||
const formatMoney = (val:any) => isNaN(Number(val)) ? '-' : `¥ ${Number(val).toFixed(2)}`
|
const formatMoney = (val:any) => isNaN(Number(val)) ? '-' : `¥ ${Number(val).toFixed(2)}`
|
||||||
onMounted(() => fetchData())
|
onMounted(() => fetchData())
|
||||||
@ -641,7 +692,9 @@ onMounted(() => fetchData())
|
|||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.product-module { background: #f5f7fa; padding: 20px; min-height: 100vh; }
|
.product-module { background: #f5f7fa; padding: 20px; min-height: 100vh; }
|
||||||
.header-tools { display: flex; justify-content: space-between; margin-bottom: 20px; background: #fff; padding: 15px; border-radius: 8px; box-shadow: 0 2px 12px 0 rgba(0,0,0,0.05); }
|
.header-tools { display: flex; justify-content: space-between; margin-bottom: 20px; background: #fff; padding: 15px 20px; border-radius: 8px; box-shadow: 0 2px 12px 0 rgba(0,0,0,0.05); }
|
||||||
|
.left-tools { display: flex; gap: 10px; align-items: center; flex: 1; }
|
||||||
|
.right-tools { display: flex; gap: 10px; align-items: center; }
|
||||||
.modern-table { border-radius: 8px; box-shadow: 0 2px 12px 0 rgba(0,0,0,0.05); }
|
.modern-table { border-radius: 8px; box-shadow: 0 2px 12px 0 rgba(0,0,0,0.05); }
|
||||||
:deep(.table-header-gray th) { background-color: #f8f9fb !important; color: #606266; }
|
:deep(.table-header-gray th) { background-color: #f8f9fb !important; color: #606266; }
|
||||||
.tag-sn { color: #409EFF; font-weight: bold; font-family: monospace; }
|
.tag-sn { color: #409EFF; font-weight: bold; font-family: monospace; }
|
||||||
@ -668,6 +721,8 @@ onMounted(() => fetchData())
|
|||||||
.empty-preview { color: #909399; }
|
.empty-preview { color: #909399; }
|
||||||
.more-images-badge { margin-left: 5px; background: #909399; color: #fff; border-radius: 10px; padding: 0 6px; font-size: 12px; }
|
.more-images-badge { margin-left: 5px; background: #909399; color: #fff; border-radius: 10px; padding: 0 6px; font-size: 12px; }
|
||||||
.clickable-text { color: #409EFF; cursor: pointer; font-weight: 500; text-decoration: underline; }
|
.clickable-text { color: #409EFF; cursor: pointer; font-weight: 500; text-decoration: underline; }
|
||||||
|
.id-cell { display: flex; align-items: center; }
|
||||||
|
.id-text { font-family: monospace; color: #606266; }
|
||||||
|
|
||||||
.upload-container { display: flex; flex-wrap: wrap; gap: 8px; }
|
.upload-container { display: flex; flex-wrap: wrap; gap: 8px; }
|
||||||
:deep(.el-upload--picture-card) { width: 100px; height: 100px; line-height: 100px; }
|
:deep(.el-upload--picture-card) { width: 100px; height: 100px; line-height: 100px; }
|
||||||
|
|||||||
Reference in New Issue
Block a user