ellisran 1 неделя назад
Родитель
Сommit
83a189b89a
1 измененных файлов с 18 добавлено и 1 удалено
  1. 18 1
      app/service/material_audit.js

+ 18 - 1
app/service/material_audit.js

@@ -292,7 +292,24 @@ module.exports = app => {
                 // 本期一些必要数据(如应耗数量和上期调差金额)插入到material_bills_history表里
                 const materialBillsData = await this.ctx.service.materialBills.getAllDataByCondition({ where: { tid: this.ctx.tender.id } });
                 if (materialBillsData.length === 0 && this.ctx.material.ex_expr === null) {
-                    throw '请至少使用一种调差方式';
+                    if (!this.ctx.material.exponent_node && this.ctx.material.is_stage_self === 0) {
+                        throw '请至少使用一种调差方式';
+                    } else if (this.ctx.material.exponent_node) {
+                        const nodes = await this.ctx.service.materialExponentNode.getAllDataByCondition({ where: { mid: materialId } });
+                        const ex_exprs = this._.map(nodes, 'ex_expr');
+                        // 如果都为空或者null,则抛出错误
+                        if (ex_exprs.every(expr => expr === null || expr === '')) {
+                            throw '请至少使用一种调差方式';
+                        }
+                    } else if (!this.ctx.material.exponent_node && this.ctx.material.is_stage_self === 1) {
+                        const stages = await this.ctx.service.materialStage.getAllDataByCondition({where: {mid: materialId}});
+                        const stage_exprs = this._.map(stages, 'ex_expr');
+                        // 如果都为空或者null,则抛出错误
+                        if (stage_exprs.every(expr => expr === null || expr === '')) {
+                            throw '请至少使用一种调差方式';
+                        }
+                    }
+                    throw 'test';
                 }
 
                 // 微信模板通知