Просмотр исходного кода

指数调差增加上涨下跌及现行价格指数和有效价格指数

ellisran 10 часов назад
Родитель
Сommit
0cd88434c9
1 измененных файлов с 5 добавлено и 3 удалено
  1. 5 3
      app/service/material_exponent_shard.js

+ 5 - 3
app/service/material_exponent_shard.js

@@ -212,18 +212,20 @@ module.exports = app => {
             if (msid !== null) condition.ms_id = msid;
             if (mnid !== null) condition.mn_id = mnid;
             const stageExponentList = this._.filter(allStageExponentList, condition);
+            const inheritWeight = !this._.some(exponentList, ex => ex.type === materialConst.ex_type[0].value && this._.some(stageExponentList, { me_id: ex.id }));
             let sumByChange = 0;
             let constant = 0;
             for (const ex of exponentList) {
                 const stageEx = this._.find(stageExponentList, { me_id: ex.id }) || ex;
+                const weightNum = stageEx.weight_num !== null && stageEx.weight_num !== undefined ? stageEx.weight_num : (inheritWeight ? (ex.weight_num || 0) : 0);
                 if (ex.type === materialConst.ex_type[0].value) {
-                    constant = stageEx.weight_num ? stageEx.weight_num : 0;
+                    constant = weightNum;
                     expr += constant.toString();
                 } else if (ex.type === materialConst.ex_type[1].value) {
                     const effectivePrice = stageEx.effective_price !== null && stageEx.effective_price !== undefined ? stageEx.effective_price : stageEx.m_price;
-                    const calc_num = ex.basic_price > 0 ? this.ctx.helper.mul(stageEx.weight_num, this.ctx.helper.div(effectivePrice, ex.basic_price)) : 0;
+                    const calc_num = ex.basic_price > 0 ? this.ctx.helper.mul(weightNum, this.ctx.helper.div(effectivePrice, ex.basic_price)) : 0;
                     const change = calc_num ? this.ctx.helper.round(calc_num, decimal.qty) : 0;
-                    expr = expr + (change !== 0 ? '+' + stageEx.weight_num.toString() + '*(' + effectivePrice.toString() + '/' + ex.basic_price.toString() + ')' : '');
+                    expr = expr + (change !== 0 ? '+' + weightNum.toString() + '*(' + effectivePrice.toString() + '/' + ex.basic_price.toString() + ')' : '');
                     sumByChange = this.ctx.helper.add(sumByChange, change);
                 }
             }