#5926 - Worker/PDA docuware #2482

Open
jsegarra wants to merge 40 commits from 5926_pda_worker_docuware into dev
10 changed files with 92 additions and 132 deletions
Showing only changes of commit cf5cae3de0 - Show all commits

View File

@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models;
describe('docuware upload()', () => {
const userId = 9;
const ticketIds = [10];
const ids = [10];
const ctx = {
args: {ticketIds},
args: {ids},
req: {
getLocale: () => {
return 'en';
@ -32,7 +32,7 @@ describe('docuware upload()', () => {
const options = {transaction: tx};
const user = await models.UserConfig.findById(userId, null, options);
await user.updateAttribute('tabletFk', 'Tablet1', options);
await models.Docuware.upload(ctx, ticketIds, fileCabinetName, options);
await models.Docuware.upload(ctx, ids, fileCabinetName, options);
await tx.rollback();
} catch (e) {
@ -50,7 +50,7 @@ describe('docuware upload()', () => {
let error;
try {
const options = {transaction: tx};
await models.Docuware.upload(ctx, ticketIds, fileCabinetName, options);
await models.Docuware.upload(ctx, ids, fileCabinetName, options);
await tx.rollback();
} catch (e) {

View File

@ -1,4 +1,5 @@
const UserError = require('vn-loopback/util/user-error');
// const isProduction = require('vn-loopback/server/boot/isProduction');
module.exports = Self => {
Self.remoteMethodCtx('upload', {
@ -45,7 +46,7 @@ module.exports = Self => {
throw new UserError('This user does not have an assigned tablet');
const docuwareOptions = await Self.getOptions();
const {modelFk} = await Self.getDocuware({code: fileCabinet, action});
const {modelFk} = await Self.getDocuware({where: {code: fileCabinet, action}});
const modelIsValid = await Self.app.models.Module.findOne({where: {code: modelFk}});
if (!modelIsValid)
@ -58,6 +59,9 @@ module.exports = Self => {
const uri = `${docuwareOptions.url}/FileCabinets/${fileCabinetId}/Documents`;
// if (!isProduction(false))
// throw new UserError('Action not allowed on the test environment');
await Self.app.models[model].docuwareUpload({ctx, tabletFk, ids, myOptions, uri, docuwareOptions, dialogId});
return models.TicketTracking.setDelivered(ctx, ids, myOptions);

View File

@ -315,4 +315,6 @@ INSERT INTO mysql.roles_mapping (`User`, `Host`, `Role`, `Admin_option`)
FROM mysql.roles_mapping
WHERE `User` LIKE @prefixedLike AND `Host` = @genRoleHost;
INSERT INTO vn.docuware (code,fileCabinetName,`action`,dialogName,findById,dmsTypeFk,modelFk)
Outdated
Review

En el after?
Yo diria que tiene que ir en un version

En el after? Yo diria que tiene que ir en un version

Si lo muevo de aquí a 00-firstScript, al hacer myt run me da error:

Error: Cannot add or update a child row: a foreign key constraint fails (vn.docuware, CONSTRAINT docuware_FK FOREIGN KEY (dmsTypeFk) REFERENCES dmsType (id) ON UPDATE CASCADE)

Si lo muevo de aquí a 00-firstScript, al hacer myt run me da error: Error: Cannot add or update a child row: a foreign key constraint fails (`vn`.`docuware`, CONSTRAINT `docuware_FK` FOREIGN KEY (`dmsTypeFk`) REFERENCES `dmsType` (`id`) ON UPDATE CASCADE)

Tiene que ir en fixtures.after y en version porque sino en local falla

Tiene que ir en fixtures.after y en version porque sino en local falla
VALUES ('hr','RRHH','store','Archivar','N__DOCUMENTO',3,'worker');
FLUSH PRIVILEGES;

View File

@ -3796,8 +3796,7 @@ UPDATE vn.locker SET workerFk = 1110 WHERE id = 147;
-- Auto-generated SQL script #202405201318
UPDATE vn.userConfig
SET tabletFk='Tablet1'
WHERE userFk=5;
WHERE userFk=9;
-- Auto-generated SQL script #202405201207
UPDATE vn.docuware

View File

@ -1,9 +1,11 @@
-- Place your SQL code here
ALTER TABLE vn.docuwareTablet ADD fileCabinet varchar(100) NULL;
ALTER TABLE vn.docuware ADD modelFk VARCHAR(45) DEFAULT NULL NULL;
ALTER TABLE vn.docuware ADD CONSTRAINT docuware_module_FK FOREIGN KEY (modelFk) REFERENCES salix.module(code);
ALTER TABLE vn.docuwareTablet ADD fileCabinet varchar(100) NULL;
-- Auto-generated SQL script #202405221107
jsegarra marked this conversation as resolved Outdated
Outdated
Review

Quitar

Quitar
-- Auto-generated SQL script #202405201951
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
VALUES ('Worker','isPDASigned','READ','ALLOW','ROLE','hr');

View File

@ -36,20 +36,7 @@ async function test() {
const jasmine = new Jasmine();
const specFiles = [
`./e2e/paths/01*/*[sS]pec.js`,
jsegarra marked this conversation as resolved Outdated
Outdated
Review

Dejar

Dejar
`./e2e/paths/02*/*[sS]pec.js`,
`./e2e/paths/03*/*[sS]pec.js`,
`./e2e/paths/04*/*[sS]pec.js`,
`./e2e/paths/05*/*[sS]pec.js`,
`./e2e/paths/06*/*[sS]pec.js`,
`./e2e/paths/07*/*[sS]pec.js`,
`./e2e/paths/08*/*[sS]pec.js`,
`./e2e/paths/09*/*[sS]pec.js`,
`./e2e/paths/10*/*[sS]pec.js`,
`./e2e/paths/11*/*[sS]pec.js`,
`./e2e/paths/12*/*[sS]pec.js`,
`./e2e/paths/13*/*[sS]pec.js`,
`./e2e/paths/**/*[sS]pec.js`
];
jasmine.loadConfig({

View File

@ -315,7 +315,7 @@ class Controller extends Section {
if (!force)
return this.$.pdfToTablet.show();
return this.$http.post(`Docuwares/upload`, {fileCabinet: 'deliveryNote', ticketIds: [this.id]})
return this.$http.post(`Docuwares/upload`, {fileCabinet: 'deliveryNote', ids: [this.id]})
.then(() => {
this.vnApp.showSuccess(this.$t('PDF sent!'));
});

View File

@ -11,12 +11,12 @@ export default class Controller extends Section {
sendDocuware() {
const checkedTickets = this.checked;
let ticketIds = [];
let ids = [];
for (let ticket of checkedTickets)
ticketIds.push(ticket.id);
ids.push(ticket.id);
return this.$http.post(`Docuwares/upload`, {fileCabinet: 'deliveryNote', ticketIds})
return this.$http.post(`Docuwares/upload`, {fileCabinet: 'deliveryNote', ids})
.then(res => {
let state = res.data;
for (let ticket of checkedTickets) {

View File

@ -3,115 +3,82 @@ const {models} = require('vn-loopback/server/server');
const UserError = require('vn-loopback/util/user-error');
const isProduction = require('vn-loopback/server/boot/isProduction');
module.exports = Self => {
Self.docuwareUpload = async({ctx, tabletFk, ids: workerId, myOptions, uri, docuwareOptions, dialogId}) => {
if (!Array.isArray(workerId)) workerId = [workerId];
for (id of ticketIds) {
// get delivery note
ctx.args.id = id;
const deliveryNote = await models.Ticket.deliveryNotePdf(ctx, {
id,
type: 'deliveryNote'
}, myOptions);
// get ticket data
const ticket = await models.Ticket.findById(id, {
include: [{
relation: 'client',
scope: {
fields: ['id', 'name', 'fi']
}
}]
}, myOptions);
Self.docuwareUpload = async({ctx, tabletFk, ids: id, myOptions, uri, docuwareOptions, dialogId}) => {
// get delivery note
const pdaId = id[0];
ctx.args.id = pdaId;
delete ctx.args.ids;
// get ticket data
const pda = await models.DeviceProduction.findById(pdaId, myOptions);
const user = await models.UserConfig.find({where: {tabletFk}, fields: ['userFk']}, myOptions);
// upload file
const templateJson = {
'Fields': [
{
'FieldName': 'N__ALBAR_N',
'ItemElementName': 'string',
'Item': id,
},
{
'FieldName': 'CIF_PROVEEDOR',
'ItemElementName': 'string',
'Item': ticket.client().fi,
},
{
'FieldName': 'CODIGO_PROVEEDOR',
'ItemElementName': 'string',
'Item': ticket.client().id,
},
{
'FieldName': 'NOMBRE_PROVEEDOR',
'ItemElementName': 'string',
'Item': ticket.client().name + ' - ' + id,
},
{
'FieldName': 'FECHA_FACTURA',
'ItemElementName': 'date',
'Item': ticket.shipped,
},
{
'FieldName': 'TOTAL_FACTURA',
'ItemElementName': 'Decimal',
'Item': ticket.totalWithVat,
},
{
'FieldName': 'ESTADO',
'ItemElementName': 'string',
'Item': 'Pendiente procesar',
},
{
'FieldName': 'FIRMA_',
'ItemElementName': 'string',
'Item': 'Si',
},
{
'FieldName': 'FILTRO_TABLET',
'ItemElementName': 'string',
'Item': tabletFk,
}
]
};
if (!isProduction(false))
throw new UserError('Action not allowed on the test environment');
// delete old
const docuwareFile = await models.Docuware.checkFile(id, fileCabinet, false);
if (docuwareFile) {
const deleteJson = {
'Field': [{'FieldName': 'ESTADO', 'Item': 'Pendiente eliminar', 'ItemElementName': 'String'}]
};
const deleteUri = `${uri}/${docuwareFile.id}/Fields`;
await axios.put(deleteUri, deleteJson, docuwareOptions.headers);
}
const uploadUri = `${uri}?StoreDialogId=${dialogId}`;
const FormData = require('form-data');
const data = new FormData();
data.append('document', JSON.stringify(templateJson), 'schema.json');
data.append('file[]', deliveryNote[0], 'file.pdf');
const uploadOptions = {
headers: {
'Content-Type': 'multipart/form-data',
'X-File-ModifiedDate': Date.vnNew(),
'Cookie': docuwareOptions.headers.headers.Cookie,
...data.getHeaders()
// upload file
const signPda = await models.Worker.signPdaPdf(ctx,
pdaId
, myOptions);
const templateJson = {
'Fields': [
{
'FieldName': 'N__DOCUMENTO',
'ItemElementName': 'string',
'Item': id,
},
};
{
'FieldName': 'ESTADO',
'ItemElementName': 'string',
'Item': 'Pendiente procesar',
},
{
'FieldName': 'FIRMA_',
'ItemElementName': 'string',
'Item': 'Si',
},
{
'FieldName': 'FILTRO_TABLET',
'ItemElementName': 'string',
'Item': tabletFk,
}
]
};
try {
await axios.post(uploadUri, data, uploadOptions);
} catch (err) {
const $t = ctx.req.__;
const message = $t('Failed to upload delivery note', {id});
if (uploaded.length)
await models.TicketTracking.setDelivered(ctx, uploaded, myOptions);
throw new UserError(message);
}
uploaded.push(id);
if (!isProduction(false))
throw new UserError('Action not allowed on the test environment');
// delete old
const docuwareFile = await models.Docuware.checkFile(id, fileCabinet, false);
if (docuwareFile) {
const deleteJson = {
'Field': [{'FieldName': 'ESTADO', 'Item': 'Pendiente eliminar', 'ItemElementName': 'String'}]
};
const deleteUri = `${uri}/${docuwareFile.id}/Fields`;
await axios.put(deleteUri, deleteJson, docuwareOptions.headers);
}
const uploadUri = `${uri}?StoreDialogId=${dialogId}`;
const FormData = require('form-data');
const data = new FormData();
data.append('document', JSON.stringify(templateJson), 'schema.json');
data.append('file[]', signPda[0], 'file.pdf');
const uploadOptions = {
headers: {
'Content-Type': 'multipart/form-data',
'X-File-ModifiedDate': Date.vnNew(),
'Cookie': docuwareOptions.headers.headers.Cookie,
...data.getHeaders()
},
};
try {
await axios.post(uploadUri, data, uploadOptions);
} catch (err) {
const $t = ctx.req.__;
const message = $t('Failed to upload delivery note', {id});
if (uploaded.length)
await models.TicketTracking.setDelivered(ctx, uploaded, myOptions);
throw new UserError(message);
}
uploaded.push(id);
};
};

View File

@ -6,7 +6,6 @@ module.exports = {
async serverPrefetch() {
this.device = await this.findOneFromDef('device', [this.id]);
},
data() {},
computed: {
},
methods: {