Browse Source

修复调差期新增bug

laiguoran 3 years ago
parent
commit
427da311e3
2 changed files with 23 additions and 21 deletions
  1. 21 19
      app/service/material_list.js
  2. 2 2
      app/service/material_list_gcl.js

+ 21 - 19
app/service/material_list.js

@@ -300,26 +300,28 @@ module.exports = app => {
          * @return {Promise<void>}
          */
         async copyPreMaterialList2(transaction, materialListData, notJoinList, newMaterial) {
-            const copyMLArray = [];
-            for (const ml of materialListData) {
-                const is_join = this._.find(notJoinList, { gcl_id: ml.gcl_id, xmj_id: ml.xmj_id, mx_id: ml.mx_id });
-                const newMaterialList = {
-                    tid: newMaterial.tid,
-                    order: ml.order,
-                    mid: newMaterial.id,
-                    mb_id: ml.mb_id,
-                    gcl_id: ml.gcl_id,
-                    xmj_id: ml.xmj_id,
-                    mx_id: ml.mx_id,
-                    gather_qty: ml.gather_qty,
-                    quantity: ml.quantity ? ml.quantity : 0,
-                    expr: ml.expr ? ml.expr : '',
-                    is_join: is_join ? 0 : 1,
-                    in_time: new Date(),
-                };
-                copyMLArray.push(newMaterialList);
+            if (materialListData && materialListData.length > 0) {
+                const copyMLArray = [];
+                for (const ml of materialListData) {
+                    const is_join = this._.find(notJoinList, { gcl_id: ml.gcl_id, xmj_id: ml.xmj_id, mx_id: ml.mx_id });
+                    const newMaterialList = {
+                        tid: newMaterial.tid,
+                        order: ml.order,
+                        mid: newMaterial.id,
+                        mb_id: ml.mb_id,
+                        gcl_id: ml.gcl_id,
+                        xmj_id: ml.xmj_id,
+                        mx_id: ml.mx_id,
+                        gather_qty: ml.gather_qty,
+                        quantity: ml.quantity ? ml.quantity : 0,
+                        expr: ml.expr ? ml.expr : '',
+                        is_join: is_join ? 0 : 1,
+                        in_time: new Date(),
+                    };
+                    copyMLArray.push(newMaterialList);
+                }
+                return copyMLArray.length !== 0 ? await transaction.insert(this.tableName, copyMLArray) : true;
             }
-            return copyMLArray.length !== 0 ? await transaction.insert(this.tableName, copyMLArray) : true;
         }
 
 

+ 2 - 2
app/service/material_list_gcl.js

@@ -49,14 +49,14 @@ module.exports = app => {
         }
 
         async insertOrDelGcl(transaction, insertGclList, removeGclList, mid) {
-            if (insertGclList.length > 0) {
+            if (insertGclList && insertGclList.length > 0) {
                 for (const gcl of insertGclList) {
                     gcl.tid = this.ctx.tender.id;
                     gcl.mid = mid;
                 }
                 await transaction.insert(this.tableName, insertGclList);
             }
-            if (removeGclList.length > 0) {
+            if (removeGclList && removeGclList.length > 0) {
                 for (const gcl of removeGclList) {
                     await transaction.delete(this.tableName, { id: gcl.id });
                 }