refs #5137 added trigger, template and test
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alexandre Riera 2023-05-10 13:22:53 +02:00
parent 3f414e28cc
commit ded8e0e141
12 changed files with 156 additions and 5 deletions

View File

@ -0,0 +1,3 @@
ALTER TABLE `vn`.`sector` DROP COLUMN `printerFk`;
ALTER TABLE `vn`.`sector` ADD COLUMN `mainPrinterFk` tinyint(3) unsigned;
ALTER TABLE `vn`.`sector` ADD CONSTRAINT sector_FK_1 FOREIGN KEY (mainPrinterFk) REFERENCES vn.printer(id) ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -179,6 +179,8 @@ INSERT INTO `vn`.`printer` (`id`, `name`, `path`, `isLabeler`, `sectorFk`, `ipAd
(2, 'printer2', 'path2', 1, 1 , NULL),
(4, 'printer4', 'path4', 0, NULL, '10.1.10.4');
UPDATE `vn`.`sector` SET mainPrinterFk = 1 WHERE id = 1;
INSERT INTO `vn`.`worker`(`id`, `code`, `firstName`, `lastName`, `userFk`,`bossFk`, `phone`, `sectorFk`, `labelerFk`)
VALUES
(1106, 'LGN', 'David Charles', 'Haller', 1106, 19, 432978106, NULL, NULL),
@ -2719,6 +2721,7 @@ INSERT INTO `util`.`notification` (`id`, `name`, `description`)
VALUES
(1, 'print-email', 'notification fixture one'),
(2, 'invoice-electronic', 'A electronic invoice has been generated'),
(3, 'not-main-printer-configured', 'A printer distinct than main has been configured'),
(4, 'supplier-pay-method-update', 'A supplier pay method has been updated');
INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`)

View File

@ -56,7 +56,7 @@
"type": "number",
"required": false
},
"printerFk": {
"mainPrinterFk": {
"type": "number",
"required": false
},

View File

@ -0,0 +1,63 @@
const models = require('vn-loopback/server/server').models;
describe('Operator', () => {
const authorFk = 9;
const sectorId = 1;
const mainPrinter = 1;
const notificationName = 'not-main-printer-configured';
const operator = {
workerFk: 1,
trainFk: 1,
itemPackingTypeFk: 'H',
warehouseFk: 1,
sectorFk: sectorId
};
async function createOperator(labelerFk, options) {
operator.labelerFk = labelerFk;
await models.Operator.create(operator, options);
return models.NotificationQueue.findOne({
where: {
notificationFk: notificationName
}
}, options);
}
it('should create notification when configured a not main printer in the sector', async() => {
const tx = await models.Operator.beginTransaction({});
try {
const options = {transaction: tx, accessToken: {userId: authorFk}};
const notificationQueue = await createOperator(2, options);
const params = JSON.parse(notificationQueue.params);
expect(notificationQueue.notificationFk).toEqual(notificationName);
expect(notificationQueue.authorFk).toEqual(authorFk);
expect(params.labeler).toContain('2');
expect(params.sector).toContain('1');
expect(params.mainPrinter).toContain('1');
expect(params.worker).toContain('9');
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should not create notification when configured the main printer in the sector', async() => {
const tx = await models.Operator.beginTransaction({});
try {
const options = {transaction: tx, accessToken: {userId: authorFk}};
const notificationQueue = await createOperator(mainPrinter, options);
expect(notificationQueue).toEqual(null);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -0,0 +1,30 @@
module.exports = function(Self) {
Self.observe('after save', async function(ctx) {
const instance = ctx.instance;
const models = Self.app.models;
const options = ctx.options;
if (!instance.sectorFk || !instance.labelerFk) return;
const sector = await models.Sector.findById(instance.sectorFk, {
fields: ['description', 'mainPrinterFk']
}, options);
if (sector.mainPrinterFk && sector.mainPrinterFk != instance.labelerFk) {
const userId = ctx.options.accessToken.userId;
const user = await models.VnUser.findById(userId, {fields: ['nickname']}, options);
const labeler = await models.Printer.findById(instance.labelerFk, {fields: ['name']}, options);
const mainPrinter = await models.Printer.findById(sector.mainPrinterFk, {fields: ['name']}, options);
await models.NotificationQueue.create({
notificationFk: 'not-main-printer-configured',
authorFk: userId,
params: JSON.stringify(
{
'labeler': `#${instance.labelerFk} ${labeler.name}`,
'sector': `#${instance.sectorFk} ${sector.description}`,
'mainPrinter': `#${sector.mainPrinterFk} ${mainPrinter.name}`,
'worker': `#${userId} ${user.nickname}`
}
)
}, options);
}
});
};

View File

@ -27,10 +27,10 @@
"type": "number",
"required": true
},
"sectorFk ": {
"sectorFk": {
"type": "number"
},
"labelerFk ": {
"labelerFk": {
"type": "number"
}
},

View File

@ -0,0 +1,11 @@
const Stylesheet = require(`vn-print/core/stylesheet`);
const path = require('path');
const vnPrintPath = path.resolve('print');
module.exports = new Stylesheet([
`${vnPrintPath}/common/css/spacing.css`,
`${vnPrintPath}/common/css/misc.css`,
`${vnPrintPath}/common/css/layout.css`,
`${vnPrintPath}/common/css/email.css`])
.mergeStyles();

View File

@ -0,0 +1,3 @@
subject: Not main printer configured
title: Not main printer configured
description: Printer {0} has been configured in sector {1} (the main printer for that sector is {2}). Ask the worker {3}

View File

@ -0,0 +1,3 @@
subject: Configurada impresora no principal
title: Configurada impresora no principal
description: Se ha configurado la impresora {0} en el sector {1} (la impresora principal de ese sector es la {2}). Preguntar al trabajador {3}.

View File

@ -0,0 +1,8 @@
<email-body v-bind="$props">
<div class="grid-row">
<div class="grid-block vn-pa-ml">
<h1>{{ $t('title') }}</h1>
<p v-html="$t('description', [labeler, sector, mainPrinter, worker])"></p>
</div>
</div>
</email-body>

View File

@ -0,0 +1,27 @@
const Component = require(`vn-print/core/component`);
const emailBody = new Component('email-body');
module.exports = {
name: 'not-main-printer-configured',
components: {
'email-body': emailBody.build(),
},
props: {
labeler: {
type: String,
required: true
},
sector: {
type: String,
required: true
},
mainPrinter: {
type: String,
required: true
},
worker: {
type: String,
required: true
}
}
};