Quellcode durchsuchen

fix:5345【库存台账】库存-批次合并功能,合并不行,弹出提示,见图

mlchen vor 1 Tag
Ursprung
Commit
2d33fb8965

+ 95 - 14
src/views/warehouseManagement/stockLedger/components/BatchChangeDialog.vue

@@ -255,7 +255,7 @@
         >
       </template>
       <div v-else class="merge-summary">
-        合并后计量数量:{{ total('stockCountBase') }},包装数量:{{
+        合并后计量数量:{{ mergeMeasureQuantity }},包装数量:{{
           total('packingQuantity')
         }},重量:{{ total('weight') }};存货周期取来源最长值。
       </div>
@@ -680,6 +680,19 @@
       hasPacking() {
         return this.packingRows.length > 0;
       },
+      mergeMeasureQuantity() {
+        return this.sources
+          .reduce(
+            (sum, source) =>
+              sum.plus(
+                decimal(source.stockCountBase).minus(
+                  decimal(source.lockQuantity)
+                )
+              ),
+            new BigNumber(0)
+          )
+          .toFixed(6);
+      },
       targetRows() {
         return this.targets.map((target) => {
           const packages = this.packingRows.filter(
@@ -932,13 +945,28 @@
       },
       assignMergeTarget() {
         this.packingRows.forEach((row) => {
-          row.targetDetailId = 1;
+          const locked = this.lockRows.some((lock) =>
+            lock.lockedPackingStockIds.some(
+              (id) => String(id) === String(row.packingStockId)
+            )
+          );
+          row.targetDetailId = locked ? null : 1;
         });
         this.lockRows.forEach((row) => {
-          row.targetDetailId = 1;
+          row.targetDetailId = null;
         });
         const target = this.targets[0];
-        target.measureQuantity = this.sum(this.sources, 'stockCountBase');
+        target.measureQuantity = this.sources
+          .reduce(
+            (sum, source) =>
+              sum.plus(
+                decimal(source.stockCountBase).minus(
+                  decimal(source.lockQuantity)
+                )
+              ),
+            new BigNumber(0)
+          )
+          .toFixed(6);
         target.packageQuantity = this.sum(this.sources, 'packingQuantity');
         target.weight = this.sum(this.sources, 'weight');
         this.syncTargetPackingMinimums();
@@ -1156,8 +1184,9 @@
           const measureMinimum = decimal(this.sum(packages, 'measureQuantity'));
           const weightMinimum = decimal(this.sum(packages, 'weight'));
           if (
-            !target.measureQuantityManual ||
-            decimal(target.measureQuantity).lt(measureMinimum)
+            packages.length &&
+            (!target.measureQuantityManual ||
+              decimal(target.measureQuantity).lt(measureMinimum))
           ) {
             target.measureQuantity = measureMinimum.toFixed(6);
           }
@@ -1366,14 +1395,18 @@
           )
         )
           return '计量数量、包装数量和重量最多支持12位整数、6位小数';
-        if (this.packingRows.some((row) => !row.targetDetailId))
+        if (
+          this.mode === 'split' &&
+          this.packingRows.some((row) => !row.targetDetailId)
+        )
           return '请为每条包装明细选择目标子批次';
         if (
+          this.mode === 'split' &&
           this.lockRows.some((row) => row.targetConflict || !row.targetDetailId)
         )
           return '请完成锁定单分配,关联包装必须属于同一目标';
         const lockOrderTargets = new Map();
-        for (const lock of this.lockRows) {
+        for (const lock of this.mode === 'split' ? this.lockRows : []) {
           const lockOrderId = String(lock.lockOrderId);
           const assignedTarget = lockOrderTargets.get(lockOrderId);
           if (
@@ -1502,12 +1535,60 @@
           targetDetailId: 1,
           batchNo: source.batchNo,
           systemBatchNo: source.systemBatchNo,
-          measureQuantity: decimalValue(source.stockCountBase),
-          packageQuantity: decimalValue(source.packingQuantity),
-          weight: decimalValue(source.weight),
-          lockQuantity: this.sum(source.lockDetails || [], 'quantity'),
-          packingStockIds: this.buildPackingIds(source.stockBatchId, 1),
-          lockAllocations: this.buildLockAllocations(source.stockBatchId, 1)
+          measureQuantity: decimalValue(
+            decimal(source.stockCountBase).minus(decimal(source.lockQuantity))
+          ),
+          packageQuantity: decimalValue(
+            this.packingRows.length
+              ? this.packingRows
+                  .filter(
+                    (row) =>
+                      row.sourceStockBatchId === source.stockBatchId &&
+                      !this.lockRows.some((lock) =>
+                        lock.lockedPackingStockIds.some(
+                          (id) => String(id) === String(row.packingStockId)
+                        )
+                      )
+                  )
+                  .reduce(
+                    (sum, row) => sum.plus(decimal(row.packageQuantity)),
+                    new BigNumber(0)
+                  )
+              : source.packingQuantity
+          ),
+          weight: decimalValue(
+            this.packingRows.length
+              ? this.packingRows
+                  .filter(
+                    (row) =>
+                      row.sourceStockBatchId === source.stockBatchId &&
+                      !this.lockRows.some((lock) =>
+                        lock.lockedPackingStockIds.some(
+                          (id) => String(id) === String(row.packingStockId)
+                        )
+                      )
+                  )
+                  .reduce(
+                    (sum, row) => sum.plus(decimal(row.weight)),
+                    new BigNumber(0)
+                  )
+              : source.weight
+          ),
+          lockQuantity: '0',
+          packingStockIds: JSON.stringify(
+            this.packingRows
+              .filter(
+                (row) =>
+                  row.sourceStockBatchId === source.stockBatchId &&
+                  !this.lockRows.some((lock) =>
+                    lock.lockedPackingStockIds.some(
+                      (id) => String(id) === String(row.packingStockId)
+                    )
+                  )
+              )
+              .map((row) => row.packingStockId)
+          ),
+          lockAllocations: '[]'
         }));
       },
       async submitApply() {