zhangweicheng 5 tahun lalu
induk
melakukan
57638316b6

+ 0 - 1
modules/common/base/base_model.js

@@ -125,7 +125,6 @@ class BaseModel {
       let counter = await counterModel.findOneAndUpdate(condition, update, options);
       let firstID = counter.sequence_value - (list.length - 1);
       for(let a of list){
-          console.log(firstID)
           a.id = firstID;
           firstID+=1
           if(map && keyfield){

+ 9 - 3
modules/glj/facade/glj_facade.js

@@ -81,9 +81,15 @@ async function changeUnitFile(projectData,unitFile,type,userID) {
                     n.unit_price_file_id = targetUnitPriceFile.id;
                     copyList.push(n);
                 }
-                copyList.length>0 ? await unitPriceModel.add(copyList):'';
+                copyList.length>0 ? await unitPriceModel.add(copyList):''; 
+                //也要复制一份组成物信息和材料计算信息
+                let mixRatioModel = new MixRatioModel();
+                await mixRatioModel.copyNotExist(changeUnitPriceId, targetUnitPriceFile.id,{},true);//复制组成物
+                await unitPriceModel.copyMaterialNotExist(changeUnitPriceId,targetUnitPriceFile.id,{},true);
             }
         }
+
+
         let copyResult = await unitPriceModel.copyNotExist(currentUnitPriceId, targetUnitPriceFile.id,projectId);
         // 复制成功后更改project数据
         if (!copyResult) {
@@ -98,8 +104,8 @@ async function changeUnitFile(projectData,unitFile,type,userID) {
         if (!result) {
             throw '切换单价文件失败!';
         }
-        //处理车船税记录
-        await handleVvTaxForChang(targetUnitPriceFile.id,targetUnitPriceFile.vvTaxFileID);
+        //处理车船税记录 - 如果直接从其它项目复制,不用管车船税问题
+        if(type !==1) await handleVvTaxForChang(targetUnitPriceFile.id,targetUnitPriceFile.vvTaxFileID);
         return changeUnitPriceFileInfo;
 }
 

+ 5 - 6
modules/glj/models/mix_ratio_model.js

@@ -57,8 +57,7 @@ class MixRatioModel extends BaseModel {
         } else {
             data.id = await counterModel.getId(collectionName);
         }
-
-        return this.db.model.create(data);
+        return await this.db.model.create(data);
     }
 
     /**
@@ -80,7 +79,7 @@ class MixRatioModel extends BaseModel {
     }
 
     //复制组成物到切换后的组成物映射表
-    async copyNotExist(currentUnitPriceId, changeUnitPriceId,gljMap){
+    async copyNotExist(currentUnitPriceId, changeUnitPriceId,gljMap,newFile = false){
         let currentMap = {},targetMap = {}, insertData = [];
         //取原单价文件所有的的组成物
         let currentList = await  this.model.find({'unit_price_file_id':currentUnitPriceId}).lean();
@@ -93,16 +92,16 @@ class MixRatioModel extends BaseModel {
             if(targetMap[ckey]){//如果切换后的单价文件已经存在,则不用复
                 continue;
             }
-            if(gljMap[ckey]){//在本项目中有用到
+            if(gljMap[ckey] || newFile == true){//在本项目中有用到 或者新建的文件
                 for(let ratio of  currentMap[ckey]){
                     delete ratio._id;  // 删除原有id信息
                     delete ratio.id;
-                    ratio.unit_price_file_id = changeUnitPriceId;
+                    ratio.unit_price_file_id = changeUnitPriceId; 
                     insertData.push(ratio);
                 }
             }
         }
-        return insertData.length > 0 ? this.add(insertData) : true;
+        return insertData.length > 0 ? await this.add(insertData) : true;
     }
     getConnectionMap(map,list){
         for(let l of list){

+ 6 - 6
modules/glj/models/unit_price_model.js

@@ -174,7 +174,7 @@ class UnitPriceModel extends BaseModel {
         }
 
         this.setScene('add');
-        return this.db.model.create(data);
+        return await this.db.model.create(data);
     }
 
     /**
@@ -479,13 +479,13 @@ class UnitPriceModel extends BaseModel {
         return uResult&&mResult&&cResult;
 
     }
-    async copyMaterialNotExist(currentUnitPriceId, changeUnitPriceId,gljMap){
-        await  this.copyCalcNotExist(currentUnitPriceId, changeUnitPriceId,gljMap,original_calc_model);//复制原价计算
-        await  this.copyCalcNotExist(currentUnitPriceId, changeUnitPriceId,gljMap,freight_calc_model);//复制运费计算
+    async copyMaterialNotExist(currentUnitPriceId, changeUnitPriceId,gljMap,newFile = false){
+        await  this.copyCalcNotExist(currentUnitPriceId, changeUnitPriceId,gljMap,original_calc_model,newFile);//复制原价计算
+        await  this.copyCalcNotExist(currentUnitPriceId, changeUnitPriceId,gljMap,freight_calc_model,newFile);//复制运费计算
         return true;
     }
 
-    async  copyCalcNotExist(currentUnitPriceId, changeUnitPriceId,gljMap,model){
+    async  copyCalcNotExist(currentUnitPriceId, changeUnitPriceId,gljMap,model,newFile){
         let currentMap = {},targetMap = {}, insertData = [];
         //取原单价文件所有的原价、运费计算计录
         let currentList = await model.find({'unit_price_file_id':currentUnitPriceId}).lean();
@@ -498,7 +498,7 @@ class UnitPriceModel extends BaseModel {
             if(targetMap[ckey]){//如果切换后已经存在,则不用复制
                 continue;
             }
-            if(gljMap[ckey]){//在本项目中有用到并且复制标记为true
+            if(gljMap[ckey] || newFile == true){//在本项目中有用到 或者 新建的文件
                 for(let c of  currentMap[ckey]){
                     delete c._id;  // 删除原有id信息
                     c.ID = uuidV1();