refactor: refs #7950 Created cmr model #3180
|
@ -2084,7 +2084,7 @@ INSERT INTO `ACL` VALUES (756,'Route','findOne','READ','ALLOW','ROLE','employee'
|
||||||
INSERT INTO `ACL` VALUES (757,'Route','getRoutesByWorker','READ','ALLOW','ROLE','employee',NULL);
|
INSERT INTO `ACL` VALUES (757,'Route','getRoutesByWorker','READ','ALLOW','ROLE','employee',NULL);
|
||||||
INSERT INTO `ACL` VALUES (758,'Route','canViewAllRoute','READ','ALLOW','ROLE','deliveryAssistant',NULL);
|
INSERT INTO `ACL` VALUES (758,'Route','canViewAllRoute','READ','ALLOW','ROLE','deliveryAssistant',NULL);
|
||||||
INSERT INTO `ACL` VALUES (759,'Route','cmr','READ','ALLOW','ROLE','employee',NULL);
|
INSERT INTO `ACL` VALUES (759,'Route','cmr','READ','ALLOW','ROLE','employee',NULL);
|
||||||
INSERT INTO `ACL` VALUES (760,'Route','downloadCmrsZip','READ','ALLOW','ROLE','employee',NULL);
|
INSERT INTO `ACL` VALUES (760,'Cmr','downloadZip','READ','ALLOW','ROLE','employee',NULL);
|
||||||
INSERT INTO `ACL` VALUES (761,'Route','downloadZip','READ','ALLOW','ROLE','employee',NULL);
|
INSERT INTO `ACL` VALUES (761,'Route','downloadZip','READ','ALLOW','ROLE','employee',NULL);
|
||||||
INSERT INTO `ACL` VALUES (762,'Route','filter','READ','ALLOW','ROLE','employee',NULL);
|
INSERT INTO `ACL` VALUES (762,'Route','filter','READ','ALLOW','ROLE','employee',NULL);
|
||||||
INSERT INTO `ACL` VALUES (763,'Route','getByWorker','READ','ALLOW','ROLE','employee',NULL);
|
INSERT INTO `ACL` VALUES (763,'Route','getByWorker','READ','ALLOW','ROLE','employee',NULL);
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
DELETE FROM salix.ACL
|
||||||
|
WHERE property IN ('cmrs', 'cmr', 'downloadCmrsZip')
|
||||||
|
AND model = 'Route';
|
||||||
|
|
||||||
|
INSERT INTO salix.ACL (model,property,principalId)
|
||||||
|
VALUES ('Cmr','filter','production'),
|
||||||
|
('Cmr','downloadZip','production'),
|
||||||
|
('Cmr','print','production')
|
|
@ -2,7 +2,7 @@ const {Report, Email} = require('vn-print');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.printReport = async function(ctx, id, reportName) {
|
Self.printReport = async function(ctx, id, reportName) {
|
||||||
const args = Object.assign({}, ctx.args);
|
const args = Object.assign({id}, ctx.args);
|
||||||
guillermo marked this conversation as resolved
|
|||||||
const params = {lang: ctx.req.getLocale()};
|
const params = {lang: ctx.req.getLocale()};
|
||||||
|
|
||||||
delete args.ctx;
|
delete args.ctx;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const JSZip = require('jszip');
|
const JSZip = require('jszip');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('downloadCmrsZip', {
|
Self.remoteMethodCtx('downloadZip', {
|
||||||
description: 'Download a zip file with multiple cmrs pdfs',
|
description: 'Download a zip file with multiple cmrs pdfs',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
accepts: [
|
accepts: [
|
||||||
|
@ -27,13 +27,13 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
http: {
|
http: {
|
||||||
path: '/downloadCmrsZip',
|
path: '/downloadZip',
|
||||||
verb: 'GET'
|
verb: 'GET'
|
||||||
},
|
},
|
||||||
accessScopes: ['DEFAULT', 'read:multimedia']
|
accessScopes: ['DEFAULT', 'read:multimedia']
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.downloadCmrsZip = async function(ctx, ids, options) {
|
Self.downloadZip = async function(ctx, ids, options) {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
const zip = new JSZip();
|
const zip = new JSZip();
|
||||||
|
@ -44,7 +44,7 @@ module.exports = Self => {
|
||||||
const downloadAddZip = async id => {
|
const downloadAddZip = async id => {
|
||||||
ctx.args = ctx.args || {};
|
ctx.args = ctx.args || {};
|
||||||
ctx.args.id = Number(id);
|
ctx.args.id = Number(id);
|
||||||
const [data] = await models.Route.cmr(ctx, myOptions);
|
const [data] = await models.Cmr.print(ctx, myOptions);
|
||||||
zip.file(`${id}.pdf`, data, {binary: true});
|
zip.file(`${id}.pdf`, data, {binary: true});
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@ const buildFilter = require('vn-loopback/util/filter').buildFilter;
|
||||||
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethod('cmrs', {
|
Self.remoteMethod('filter', {
|
||||||
description: 'Returns an array of cmrs',
|
description: 'Returns an array of cmrs',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
accepts: [
|
accepts: [
|
||||||
|
@ -57,12 +57,12 @@ module.exports = Self => {
|
||||||
root: true
|
root: true
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
path: `/cmrs`,
|
path: `/filter`,
|
||||||
verb: 'GET'
|
verb: 'GET'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.cmrs = async(
|
Self.filter = async(
|
||||||
filter, cmrFk, ticketFk, routeFk, country, clientFk, hasCmrDms, shipped, warehouseFk, options
|
filter, cmrFk, ticketFk, routeFk, country, clientFk, hasCmrDms, shipped, warehouseFk, options
|
||||||
) => {
|
) => {
|
||||||
const params = {cmrFk, ticketFk, routeFk, country, clientFk, hasCmrDms, warehouseFk, shipped};
|
const params = {cmrFk, ticketFk, routeFk, country, clientFk, hasCmrDms, warehouseFk, shipped};
|
|
@ -1,6 +1,6 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('cmr', {
|
Self.remoteMethodCtx('print', {
|
||||||
description: 'Returns the cmr',
|
description: 'Returns the cmr pdf',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
|
@ -27,11 +27,11 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
http: {
|
http: {
|
||||||
path: '/:id/cmr',
|
path: '/:id/print',
|
||||||
verb: 'GET'
|
verb: 'GET'
|
||||||
},
|
},
|
||||||
accessScopes: ['DEFAULT', 'read:multimedia']
|
accessScopes: ['DEFAULT', 'read:multimedia']
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.cmr = (ctx, id) => Self.printReport(ctx, id, 'cmr');
|
Self.print = (ctx, id) => Self.printReport(ctx, id, 'cmr');
|
||||||
};
|
};
|
|
@ -1,6 +1,6 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('route downloadCmrsZip()', () => {
|
describe('route downloadZip()', () => {
|
||||||
it('should create a zip file with the given cmr ids', async() => {
|
it('should create a zip file with the given cmr ids', async() => {
|
||||||
const tx = await models.Route.beginTransaction({});
|
const tx = await models.Route.beginTransaction({});
|
||||||
const ctx = {
|
const ctx = {
|
||||||
|
@ -13,7 +13,7 @@ describe('route downloadCmrsZip()', () => {
|
||||||
};
|
};
|
||||||
let cmrs = '1,2';
|
let cmrs = '1,2';
|
||||||
try {
|
try {
|
||||||
const stream = await models.Route.downloadCmrsZip(ctx, cmrs);
|
const stream = await models.Cmr.downloadZip(ctx, cmrs);
|
||||||
|
|
||||||
expect(stream[0]).toBeDefined();
|
expect(stream[0]).toBeDefined();
|
||||||
await tx.rollback();
|
await tx.rollback();
|
|
@ -5,6 +5,9 @@
|
||||||
"AgencyTermConfig": {
|
"AgencyTermConfig": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
"Cmr": {
|
||||||
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
"DeliveryPoint": {
|
"DeliveryPoint": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
require('../methods/cmr/print')(Self);
|
||||||
|
require('../methods/cmr/filter')(Self);
|
||||||
|
require('../methods/cmr/downloadZip')(Self);
|
||||||
|
};
|
|
@ -14,10 +14,6 @@ module.exports = Self => {
|
||||||
require('../methods/route/driverRouteEmail')(Self);
|
require('../methods/route/driverRouteEmail')(Self);
|
||||||
require('../methods/route/sendSms')(Self);
|
require('../methods/route/sendSms')(Self);
|
||||||
require('../methods/route/downloadZip')(Self);
|
require('../methods/route/downloadZip')(Self);
|
||||||
require('../methods/route/cmr')(Self);
|
|
||||||
require('../methods/route/cmrs')(Self);
|
|
||||||
require('../methods/route/downloadCmrsZip')(Self);
|
|
||||||
require('../methods/route/cmrEmail')(Self);
|
|
||||||
require('../methods/route/getExpeditionSummary')(Self);
|
require('../methods/route/getExpeditionSummary')(Self);
|
||||||
require('../methods/route/getByWorker')(Self);
|
require('../methods/route/getByWorker')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,7 +41,7 @@ module.exports = Self => {
|
||||||
for (const ticketId of tickets) {
|
for (const ticketId of tickets) {
|
||||||
const ticket = await models.Ticket.findById(ticketId, null, myOptions);
|
const ticket = await models.Ticket.findById(ticketId, null, myOptions);
|
||||||
|
|
||||||
if (ticket.cmrFk) {
|
if (ticket.$cmrFk) {
|
||||||
const hasDmsCmr = await Self.rawSql(`
|
const hasDmsCmr = await Self.rawSql(`
|
||||||
SELECT d.id
|
SELECT d.id
|
||||||
FROM ticketDms td
|
FROM ticketDms td
|
||||||
|
@ -53,8 +53,7 @@ module.exports = Self => {
|
||||||
if (hasDmsCmr.length)
|
if (hasDmsCmr.length)
|
||||||
throw new UserError('This ticket already has a cmr saved');
|
throw new UserError('This ticket already has a cmr saved');
|
||||||
|
|
||||||
ctx.args.id = ticket.cmrFk;
|
const response = await models.Cmr.print(ctx, ticket.$cmrFk, myOptions);
|
||||||
jgallego marked this conversation as resolved
Outdated
jgallego
commented
el $ no el solem gastar, si no te un objectiu clar jo meu pensaria be antes de gastarlo, @alexm com ho veus ? el $ no el solem gastar, si no te un objectiu clar jo meu pensaria be antes de gastarlo, @alexm com ho veus ?
guillermo
commented
El problema es que ara com es un model, te que accedir de una altra forma, ticket.cmrFk ja no val. Es pot gastar ticket.cmrFk().id, pero ticket.$cmrFk es mes curt El problema es que ara com es un model, te que accedir de una altra forma, ticket.cmrFk ja no val.
Es pot gastar ticket.cmrFk().id, pero ticket.$cmrFk es mes curt
alexm
commented
Mai havia vist ticket.$cmrFk si funciona i es natiu de loopback supose que abant Mai havia vist ticket.$cmrFk si funciona i es natiu de loopback supose que abant
|
|||||||
const response = await models.Route.cmr(ctx, myOptions);
|
|
||||||
const pdfStream = Readable.from(Buffer.from(response[0]));
|
const pdfStream = Readable.from(Buffer.from(response[0]));
|
||||||
guillermo marked this conversation as resolved
Outdated
jgallego
commented
ho he comentat en Juan i m'ha dit lo mateix, que si es natiu de loopback avant. ho he comentat en Juan i m'ha dit lo mateix, que si es natiu de loopback avant.
**Pero** que l'objecte ctx no hi ha que alterarlo.
guillermo
commented
Entonces com li pase el id? Es que es un param que va per URL, crec que en el seu moment no vaig trovar altra forma... Entonces com li pase el id? Es que es un param que va per URL, crec que en el seu moment no vaig trovar altra forma...
alexm
commented
En este cas seria En este cas seria `await models.Cmr.print(ctx, ticket.$cmrFk); `
Son els parametres que te el back https://gitea.verdnatura.es/verdnatura/salix/src/commit/90e7ab1ec1d18366c7b1a394ddfaa03e90c01d52/modules/route/back/methods/cmr/print.js#L36
guillermo
commented
Ya lo comprobé en su momento y no pude, lo he vuelto a comprobar por si acaso y lo mismo: const response = await models.Cmr.print(ctx, ticket.$cmrFk, myOptions);
Ya lo comprobé en su momento y no pude, lo he vuelto a comprobar por si acaso y lo mismo:
const response = await models.Cmr.print(ctx, ticket.$cmrFk, myOptions);
```
1) ticket saveCmr() should save cmr
- Error: Required properties not found [id]
```
alexm
commented
Se pot posar en
Se pot posar en https://gitea.verdnatura.es/verdnatura/salix/src/commit/6ab431f8efec6e80495451332064c6eeb8b6684f/loopback/common/methods/vn-model/printService.js#L5
`const args = Object.assign({id}, ctx.args);`
jgallego
commented
Cuidao @guillermo el assign tal com l'has posat actualiza l'objecte ctx, que es el que no volem. Cuidao @guillermo el assign tal com l'has posat actualiza l'objecte ctx, que es el que no volem.
Amb la proposata d'Alex es crea uno nou, gasta ixa opcio.
|
|||||||
const data = {
|
const data = {
|
||||||
workerFk: ctx.req.accessToken.userId,
|
workerFk: ctx.req.accessToken.userId,
|
||||||
|
|
|
@ -151,7 +151,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketId, stateCode], myOptions);
|
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketId, stateCode], myOptions);
|
||||||
|
|
||||||
if (ticket?.address()?.province()?.country()?.code != 'ES' && ticket.cmrFk) {
|
if (ticket?.address()?.province()?.country()?.code != 'ES' && ticket.$cmrFk) {
|
||||||
await models.Ticket.saveCmr(ctx, [ticketId], myOptions);
|
await models.Ticket.saveCmr(ctx, [ticketId], myOptions);
|
||||||
externalTickets.push(ticketId);
|
externalTickets.push(ticketId);
|
||||||
}
|
}
|
||||||
|
@ -161,6 +161,6 @@ module.exports = Self => {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
await models.Route.cmrEmail(ctx, externalTickets);
|
await models.Ticket.sendCmrEmail(ctx, externalTickets);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@ const {Email} = require('vn-print');
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('cmrEmail', {
|
Self.remoteMethodCtx('sendCmrEmail', {
|
||||||
description: 'Sends the email with an cmr attached PDF',
|
description: 'Sends the email with an cmr attached PDF',
|
||||||
accessType: 'WRITE',
|
accessType: 'WRITE',
|
||||||
accepts: [
|
accepts: [
|
||||||
|
@ -14,12 +14,12 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
http: {
|
http: {
|
||||||
path: '/cmrEmail',
|
path: '/sendCmrEmail',
|
||||||
verb: 'POST'
|
verb: 'POST'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.cmrEmail = async function(ctx, tickets, options) {
|
Self.sendCmrEmail = async function(ctx, tickets, options) {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
let tx;
|
||||||
|
@ -70,7 +70,7 @@ module.exports = Self => {
|
||||||
await email.send({
|
await email.send({
|
||||||
overrideAttachments: true,
|
overrideAttachments: true,
|
||||||
attachments: [{
|
attachments: [{
|
||||||
filename: `${ticket.cmrFk}.pdf`,
|
filename: `${ticket.$cmrFk}.pdf`,
|
||||||
content: response[0]
|
content: response[0]
|
||||||
}]
|
}]
|
||||||
});
|
});
|
|
@ -40,6 +40,7 @@ module.exports = function(Self) {
|
||||||
require('../methods/ticket/expeditionPalletLabel')(Self);
|
require('../methods/ticket/expeditionPalletLabel')(Self);
|
||||||
require('../methods/ticket/saveSign')(Self);
|
require('../methods/ticket/saveSign')(Self);
|
||||||
require('../methods/ticket/saveCmr')(Self);
|
require('../methods/ticket/saveCmr')(Self);
|
||||||
|
require('../methods/ticket/sendCmrEmail')(Self);
|
||||||
require('../methods/ticket/invoiceTickets')(Self);
|
require('../methods/ticket/invoiceTickets')(Self);
|
||||||
require('../methods/ticket/invoiceTicketsAndPdf')(Self);
|
require('../methods/ticket/invoiceTicketsAndPdf')(Self);
|
||||||
require('../methods/ticket/docuwareDownload')(Self);
|
require('../methods/ticket/docuwareDownload')(Self);
|
||||||
|
|
bajar el id a params.
He revisado el código, y habiamos visto printEmail, en printReport no se hace.
Por lo que el cambio es correcto.
Además, he probado a poner
params.id = id;
y da error, ya que no es lo mismo.