Kaynağa Gözat

计算相关单元测试

MaiXinRong 6 yıl önce
ebeveyn
işleme
2888bc1b7e
3 değiştirilmiş dosya ile 24 ekleme ve 13 silme
  1. 3 2
      app/service/ledger.js
  2. 2 0
      app/view/stage/pay.ejs
  3. 19 11
      test/app/service/ledger.test.js

+ 3 - 2
app/service/ledger.js

@@ -1679,6 +1679,8 @@ module.exports = app => {
                                 this.ctx.helper.times(calcData.sjcl_qty, calcData.unit_price), info.decimal.tp);
                             calcData.qtcl_tp = this.ctx.helper.round(
                                 this.ctx.helper.times(calcData.qtcl_qty, calcData.unit_price), info.decimal.tp);
+                            calcData.total_price = this.ctx.helper.round(
+                                this.ctx.helper.times(calcData.quantity, calcData.unit_price), info.decimal.tp);
                             calcData.deal_tp = this.ctx.helper.round(
                                 this.ctx.helper.times(calcData.deal_qty, calcData.unit_price), info.decimal.tp);
                         } else if (row.sgfh_tp !== undefined || row.sjcl_tp !== undefined || row.qtcl_tp !== undefined || row.deal_tp !== undefined) {
@@ -1691,11 +1693,10 @@ module.exports = app => {
                             calcData.sjcl_tp = (row.sgfh_tp !== undefined) ? this.ctx.helper.round(calcData.row.sjcl_tp, info.decimal.tp) : updateNode.sjcl_tp;
                             calcData.qtcl_tp = (row.sgfh_tp !== undefined) ? this.ctx.helper.round(calcData.row.qtcl_tp, info.decimal.tp) : updateNode.qtcl_tp;
                             calcData.total_price = this.ctx.helper.sum([calcData.sgfh_tp, calcData.sjcl_tp, calcData.qtcl_tp]);
-                            calcData.qtcl_tp = (row.deal_tp !== undefined) ? this.ctx.helper.round(calcData.row.deal_tp, info.decimal.tp) : updateNode.deal_tp;
+                            calcData.deal_tp = (row.deal_tp !== undefined) ? this.ctx.helper.round(calcData.row.deal_tp, info.decimal.tp) : updateNode.deal_tp;
                         }
                         updateData = this._filterUpdateInvalidField(updateNode.id, calcData);
                     } else {
-
                         updateData = this._filterUpdateInvalidField(updateNode.id, row);
                     }
                     await this.transaction.update(this.tableName, updateData);

+ 2 - 0
app/view/stage/pay.ejs

@@ -8,7 +8,9 @@
                     <a href="javascript: void(0);" id="del" class="btn btn-sm" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="删除"><i class="fa fa-remove" aria-hidden="true"></i></a>
                     <a href="javascript: void(0);" id="down-move" class="btn btn-sm" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="下移"><i class="fa fa-arrow-down" aria-hidden="true"></i></a>
                     <a href="javascript: void(0);" id="up-move" class="btn btn-sm" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="上移"><i class="fa fa-arrow-up" aria-hidden="true"></i></a>
+                    <% if (ctx.session.sessionUser.accountId === ctx.stage.user_id && !readOnly) { %>
                     <a href="javascript: void(0);" id="unlock" class="btn btn-sm" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="解锁"><i class="fa fa-unlock" aria-hidden="true"></i> 解锁</a>
+                    <% } %>
                 </div>
                 <div class="d-inline-block">
                     <div class="input-group input-group-sm ml-2 mt-1">

+ 19 - 11
test/app/service/ledger.test.js

@@ -584,13 +584,15 @@ describe('test/app/service/ledger.test.js', () => {
             id: node1.id,
             tender_id: node1.tender_id,
             ledger_id: node1.ledger_id,
-            quantity: qty,
+            sgfh_qty: qty,
             unit_price: up
         });
         assert(resultData.update.length === 1);
         let node = findById(resultData.update, 12);
+        assert(node.sgfh_qty === fQty);
         assert(node.quantity === fQty);
         assert(node.unit_price === fUp);
+        assert(node.sgfh_tp === fTp);
         assert(node.total_price == fTp);
     });
     /* 期望运行结果:
@@ -649,36 +651,42 @@ describe('test/app/service/ledger.test.js', () => {
             id: node1.id,
             tender_id: node1.tender_id,
             ledger_id: node1.ledger_id,
-            quantity: qty[0],
+            sgfh_qty: qty[0],
             unit_price: up[0]
         }, {
             id: node2.id,
             tender_id: node2.tender_id,
             ledger_id: node2.ledger_id,
-            quantity: qty[1],
+            sjcl_qty: qty[1],
             unit_price: up[1]
         }, {
             id: node3.id,
             tender_id: node3.tender_id,
             ledger_id: node3.ledger_id,
-            quantity: qty[2],
+            qtcl_qty: qty[2],
             unit_price: up[2]
         }]);
 
         assert(resultData.update.length === 3);
 
         let node = findById(resultData.update, 11);
-        assert(node.quantity == fQty[0]);
-        assert(node.unit_price == fUp[0]);
+        assert(node.sgfh_qty === fQty[0]);
+        assert(node.quantity === fQty[0]);
+        assert(node.unit_price === fUp[0]);
+        assert(node.sgfh_tp === fTp[0]);
         assert(node.total_price === fTp[0]);
         node = findById(resultData.update, 20);
-        assert(node.quantity == fQty[1]);
-        assert(node.unit_price == fUp[1]);
+        assert(node.sjcl_qty === fQty[1]);
+        assert(node.quantity === fQty[1]);
+        assert(node.unit_price === fUp[1]);
+        assert(node.sjcl_tp === fTp[1]);
         assert(node.total_price === fTp[1]);
         node = findById(resultData.update, 21);
-        assert(node.quantity == fQty[2]);
-        assert(node.unit_price == fUp[2]);
-        assert(node.total_price == fTp[2]);
+        assert(node.qtcl_qty === fQty[2]);
+        assert(node.quantity === fQty[2]);
+        assert(node.unit_price === fUp[2]);
+        assert(node.qtcl_tp === fTp[2]);
+        assert(node.total_price === fTp[2]);
     });
     /* 期望运行结果:
         1