Merge pull request '3061-send_thermograph' (#725) from 3061-send_thermograph into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #725
Reviewed-by: Joan Sanchez <joan@verdnatura.es>
This commit is contained in:
Joan Sanchez 2021-09-07 10:14:38 +00:00
commit afece39bdc
20 changed files with 204 additions and 154 deletions

View File

@ -3,7 +3,7 @@ module.exports = Self => {
description: 'Get pending collections from a worker',
accessType: 'READ',
returns: {
type: 'Object',
type: 'object',
root: true
},
http: {

View File

@ -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);

View File

@ -0,0 +1 @@
alter table `vn`.`travelThermograph` modify `temperature` enum('COOL', 'WARM') null;

View File

@ -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),

View File

@ -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',

View File

@ -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;

View File

@ -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);
});

View File

@ -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,

View File

@ -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);

View File

@ -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;
}
};

View File

@ -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');
});
});

View File

@ -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');
};
};

View File

@ -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;
}
};

View File

@ -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;
}
});
});

View File

@ -13,5 +13,8 @@
},
"TravelThermograph": {
"dataSource": "vn"
},
"Temperature": {
"dataSource": "vn"
}
}

View File

@ -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"
}]
}

View File

@ -1,4 +0,0 @@
module.exports = Self => {
require('../methods/travel-thermograph/getThermographTemperatures')(Self);
};

View File

@ -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
}
},

View File

@ -122,8 +122,9 @@
</vn-crud-model>
<vn-crud-model
vn-id="temperaturesModel"
url="TravelThermographs/getThermographTemperatures"
data="thermographTemperatures">
url="Temperatures"
data="Temperatures"
auto-load="true">
</vn-crud-model>
<vn-dialog class="edit"
vn-id="newThermographDialog"
@ -162,10 +163,10 @@
vn-one
required="true"
label="Temperature"
ng-model="$ctrl.newThermograph.temperature"
data="thermographTemperatures"
show-field="value"
value-field="value">
ng-model="$ctrl.newThermograph.temperatureFk"
data='Temperatures'
show-field="name"
value-field="code">
</vn-autocomplete>
</vn-horizontal>
</tpl-body>

View File

@ -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();
}