diff --git a/back/methods/collection/getCollection.js b/back/methods/collection/getCollection.js index caf9cc521..e02d2c5c7 100644 --- a/back/methods/collection/getCollection.js +++ b/back/methods/collection/getCollection.js @@ -3,7 +3,7 @@ module.exports = Self => { description: 'Get pending collections from a worker', accessType: 'READ', returns: { - type: 'Object', + type: 'object', root: true }, http: { diff --git a/back/methods/collection/spec/getCollection.spec.js b/back/methods/collection/spec/getCollection.spec.js index bfd3e3603..5ea042f9d 100644 --- a/back/methods/collection/spec/getCollection.spec.js +++ b/back/methods/collection/spec/getCollection.spec.js @@ -1,9 +1,9 @@ -const app = require('vn-loopback/server/server'); +const models = require('vn-loopback/server/server').models; -describe('getCollection()', () => { - it('return list of collection', async() => { +describe('ticket getCollection()', () => { + it('should return a list of collections', async() => { let ctx = {req: {accessToken: {userId: 1106}}}; - let response = await app.models.Collection.getCollection(ctx); + let response = await models.Collection.getCollection(ctx); expect(response.length).toBeGreaterThan(0); expect(response[0].collectionFk).toEqual(1); diff --git a/db/changes/10360-september/01-travelThermograph.sql b/db/changes/10360-september/01-travelThermograph.sql new file mode 100644 index 000000000..dec86d102 --- /dev/null +++ b/db/changes/10360-september/01-travelThermograph.sql @@ -0,0 +1 @@ +alter table `vn`.`travelThermograph` modify `temperature` enum('COOL', 'WARM') null; \ No newline at end of file diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 3da674cb1..8ce5061c5 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1067,10 +1067,10 @@ INSERT INTO `vn`.`itemPlacement`(`id`, `itemFk`, `warehouseFk`, `code`) (4, 2, 1, 'A44'); -INSERT INTO `vn`.`collection`(`id`, `workerFk`, `stateFk`) +INSERT INTO `vn`.`collection`(`id`, `workerFk`, `stateFk`, `created`) VALUES - (1, 1106, 5), - (2, 1106, 14); + (1, 1106, 5, DATE_ADD(CURDATE(),INTERVAL +1 DAY)), + (2, 1106, 14, CURDATE()); INSERT INTO `vn`.`ticketCollection`(`id`, `ticketFk`, `collectionFk`) VALUES @@ -2224,6 +2224,11 @@ INSERT INTO `vn`.`workerTimeControlParams` (`id`, `dayBreak`, `weekBreak`, `week INSERT IGNORE INTO `vn`.`greugeConfig` (`id`, `freightPickUpPrice`) VALUES ('1', '11'); +INSERT INTO `vn`.`temperature`(`code`, `name`, `description`) + VALUES + ('WARM', 'Warm', 'Warm'), + ('COOL', 'Cool', 'Cool'); + INSERT INTO `vn`.`thermograph`(`id`, `model`) VALUES ('TMM190901395', 'TEMPMATE'), @@ -2231,7 +2236,8 @@ INSERT INTO `vn`.`thermograph`(`id`, `model`) ('TZ1905012010', 'DISPOSABLE'), ('138350-0', 'DISPOSABLE'); -INSERT INTO `vn`.`travelThermograph`(`thermographFk`, `created`, `warehouseFk`, `travelFk`, `temperature`, `result`, `dmsFk`) + +INSERT INTO `vn`.`travelThermograph`(`thermographFk`, `created`, `warehouseFk`, `travelFk`, `temperatureFk`, `result`, `dmsFk`) VALUES ('TMM190901395', CURDATE(), 1, 1, 'WARM', 'Ok', NULL), ('TL.BBA85422', DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 2, 2, 'COOL', 'Ok', NULL), diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index b22b0363d..6f257774a 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -1005,7 +1005,7 @@ export default { newThermographId: 'vn-textfield[ng-model="$ctrl.newThermograph.thermographId"]', newThermographModel: 'vn-autocomplete[ng-model="$ctrl.newThermograph.model"]', newThermographWarehouse: 'vn-autocomplete[ng-model="$ctrl.newThermograph.warehouseId"]', - newThermographTemperature: 'vn-autocomplete[ng-model="$ctrl.newThermograph.temperature"]', + newThermographTemperature: 'vn-autocomplete[ng-model="$ctrl.newThermograph.temperatureFk"]', createThermographButton: 'form button[response="accept"]', uploadIcon: 'vn-travel-thermograph-create vn-icon[icon="icon-attach"]', createdThermograph: 'vn-travel-thermograph-index vn-tbody > vn-tr', diff --git a/e2e/paths/09-invoice-in/02_descriptor.spec.js b/e2e/paths/09-invoice-in/02_descriptor.spec.js index 00ed49ec9..02bbce7ac 100644 --- a/e2e/paths/09-invoice-in/02_descriptor.spec.js +++ b/e2e/paths/09-invoice-in/02_descriptor.spec.js @@ -1,8 +1,7 @@ import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; -// #3082 clone is broken due to a strange trigger from production -xdescribe('InvoiceIn descriptor path', () => { +describe('InvoiceIn descriptor path', () => { let browser; let page; diff --git a/e2e/paths/10-travel/05_thermograph.spec.js b/e2e/paths/10-travel/05_thermograph.spec.js index 97077554f..a99dc8352 100644 --- a/e2e/paths/10-travel/05_thermograph.spec.js +++ b/e2e/paths/10-travel/05_thermograph.spec.js @@ -32,7 +32,7 @@ describe('Travel thermograph path', () => { await page.write(selectors.travelThermograph.newThermographId, thermographName); await page.autocompleteSearch(selectors.travelThermograph.newThermographModel, 'TEMPMATE'); await page.autocompleteSearch(selectors.travelThermograph.newThermographWarehouse, 'Warehouse Two'); - await page.autocompleteSearch(selectors.travelThermograph.newThermographTemperature, 'WARM'); + await page.autocompleteSearch(selectors.travelThermograph.newThermographTemperature, 'Warm'); await page.waitToClick(selectors.travelThermograph.createThermographButton); }); diff --git a/modules/invoiceIn/back/methods/invoice-in/clone.js b/modules/invoiceIn/back/methods/invoice-in/clone.js index 35478b045..18df53a95 100644 --- a/modules/invoiceIn/back/methods/invoice-in/clone.js +++ b/modules/invoiceIn/back/methods/invoice-in/clone.js @@ -52,10 +52,11 @@ module.exports = Self => { const issued = new Date(sourceInvoiceIn.issued); issued.setMonth(issued.getMonth() + 1); + const clonedRef = sourceInvoiceIn.supplierRef + '(2)'; const clone = await models.InvoiceIn.create({ serial: sourceInvoiceIn.serial, - supplierRef: sourceInvoiceIn.supplierRef, + supplierRef: clonedRef, supplierFk: sourceInvoiceIn.supplierFk, issued: issued, currencyFk: sourceInvoiceIn.currencyFk, diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/clone.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/clone.spec.js index 71e3c2f6d..e0f191962 100644 --- a/modules/invoiceIn/back/methods/invoice-in/specs/clone.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in/specs/clone.spec.js @@ -1,7 +1,6 @@ const models = require('vn-loopback/server/server').models; -// #3082 clone is broken due to a strange trigger from production -xdescribe('invoiceIn clone()', () => { +describe('invoiceIn clone()', () => { it('should return the cloned invoiceIn and also clone invoiceInDueDays and invoiceInTaxes if there are any referencing the invoiceIn', async() => { const userId = 1; const ctx = { @@ -18,7 +17,7 @@ xdescribe('invoiceIn clone()', () => { try { const clone = await models.InvoiceIn.clone(ctx, 1, options); - expect(clone.supplierRef).toEqual('1234'); + expect(clone.supplierRef).toEqual('1234(2)'); const invoiceInTaxes = await models.InvoiceInTax.find({where: {invoiceInFk: clone.id}}, options); diff --git a/modules/travel/back/methods/thermograph/createThermograph.js b/modules/travel/back/methods/thermograph/createThermograph.js index bfca208fe..137f32ac4 100644 --- a/modules/travel/back/methods/thermograph/createThermograph.js +++ b/modules/travel/back/methods/thermograph/createThermograph.js @@ -4,27 +4,30 @@ module.exports = Self => { accessType: 'WRITE', accepts: [{ arg: 'thermographId', - type: 'String', + type: 'string', description: 'The thermograph id', required: true - }, { + }, + { arg: 'model', - type: 'String', + type: 'string', description: 'The thermograph model', required: true - }, { - arg: 'temperature', - type: 'String', + }, + { + arg: 'temperatureFk', + type: 'string', description: 'The thermograph temperature', required: true - }, { + }, + { arg: 'warehouseId', - type: 'Number', + type: 'number', description: 'The warehouse id', required: true }], returns: { - type: 'Object', + type: 'object', root: true }, http: { @@ -33,27 +36,35 @@ module.exports = Self => { } }); - Self.createThermograph = async(thermographId, model, temperature, warehouseId) => { + Self.createThermograph = async(thermographId, model, temperatureFk, warehouseId, options) => { const models = Self.app.models; - const tx = await Self.beginTransaction({}); + let tx; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } try { - const options = {transaction: tx}; const thermograph = await models.Thermograph.create({ id: thermographId, model: model - }, options); + }, myOptions); await Self.rawSql(` - INSERT INTO travelThermograph(thermographFk, warehouseFk, temperature, created) - VALUES (?, ?,?, NOW()) - `, [thermograph.id, warehouseId, temperature], options); + INSERT INTO travelThermograph(thermographFk, warehouseFk, temperatureFk, created) + VALUES (?, ?, ?, NOW()) + `, [thermograph.id, warehouseId, temperatureFk], myOptions); - await tx.commit(); + if (tx) await tx.commit(); return thermograph; } catch (err) { - await tx.rollback(); + if (tx) await tx.rollback(); throw err; } }; diff --git a/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js b/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js index a3fc98aa6..32014e303 100644 --- a/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js +++ b/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js @@ -1,47 +1,51 @@ -const app = require('vn-loopback/server/server'); +const models = require('vn-loopback/server/server').models; describe('Termograph createThermograph()', () => { - const models = app.models; const thermographId = '99999-1'; const model = 'DISPOSABLE'; - const temperature = 'COOL'; + const temperatureFk = 'COOL'; const warehouseId = 1; - let createdThermograph; - afterAll(async done => { - let travelThermograpToDelete = await models.TravelThermograph.findOne({where: {thermographFk: createdThermograph.id}}); - let thermograpToDelete = await models.Thermograph.findById(createdThermograph.id); + it(`should create a thermograph which is saved in both thermograph and travelThermograph`, async() => { + const tx = await models.Thermograph.beginTransaction({}); - await travelThermograpToDelete.destroy(); - await thermograpToDelete.destroy(); + try { + const options = {transaction: tx}; - done(); + const createdThermograph = await models.Thermograph.createThermograph(thermographId, model, temperatureFk, warehouseId, options); + + expect(createdThermograph.id).toEqual(thermographId); + expect(createdThermograph.model).toEqual(model); + + const createdTravelThermograpth = await models.TravelThermograph.findOne({where: {thermographFk: thermographId}}, options); + + expect(createdTravelThermograpth.warehouseFk).toEqual(warehouseId); + expect(createdTravelThermograpth.temperatureFk).toEqual(temperatureFk); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } }); - it(`should be able to create just once a thermograph which is saved in both thermograph and travelThermograph`, async() => { - let createdTravelThermograpth = await models.TravelThermograph.findOne({where: {thermographFk: thermographId}}); - - expect(createdTravelThermograpth).toBeNull(); - - createdThermograph = await models.Thermograph.createThermograph(thermographId, model, temperature, warehouseId); - - expect(createdThermograph.id).toEqual(thermographId); - expect(createdThermograph.model).toEqual(model); - - createdTravelThermograpth = await models.TravelThermograph.findOne({where: {thermographFk: thermographId}}); - - expect(createdTravelThermograpth.warehouseFk).toEqual(warehouseId); - expect(createdTravelThermograpth.temperature).toEqual(temperature); + it(`should throw an error when trying to created repeated thermograph`, async() => { + const tx = await models.Thermograph.beginTransaction({}); let error; try { - await models.Thermograph.createThermograph(thermographId, model, temperature, warehouseId); + const options = {transaction: tx}; + + await models.Thermograph.createThermograph(thermographId, model, temperatureFk, warehouseId, options); + await models.Thermograph.createThermograph(thermographId, model, temperatureFk, warehouseId, options); + + await tx.rollback(); } catch (e) { + await tx.rollback(); error = e; } - expect(error).toBeDefined(); expect(error.message).toBe('This thermograph id already exists'); }); }); diff --git a/modules/travel/back/methods/travel-thermograph/getThermographTemperatures.js b/modules/travel/back/methods/travel-thermograph/getThermographTemperatures.js deleted file mode 100644 index 1d510b513..000000000 --- a/modules/travel/back/methods/travel-thermograph/getThermographTemperatures.js +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = Self => { - Self.remoteMethod('getThermographTemperatures', { - description: 'Gets the thermograph temperatures', - accessType: 'READ', - returns: { - type: ['String'], - root: true - }, - http: { - path: `/getThermographTemperatures`, - verb: 'GET' - } - }); - - Self.getThermographTemperatures = async() => { - return Self.getEnumValues('temperature'); - }; -}; diff --git a/modules/travel/back/methods/travel/createThermograph.js b/modules/travel/back/methods/travel/createThermograph.js index 974b67923..aac3a22b9 100644 --- a/modules/travel/back/methods/travel/createThermograph.js +++ b/modules/travel/back/methods/travel/createThermograph.js @@ -6,44 +6,51 @@ module.exports = Self => { accessType: 'WRITE', accepts: [{ arg: 'id', - type: 'Number', + type: 'number', description: 'The travel id', http: {source: 'path'} - }, { + }, + { arg: 'thermographId', - type: 'String', + type: 'string', description: 'The thermograph id', required: true - }, { + }, + { arg: 'state', - type: 'String', + type: 'string', required: true - }, { + }, + { arg: 'warehouseId', - type: 'Number', + type: 'number', description: 'The warehouse id', required: true - }, { + }, + { arg: 'companyId', - type: 'Number', + type: 'number', description: 'The company id', required: true - }, { + }, + { arg: 'dmsTypeId', - type: 'Number', + type: 'number', description: 'The dms type id', required: true - }, { + }, + { arg: 'reference', - type: 'String', + type: 'string', required: true - }, { + }, + { arg: 'description', - type: 'String', + type: 'string', required: true }], returns: { - type: 'Object', + type: 'object', root: true }, http: { @@ -52,36 +59,44 @@ module.exports = Self => { } }); - Self.createThermograph = async(ctx, id, thermographId, state) => { + Self.createThermograph = async(ctx, id, thermographId, state, options) => { const models = Self.app.models; - const tx = await Self.beginTransaction({}); + let tx; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } try { - const options = {transaction: tx}; const travelThermograph = await models.TravelThermograph.findOne({ where: { thermographFk: thermographId, travelFk: null } - }, options); + }, myOptions); if (!travelThermograph) throw new UserError('No valid travel thermograph found'); - const uploadedFiles = await models.Dms.uploadFile(ctx, options); + const uploadedFiles = await models.Dms.uploadFile(ctx, myOptions); const firstDms = uploadedFiles[0]; await travelThermograph.updateAttributes({ dmsFk: firstDms.id, travelFk: id, result: state - }, options); + }, myOptions); - await tx.commit(); + if (tx) await tx.commit(); return travelThermograph; } catch (err) { - await tx.rollback(); + if (tx) await tx.rollback(); throw err; } }; diff --git a/modules/travel/back/methods/travel/specs/createThermograph.spec.js b/modules/travel/back/methods/travel/specs/createThermograph.spec.js index 36221e479..742e2dc18 100644 --- a/modules/travel/back/methods/travel/specs/createThermograph.spec.js +++ b/modules/travel/back/methods/travel/specs/createThermograph.spec.js @@ -1,50 +1,50 @@ -const app = require('vn-loopback/server/server'); +const models = require('vn-loopback/server/server').models; describe('Travel createThermograph()', () => { - const models = app.models; const travelId = 3; const currentUserId = 1102; const thermographId = '138350-0'; const ctx = {req: {accessToken: {userId: currentUserId}}, args: {dmsTypeId: 1}}; - let travelThermographBefore; - - afterAll(async done => { - await app.models.TravelThermograph.rawSql(` - UPDATE travelThermograph - SET travelFk = NULL, dmsFk = NULL - WHERE id = ?`, [travelThermographBefore.id]); - - done(); - }); it(`should set the travelFk and dmsFk properties to the travel thermograph`, async() => { - spyOn(app.models.Dms, 'uploadFile').and.returnValue([{id: 5}]); + const tx = await models.Travel.beginTransaction({}); - travelThermographBefore = await models.TravelThermograph.findOne({ - where: { - thermographFk: thermographId, - travelFk: null - } - }); + try { + const options = {transaction: tx}; - await models.Travel.createThermograph(ctx, travelId, thermographId); + spyOn(models.Dms, 'uploadFile').and.returnValue([{id: 5}]); - const travelThermographAfter = await models.TravelThermograph.findOne({ - where: { - thermographFk: thermographId, - travelFk: travelId - } - }); + travelThermographBefore = await models.TravelThermograph.findOne({ + where: { + thermographFk: thermographId, + travelFk: null + } + }, options); - expect(app.models.Dms.uploadFile).toHaveBeenCalledWith(ctx, jasmine.any(Object)); + await models.Travel.createThermograph(ctx, travelId, thermographId, options); - expect(travelThermographBefore).toBeDefined(); - expect(travelThermographBefore.thermographFk).toEqual(thermographId); - expect(travelThermographBefore.travelFk).toBeNull(); - expect(travelThermographAfter).toBeDefined(); + const travelThermographAfter = await models.TravelThermograph.findOne({ + where: { + thermographFk: thermographId, + travelFk: travelId + } + }, options); - expect(travelThermographAfter.thermographFk).toEqual(thermographId); - expect(travelThermographAfter.travelFk).toEqual(travelId); - expect(travelThermographAfter.dmsFk).toEqual(5); + expect(models.Dms.uploadFile).toHaveBeenCalledWith(ctx, jasmine.any(Object)); + + expect(travelThermographBefore).toBeDefined(); + expect(travelThermographBefore.thermographFk).toEqual(thermographId); + expect(travelThermographBefore.travelFk).toBeNull(); + expect(travelThermographAfter).toBeDefined(); + + expect(travelThermographAfter.thermographFk).toEqual(thermographId); + expect(travelThermographAfter.travelFk).toEqual(travelId); + expect(travelThermographAfter.dmsFk).toEqual(5); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } }); }); diff --git a/modules/travel/back/model-config.json b/modules/travel/back/model-config.json index b06d00f06..34321ba78 100644 --- a/modules/travel/back/model-config.json +++ b/modules/travel/back/model-config.json @@ -13,5 +13,8 @@ }, "TravelThermograph": { "dataSource": "vn" + }, + "Temperature": { + "dataSource": "vn" } } diff --git a/modules/travel/back/models/temperature.json b/modules/travel/back/models/temperature.json new file mode 100644 index 000000000..575b5f8be --- /dev/null +++ b/modules/travel/back/models/temperature.json @@ -0,0 +1,30 @@ +{ + "name": "Temperature", + "base": "VnModel", + "options": { + "mysql": { + "table": "temperature" + } + }, + "properties": { + "code": { + "type": "string", + "id": true, + "description": "Identifier", + "required": true + }, + "name": { + "type": "string", + "required": true + }, + "description": { + "type": "string" + } + }, + "acls": [{ + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + }] +} diff --git a/modules/travel/back/models/travel-thermograph.js b/modules/travel/back/models/travel-thermograph.js deleted file mode 100644 index 91aa4de69..000000000 --- a/modules/travel/back/models/travel-thermograph.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = Self => { - require('../methods/travel-thermograph/getThermographTemperatures')(Self); -}; - diff --git a/modules/travel/back/models/travel-thermograph.json b/modules/travel/back/models/travel-thermograph.json index 70ee0de07..1e6dd1905 100644 --- a/modules/travel/back/models/travel-thermograph.json +++ b/modules/travel/back/models/travel-thermograph.json @@ -13,22 +13,25 @@ }, "properties": { "id": { - "type": "Number", + "type": "number", "description": "Identifier", "id": true }, "created": { - "type": "Date" + "type": "date" }, "temperature": { - "type": "String", + "type": "string" + }, + "temperatureFk": { + "type": "string", "required": true }, "result": { - "type": "String" + "type": "string" }, "warehouseFk": { - "type": "Number", + "type": "number", "required": true } }, diff --git a/modules/travel/front/thermograph/create/index.html b/modules/travel/front/thermograph/create/index.html index f73938f5b..41709e1fb 100644 --- a/modules/travel/front/thermograph/create/index.html +++ b/modules/travel/front/thermograph/create/index.html @@ -122,8 +122,9 @@ + url="Temperatures" + data="Temperatures" + auto-load="true"> + ng-model="$ctrl.newThermograph.temperatureFk" + data='Temperatures' + show-field="name" + value-field="code"> diff --git a/modules/travel/front/thermograph/create/index.js b/modules/travel/front/thermograph/create/index.js index 666393350..b6d78fc50 100644 --- a/modules/travel/front/thermograph/create/index.js +++ b/modules/travel/front/thermograph/create/index.js @@ -63,12 +63,11 @@ class Controller extends Section { this.newThermograph = { thermographId: this.thermographId, warehouseId: this.warehouseId, - temperature: defaultTemperature, + temperatureFk: defaultTemperature, model: defaultModel }; this.$.modelsModel.refresh(); - this.$.temperaturesModel.refresh(); this.$.newThermographDialog.show(); }