|
|
@@ -849,7 +849,13 @@
|
|
|
// 获取物品列表
|
|
|
async getListItems() {
|
|
|
const { data } = await getTreeByGroup({});
|
|
|
- this.goodsLists = data;
|
|
|
+ const seen = new Set();
|
|
|
+ this.goodsLists = data.filter((item) => {
|
|
|
+ const key = String(item.id);
|
|
|
+ if (seen.has(key)) return false;
|
|
|
+ seen.add(key);
|
|
|
+ return true;
|
|
|
+ });
|
|
|
},
|
|
|
// 打开单据来源弹窗
|
|
|
openDocumentSourceDialog() {
|
|
|
@@ -1159,6 +1165,11 @@
|
|
|
console.log(res, 'makerId');
|
|
|
this.$set(this.formData.extInfo, 'verifyDeptCode', res.groupId);
|
|
|
this.$set(this.formData.extInfo, 'verifyDeptName', res.groupName);
|
|
|
+ if (this.bizType == 10) {
|
|
|
+ this.formData.fromId = this.form.makerId;
|
|
|
+ this.formData.fromUser = this.form.makerName;
|
|
|
+ if (res.groupId) this.getStaffList({ id: res.groupId });
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -1298,8 +1309,117 @@
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
- //采购退货按收货明细选择不良库存,不使用普通物品先进先出预填。
|
|
|
+ // 普通采购退货按收货明细查实际批次,退货单的空批次不能直接用于先进先出查询。
|
|
|
if (this.bizType == 10) {
|
|
|
+ const returnProducts = (this.form.productList || []).filter(
|
|
|
+ (item) => !(item.packageSources || []).length
|
|
|
+ );
|
|
|
+ if (returnProducts.length) {
|
|
|
+ try {
|
|
|
+ const receiveProductIds = returnProducts.map(
|
|
|
+ (item) => item.receiveProductId
|
|
|
+ );
|
|
|
+ if (!this.form.receiveNo || receiveProductIds.some((id) => !id)) {
|
|
|
+ throw new Error('采购退货缺少收货单号或收货明细');
|
|
|
+ }
|
|
|
+ const rows = [];
|
|
|
+ let pageNum = 1;
|
|
|
+ let page;
|
|
|
+ do {
|
|
|
+ page = await storageApi.getBatchList({
|
|
|
+ sourceBizNo: this.form.receiveNo,
|
|
|
+ sourceReceiveProductIds: [...new Set(receiveProductIds)].join(
|
|
|
+ ','
|
|
|
+ ),
|
|
|
+ pageNum,
|
|
|
+ size: 100
|
|
|
+ });
|
|
|
+ rows.push(...(page.list || []));
|
|
|
+ pageNum++;
|
|
|
+ } while (page.list?.length && rows.length < page.count);
|
|
|
+
|
|
|
+ const remaining = new Map(
|
|
|
+ rows.map((row) => [
|
|
|
+ String(row.stockBatchId),
|
|
|
+ Math.max(
|
|
|
+ 0,
|
|
|
+ Number(row.availableCountBase || 0) -
|
|
|
+ Number(row.lockQuantity || 0)
|
|
|
+ )
|
|
|
+ ])
|
|
|
+ );
|
|
|
+ const builders = [];
|
|
|
+ for (const product of returnProducts) {
|
|
|
+ let needed = Number(product.totalCount);
|
|
|
+ if (!(needed > 0)) {
|
|
|
+ throw new Error('采购退货数量无效');
|
|
|
+ }
|
|
|
+ for (const row of rows) {
|
|
|
+ if (
|
|
|
+ !this.$refs.assetsDialogRef.matchesReturnProduct(
|
|
|
+ product,
|
|
|
+ row
|
|
|
+ )
|
|
|
+ ) continue;
|
|
|
+ const available = remaining.get(String(row.stockBatchId)) || 0;
|
|
|
+ const num = Math.min(needed, available);
|
|
|
+ if (!(num > 0)) continue;
|
|
|
+ builders.push({
|
|
|
+ id: row.id,
|
|
|
+ categoryId: row.categoryId,
|
|
|
+ warehouseId: row.warehouseId,
|
|
|
+ batchNo: row.batchNo,
|
|
|
+ systemBatchNo: row.systemBatchNo || '',
|
|
|
+ num
|
|
|
+ });
|
|
|
+ remaining.set(String(row.stockBatchId), available - num);
|
|
|
+ needed = Number((needed - num).toFixed(4));
|
|
|
+ if (!needed) break;
|
|
|
+ }
|
|
|
+ if (needed > 0) {
|
|
|
+ throw new Error(
|
|
|
+ `采购退货物品 ${product.productId} 的来源批次库存不足`
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const details = await storageApi.getHierarchyFifo({
|
|
|
+ type: 2,
|
|
|
+ builders
|
|
|
+ });
|
|
|
+ const requested = builders.map((item) => ({ ...item }));
|
|
|
+ for (const detail of details || []) {
|
|
|
+ const builder = requested.find(
|
|
|
+ (item) =>
|
|
|
+ String(item.id) === String(detail.id) &&
|
|
|
+ item.batchNo === detail.batchNo &&
|
|
|
+ item.systemBatchNo === (detail.systemBatchNo || '')
|
|
|
+ );
|
|
|
+ const matchingProducts = returnProducts.filter((item) =>
|
|
|
+ this.$refs.assetsDialogRef.matchesReturnProduct(item, detail)
|
|
|
+ );
|
|
|
+ if (
|
|
|
+ !builder ||
|
|
|
+ !matchingProducts.length ||
|
|
|
+ new Set(matchingProducts.map((item) => String(item.receiveProductId))).size !== 1
|
|
|
+ ) {
|
|
|
+ throw new Error('采购退货来源批次不一致');
|
|
|
+ }
|
|
|
+ // 历史入库明细缺少来源 ID 时,仍按收货单和唯一退货产品回填来源。
|
|
|
+ detail.sourceReceiveProductId = matchingProducts[0].receiveProductId;
|
|
|
+ builder.num = Number(
|
|
|
+ (builder.num - Number(detail.measureQuantity || 0)).toFixed(4)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (!details?.length || requested.some((item) => item.num !== 0)) {
|
|
|
+ throw new Error('采购退货来源批次可出库数量不足');
|
|
|
+ }
|
|
|
+ if (!this.productList.length) this.detailData(details, '2');
|
|
|
+ } catch (error) {
|
|
|
+ this.stockError = true;
|
|
|
+ this.stockErrorMsg = error.message || '采购退货来源批次查询失败';
|
|
|
+ this.$message.error(this.stockErrorMsg);
|
|
|
+ }
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
//采购委外
|