fix: fix BOM parents SQL error and remove unused add children button
Co-authored-by: aider (openai/DeepSeek-V3.2-Thinking) <aider@aider.chat>
This commit is contained in:
@ -63,7 +63,7 @@ def get_material_base_list():
|
|||||||
def get_bom_parents():
|
def get_bom_parents():
|
||||||
"""获取所有已定义BOM的父件物料列表"""
|
"""获取所有已定义BOM的父件物料列表"""
|
||||||
try:
|
try:
|
||||||
subq = db.session.query(distinct(BomTable.parent_id)).subquery()
|
subq = db.session.query(BomTable.parent_id).distinct().subquery()
|
||||||
parents = MaterialBase.query.join(subq, MaterialBase.id == subq.c.parent_id).all()
|
parents = MaterialBase.query.join(subq, MaterialBase.id == subq.c.parent_id).all()
|
||||||
data = [item.to_dict() for item in parents]
|
data = [item.to_dict() for item in parents]
|
||||||
return jsonify({
|
return jsonify({
|
||||||
|
|||||||
@ -35,19 +35,11 @@
|
|||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
<el-row :gutter="20" style="margin-top:15px">
|
<el-row :gutter="20" style="margin-top:15px">
|
||||||
<el-col :span="12">
|
<el-col :span="24">
|
||||||
<el-select v-model="selectedParentId" placeholder="选择 BOM 表" filterable style="width:100%" @change="onBomParentChange">
|
<el-select v-model="selectedParentId" placeholder="选择 BOM 表" filterable style="width:100%" @change="onBomParentChange">
|
||||||
<el-option v-for="item in bomParents" :key="item.id" :label="item.name" :value="item.id" />
|
<el-option v-for="item in bomParents" :key="item.id" :label="item.name" :value="item.id" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="12" style="text-align:right">
|
|
||||||
<el-tooltip
|
|
||||||
content="将 BOM 子件对应的库存物料添加到出库选单,用于后续拣货出库"
|
|
||||||
placement="top"
|
|
||||||
>
|
|
||||||
<el-button type="primary" plain @click="addChildrenToSelection">添加子件到出库选单</el-button>
|
|
||||||
</el-tooltip>
|
|
||||||
</el-col>
|
|
||||||
</el-row>
|
</el-row>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -431,39 +423,6 @@ const onBomParentChange = async (val: number) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加 BOM 子件到出库选单
|
|
||||||
* 作用:根据当前选定的 BOM 父件,获取其子件列表,然后根据子件的 child_id 在库存中查找匹配的库存项,
|
|
||||||
* 并将它们添加到出库选单(selectedItems)中,添加的数量受子件所需个数(dosage)的限制。
|
|
||||||
* 每个子件会尝试添加 dosage 个库存项(每个库存项代表一个实物单位),若库存项不足则按实际数量添加。
|
|
||||||
*/
|
|
||||||
const addChildrenToSelection = () => {
|
|
||||||
if (bomChildren.value.length === 0) {
|
|
||||||
ElMessage.warning('当前没有可添加的子件')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
let addedCount = 0
|
|
||||||
for (const child of bomChildren.value) {
|
|
||||||
// 寻找匹配的库存项 (根据 base_id)
|
|
||||||
const matchingItems = allStockData.value.filter(item => item.base_id == child.child_id)
|
|
||||||
if (matchingItems.length > 0) {
|
|
||||||
const existingIds = selectedItems.value.map(s => s.id)
|
|
||||||
// 最多添加 dosage 个 (简单起见每个匹配项添加一个)
|
|
||||||
for (let i = 0; i < Math.min(child.dosage, matchingItems.length); i++) {
|
|
||||||
const stock = matchingItems[i]
|
|
||||||
if (!existingIds.includes(stock.id)) {
|
|
||||||
selectedItems.value.push(stock)
|
|
||||||
addedCount++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ElMessage.warning(`物料 ${child.child_name} 暂无库存`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (addedCount > 0) {
|
|
||||||
ElMessage.success(`已添加 ${addedCount} 个子件到选单`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
fetchData()
|
fetchData()
|
||||||
|
|||||||
Reference in New Issue
Block a user