Browse Source

批量插入、导入Excel,清单精度问题

MaiXinRong 6 years ago
parent
commit
77c2c4e84a
2 changed files with 6 additions and 21 deletions
  1. 5 3
      app/service/ledger.js
  2. 1 18
      app/service/pos.js

+ 5 - 3
app/service/ledger.js

@@ -1713,8 +1713,9 @@ module.exports = app => {
                     const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, qd.unit);
                     this.ctx.helper.checkFieldPrecision(qd, qtyFields, precision.value);
                     const insertResult = await this.transaction.insert(this.tableName, qd);
+                    qd.id = insertResult.insertId;
                     newIds.push(insertResult.insertId);
-                    await this.ctx.service.pos.insertLedgerPosData(this.transaction, tenderId, insertResult.insertId, data[i].pos);
+                    await this.ctx.service.pos.insertLedgerPosData(this.transaction, tenderId, qd, data[i].pos);
                     await this.calc(tenderId, insertResult.insertId, this.transaction);
                 }
                 this.cache.set(cacheKey, maxId + data.length + 1, 'EX', this.ctx.app.config.cacheTime);
@@ -1782,8 +1783,9 @@ module.exports = app => {
                     const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, qd.unit);
                     this.ctx.helper.checkFieldPrecision(qd, qtyFields, precision.value);
                     const insertResult = await this.transaction.insert(this.tableName, qd);
+                    qd.id = insertResult.insertId;
                     newIds.push(insertResult.insertId);
-                    await this.ctx.service.pos.insertLedgerPosData(this.transaction, tenderId, insertResult.insertId, data[i].pos);
+                    await this.ctx.service.pos.insertLedgerPosData(this.transaction, tenderId, qd, data[i].pos);
                     await this.calc(tenderId, insertResult.insertId, this.transaction);
                 }
                 this.cache.set(cacheKey, maxId + data.length + 1, 'EX', this.ctx.app.config.cacheTime);
@@ -1866,7 +1868,7 @@ module.exports = app => {
                     await this._importCacheTreeNode(transaction, child);
                 }
             } else if (node.pos && node.pos.length > 0) {
-                await this.ctx.service.pos.insertLedgerPosDataExcel(transaction, this.ctx.tender.id, data, node.pos);
+                await this.ctx.service.pos.insertLedgerPosData(transaction, this.ctx.tender.id, data, node.pos);
             }
         }
 

+ 1 - 18
app/service/pos.js

@@ -190,24 +190,7 @@ module.exports = app => {
          * @param {Array} data - 新增数据
          * @returns {Promise<void>}
          */
-        async insertLedgerPosData(transaction, tid, lid, data) {
-            const bills = await this.ctx.service.ledger.getDataById(lid);
-            const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
-            for (const d of data) {
-                d.tid = tid;
-                d.lid = lid;
-                // todo 新增期
-                d.add_stage = 0;
-                d.add_times = 0;
-                d.add_user = this.ctx.session.sessionUser.accountId;
-                if (d.quantity) {
-                    d.quantity = this._.round(d.quantity, precision.value);
-                }
-            }
-            await transaction.insert(this.tableName, data);
-        }
-
-        async insertLedgerPosDataExcel(transaction, tid, bills, data) {
+        async insertLedgerPosData(transaction, tid, bills, data) {
             const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
             for (const d of data) {
                 d.tid = tid;