|
@@ -139,4 +139,38 @@ describe('test/app/service/deal_bills.test.js', () => {
|
|
|
const bills = yield ctx.service.dealBills.getAllDataByCondition({where: {tender_id: ctx.tender.id}});
|
|
|
assert(bills.length === 98);
|
|
|
});
|
|
|
+ // 导入 存在数量单价为空的数据
|
|
|
+ it('test import Excel data by js-xlsx', function* () {
|
|
|
+ const ctx = app.mockContext(mockData);
|
|
|
+ const file = app.baseDir + '/test/app/test_file/deal-bills-emptyCalcField.xls';
|
|
|
+
|
|
|
+ const wb = xlsx.readFile(file);
|
|
|
+ const name = wb.SheetNames[0];
|
|
|
+ const sheetData = {
|
|
|
+ rows: xlsx.utils.sheet_to_json(wb.Sheets[name], {header: 1}),
|
|
|
+ merge: wb.Sheets[name]["!merges"],
|
|
|
+ };
|
|
|
+ const result = yield ctx.service.dealBills.importDataJsXlsx(sheetData, ctx.tender.id);
|
|
|
+ assert(result);
|
|
|
+
|
|
|
+ const bills = yield ctx.service.dealBills.getAllDataByCondition({where: {tender_id: ctx.tender.id}});
|
|
|
+ assert(bills.length === 4);
|
|
|
+
|
|
|
+ assert(bills[0].code === '101-1');
|
|
|
+ assert(bills[0].unit_price === 20000);
|
|
|
+ assert(bills[0].quantity === 1);
|
|
|
+ assert(bills[0].total_price === 1000);
|
|
|
+ assert(bills[1].code === '101-2');
|
|
|
+ assert(bills[1].unit_price === 1200);
|
|
|
+ assert(!bills[1].quantity || bills[0].quantity === 1);
|
|
|
+ assert(bills[1].total_price === 200);
|
|
|
+ assert(bills[2].code === '101-3');
|
|
|
+ assert(!bills[2].unit_price || bills[0].unit_price === 0);
|
|
|
+ assert(bills[2].quantity === 2);
|
|
|
+ assert(bills[2].total_price === 4000);
|
|
|
+ assert(bills[3].code === '101-4');
|
|
|
+ assert(bills[3].unit_price === 2000);
|
|
|
+ assert(bills[3].quantity === 3);
|
|
|
+ assert(!bills[3].total_price || bills[0].total_price === 0);
|
|
|
+ });
|
|
|
});
|