From 6584a29ce5df96e9d63c399539c4daa1dce8ae66 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 3 May 2022 11:16:56 +0200 Subject: [PATCH 01/10] create deleteTrashFiles --- back/methods/dms/deleteTrashFiles.js | 57 ++++++ back/models/dms.js | 1 + db/changes/10460-mother/00-dmsForeignKey.sql | 8 + db/changes/10460-mother/01-dmsType.sql | 5 + db/changes/10460-mother/02-dmsTrigger.sql | 18 ++ db/changes/10460-mother/03-clean.sql | 175 ++++++++++++++++++ db/changes/10460-mother/04-acl.sql | 2 + .../back/methods/claim/deleteOldFiles.js | 63 ------- modules/claim/back/models/claim.js | 1 - modules/invoiceIn/front/dueDay/index.html | 3 + modules/invoiceIn/front/dueDay/index.js | 6 + 11 files changed, 275 insertions(+), 64 deletions(-) create mode 100644 back/methods/dms/deleteTrashFiles.js create mode 100644 db/changes/10460-mother/00-dmsForeignKey.sql create mode 100644 db/changes/10460-mother/01-dmsType.sql create mode 100644 db/changes/10460-mother/02-dmsTrigger.sql create mode 100644 db/changes/10460-mother/03-clean.sql create mode 100644 db/changes/10460-mother/04-acl.sql delete mode 100644 modules/claim/back/methods/claim/deleteOldFiles.js diff --git a/back/methods/dms/deleteTrashFiles.js b/back/methods/dms/deleteTrashFiles.js new file mode 100644 index 000000000..9d16e9d81 --- /dev/null +++ b/back/methods/dms/deleteTrashFiles.js @@ -0,0 +1,57 @@ +const fs = require('fs-extra'); +const path = require('path'); + +module.exports = Self => { + Self.remoteMethod('deleteTrashFiles', { + description: 'Deletes files that have trash type', + accessType: 'WRITE', + returns: { + type: 'object', + root: true + }, + http: { + path: `/deleteTrashFiles`, + verb: 'POST' + } + }); + + Self.deleteTrashFiles = async(options) => { + const tx = await Self.beginTransaction({}); + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) + myOptions.transaction = tx; + + try { + const models = Self.app.models; + const DmsContainer = models.DmsContainer; + + const trashDmsType = await models.DmsType.findOne({ + where: {code: 'trash'} + }, myOptions); + + const dmsToDelete = await models.Dms.find({ + where: { + dmsTypeFk: trashDmsType.id + } + }, myOptions); + + for (let dms of dmsToDelete) { + const pathHash = DmsContainer.getHash(dms.id); + const dmsContainer = await DmsContainer.container(pathHash); + const dstFile = path.join(dmsContainer.client.root, pathHash, dms.file); + await fs.unlink(dstFile); + await dms.destroy(myOptions); + } + if (tx) await tx.commit(); + + } catch (e) { + if (tx) await tx.rollback(); + + throw e; + } + }; +}; diff --git a/back/models/dms.js b/back/models/dms.js index 91291a0c2..24c072f56 100644 --- a/back/models/dms.js +++ b/back/models/dms.js @@ -5,6 +5,7 @@ module.exports = Self => { require('../methods/dms/uploadFile')(Self); require('../methods/dms/removeFile')(Self); require('../methods/dms/updateFile')(Self); + require('../methods/dms/deleteTrashFiles')(Self); Self.checkRole = async function(ctx, id) { const models = Self.app.models; diff --git a/db/changes/10460-mother/00-dmsForeignKey.sql b/db/changes/10460-mother/00-dmsForeignKey.sql new file mode 100644 index 000000000..f44391a17 --- /dev/null +++ b/db/changes/10460-mother/00-dmsForeignKey.sql @@ -0,0 +1,8 @@ +ALTER TABLE vn.propertyDms DROP FOREIGN KEY propertyDms_FK; +ALTER TABLE vn.propertyDms ADD CONSTRAINT propertyDms_FK FOREIGN KEY (dmsFk) REFERENCES vn.dms(id) ON DELETE CASCADE ON UPDATE CASCADE; + +ALTER TABLE vn.clientDms DROP FOREIGN KEY clientDms_ibfk_2; +ALTER TABLE vn.clientDms ADD CONSTRAINT clientDms_ibfk_2 FOREIGN KEY (dmsFk) REFERENCES vn.dms(id) ON DELETE CASCADE ON UPDATE CASCADE; + +ALTER TABLE vn.workerDocument DROP FOREIGN KEY workerDocument_ibfk_2; +ALTER TABLE vn.workerDocument ADD CONSTRAINT workerDocument_ibfk_2 FOREIGN KEY (document) REFERENCES vn.dms(id) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/db/changes/10460-mother/01-dmsType.sql b/db/changes/10460-mother/01-dmsType.sql new file mode 100644 index 000000000..e82c086cf --- /dev/null +++ b/db/changes/10460-mother/01-dmsType.sql @@ -0,0 +1,5 @@ +ALTER TABLE vn.dmsType ADD monthToDelete INT UNSIGNED DEFAULT NULL NULL; +ALTER TABLE vn.dmsType MODIFY COLUMN monthToDelete int(10) unsigned DEFAULT NULL NULL COMMENT 'Meses en el pasado para ir borrando registros, dejar a null para no borrarlos nunca'; +UPDATE vn.dmsType + SET monthToDelete=6 + WHERE id=20; diff --git a/db/changes/10460-mother/02-dmsTrigger.sql b/db/changes/10460-mother/02-dmsTrigger.sql new file mode 100644 index 000000000..a92efcfab --- /dev/null +++ b/db/changes/10460-mother/02-dmsTrigger.sql @@ -0,0 +1,18 @@ + +DELIMITER $$ +$$ +CREATE TRIGGER dms_beforeDelete +BEFORE DELETE +ON dms FOR EACH ROW +BEGIN + DECLARE vCanNotBeDeleted INT; + SELECT COUNT(*) INTO vCanNotBeDeleted + FROM dmsType dt + WHERE NOT (code <=> 'trash') + AND dt.id = OLD.dmsTypeFk; + + IF vCanNotBeDeleted THEN + CALL util.throw('A dms can not be deleted'); + END IF; +END$$ +DELIMITER ; diff --git a/db/changes/10460-mother/03-clean.sql b/db/changes/10460-mother/03-clean.sql new file mode 100644 index 000000000..13951394f --- /dev/null +++ b/db/changes/10460-mother/03-clean.sql @@ -0,0 +1,175 @@ +DROP PROCEDURE IF EXISTS vn.clean; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`clean`() +BEGIN + DECLARE vDateShort DATETIME; + DECLARE vOneYearAgo DATE; + DECLARE vFourYearsAgo DATE; + DECLARE v18Month DATE; + DECLARE v26Month DATE; + DECLARE v3Month DATE; + DECLARE vTrashId varchar(15); + + SET vDateShort = TIMESTAMPADD(MONTH, -2, CURDATE()); + SET vOneYearAgo = TIMESTAMPADD(YEAR,-1,CURDATE()); + SET vFourYearsAgo = TIMESTAMPADD(YEAR,-4,CURDATE()); + SET v18Month = TIMESTAMPADD(MONTH, -18,CURDATE()); + SET v26Month = TIMESTAMPADD(MONTH, -26,CURDATE()); + SET v3Month = TIMESTAMPADD(MONTH, -3, CURDATE()); + + DELETE FROM ticketParking WHERE created < vDateShort; + DELETE FROM routesMonitor WHERE dated < vDateShort; + DELETE FROM workerTimeControlLog WHERE created < vDateShort; + DELETE FROM `message` WHERE sendDate < vDateShort; + DELETE FROM messageInbox WHERE sendDate < vDateShort; + DELETE FROM messageInbox WHERE sendDate < vDateShort; + DELETE FROM workerTimeControl WHERE timed < vFourYearsAgo; + DELETE FROM itemShelving WHERE created < CURDATE() AND visible = 0; + DELETE FROM ticketDown WHERE created < TIMESTAMPADD(DAY,-1,CURDATE()); + DELETE FROM entryLog WHERE creationDate < vDateShort; + DELETE IGNORE FROM expedition WHERE created < v26Month; + DELETE FROM sms WHERE created < v18Month; + DELETE FROM saleTracking WHERE created < vOneYearAgo; + DELETE tobs FROM ticketObservation tobs + JOIN ticket t ON tobs.ticketFk = t.id WHERE t.shipped < TIMESTAMPADD(YEAR,-2,CURDATE()); + DELETE sc.* FROM saleCloned sc JOIN sale s ON s.id = sc.saleClonedFk JOIN ticket t ON t.id = s.ticketFk WHERE t.shipped < vOneYearAgo; + DELETE FROM sharingCart where ended < vDateShort; + DELETE FROM sharingClient where ended < vDateShort; + DELETE tw.* FROM ticketWeekly tw + LEFT JOIN sale s ON s.ticketFk = tw.ticketFk WHERE s.itemFk IS NULL; + DELETE FROM claim WHERE ticketCreated < vFourYearsAgo; + DELETE FROM message WHERE sendDate < vDateShort; + -- Robert ubicacion anterior de trevelLog comentario para debug + DELETE sc FROM saleChecked sc + JOIN sale s ON sc.saleFk = s.id WHERE s.created < vDateShort; + DELETE FROM zoneEvent WHERE `type` = 'day' AND dated < v3Month; + DELETE bm + FROM buyMark bm + JOIN buy b ON b.id = bm.id + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed <= vDateShort; + DELETE FROM stowaway WHERE created < v3Month; + DELETE FROM vn.buy WHERE created < vDateShort AND entryFk = 9200; + DELETE FROM vn.itemShelvingLog WHERE created < vDateShort; + DELETE FROM vn.stockBuyed WHERE creationDate < vDateShort; + + + -- Equipos duplicados + DELETE w.* + FROM workerTeam w + JOIN (SELECT id, team, workerFk, COUNT(*) - 1 as duplicated + FROM workerTeam + GROUP BY team,workerFk + HAVING duplicated + ) d ON d.team = w.team AND d.workerFk = w.workerFk AND d.id != w.id; + + DELETE sc + FROM saleComponent sc + JOIN sale s ON s.id= sc.saleFk + JOIN ticket t ON t.id= s.ticketFk + WHERE t.shipped < v18Month; + + DELETE c + FROM vn.claim c + JOIN vn.claimState cs ON cs.id = c.claimStateFk + WHERE cs.description = "Anulado" AND + c.created < vDateShort; + DELETE + FROM vn.expeditionTruck + WHERE ETD < v3Month; + + -- borrar travels sin entradas + DROP TEMPORARY TABLE IF EXISTS tmp.thermographToDelete; + CREATE TEMPORARY TABLE tmp.thermographToDelete + SELECT th.id,th.dmsFk + FROM vn.travel t + LEFT JOIN vn.entry e ON e.travelFk = t.id + JOIN vn.travelThermograph th ON th.travelFk = t.id + WHERE t.shipped < TIMESTAMPADD(MONTH, -3, CURDATE()) AND e.travelFk IS NULL; + + SELECT dt.id into vTrashId + FROM vn.dmsType dt + WHERE dt.code = 'trash'; + + UPDATE tmp.thermographToDelete th + JOIN vn.dms d ON d.id = th.dmsFk + SET d.dmsTypeFk = vTrashId; + + DELETE th + FROM tmp.thermographToDelete tmp + JOIN vn.travelThermograph th ON th.id = tmp.id; + + DELETE t + FROM vn.travel t + LEFT JOIN vn.entry e ON e.travelFk = t.id + WHERE t.shipped < TIMESTAMPADD(MONTH, -3, CURDATE()) AND e.travelFk IS NULL; + + UPDATE dms d + JOIN dmsType dt ON dt.id = d.dmsTypeFk + SET d.dmsTypeFk = vTrashId + WHERE created < TIMESTAMPADD(MONTH, -dt.monthToDelete, CURDATE()); + + -- borrar entradas sin compras + DROP TEMPORARY TABLE IF EXISTS tmp.entryToDelete; + CREATE TEMPORARY TABLE tmp.entryToDelete + SELECT e.* + FROM vn.entry e + LEFT JOIN vn.buy b ON b.entryFk = e.id + JOIN vn.entryConfig ec ON e.id != ec.defaultEntry + WHERE e.dated < TIMESTAMPADD(MONTH, -3, CURDATE()) AND b.entryFK IS NULL; + + DELETE e + FROM vn.entry e + JOIN tmp.entryToDelete tmp ON tmp.id = e.id; + + -- borrar de route registros menores a 4 años + DROP TEMPORARY TABLE IF EXISTS tmp.routeToDelete; + CREATE TEMPORARY TABLE tmp.routeToDelete + SELECT * + FROM vn.route r + WHERE created < TIMESTAMPADD(YEAR,-4,CURDATE()); + + UPDATE tmp.routeToDelete tmp + JOIN vn.dms d ON d.id = tmp.gestdocFk + SET d.dmsTypeFk = vTrashId; + + DELETE r + FROM tmp.routeToDelete tmp + JOIN vn.route r ON r.id = tmp.id; + + -- borrar registros de dua y awb menores a 2 años + DROP TEMPORARY TABLE IF EXISTS tmp.duaToDelete; + CREATE TEMPORARY TABLE tmp.duaToDelete + SELECT * + FROM vn.dua + WHERE operated < TIMESTAMPADD(YEAR,-2,CURDATE()); + + UPDATE tmp.duaToDelete tm + JOIN vn.dms d ON d.id = tm.gestdocFk + SET d.dmsTypeFk = vTrashId; + + DELETE d + FROM tmp.duaToDelete tmp + JOIN vn.dua d ON d.id = tmp.id; + + DELETE FROM vn.awb WHERE created < TIMESTAMPADD(YEAR,-2,CURDATE()); + + -- Borra los ficheros gestDoc + INSERT INTO vn.printServerQueue(priorityFk, labelReportFk)VALUES(1,11); + + -- Borra los registros de collection y ticketcollection + DELETE FROM vn.collection WHERE created < vDateShort; + + DROP TEMPORARY TABLE IF EXISTS tmp.thermographToDelete; + DROP TEMPORARY TABLE IF EXISTS tmp.entryToDelete; + DROP TEMPORARY TABLE IF EXISTS tmp.duaToDelete; + + DELETE FROM travelLog WHERE creationDate < v3Month; + + CALL shelving_clean; + +END$$ +DELIMITER ; diff --git a/db/changes/10460-mother/04-acl.sql b/db/changes/10460-mother/04-acl.sql new file mode 100644 index 000000000..c576bf1b0 --- /dev/null +++ b/db/changes/10460-mother/04-acl.sql @@ -0,0 +1,2 @@ +INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) + VALUES ('Dms','deleteTrashFiles','WRITE','ALLOW','ROLE','employee') \ No newline at end of file diff --git a/modules/claim/back/methods/claim/deleteOldFiles.js b/modules/claim/back/methods/claim/deleteOldFiles.js deleted file mode 100644 index 6beb99c88..000000000 --- a/modules/claim/back/methods/claim/deleteOldFiles.js +++ /dev/null @@ -1,63 +0,0 @@ -const fs = require('fs-extra'); -const path = require('path'); - -module.exports = Self => { - Self.remoteMethodCtx('deleteOldFiles', { - description: 'Delete files that are 6 months old from dms', - accessType: 'WRITE', - returns: { - type: 'object', - root: true - }, - http: { - path: `/deleteOldFiles`, - verb: 'POST' - } - }); - - Self.deleteOldFiles = async(ctx, options) => { - const tx = await Self.beginTransaction({}); - const myOptions = {}; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (!myOptions.transaction) - myOptions.transaction = tx; - - try { - const models = Self.app.models; - const sixMonthsAgo = new Date(); - sixMonthsAgo.setMonth(sixMonthsAgo.getMonth() - 6); - - const claimDmsType = await models.DmsType.findOne({where: {code: 'claim'}}, myOptions); - const oldDms = await models.Dms.find({ - where: { - and: [{ - created: {lt: sixMonthsAgo}}, { - dmsTypeFk: claimDmsType.id - }] - } - }); - - for (let dms of oldDms) { - const ClaimContainer = models.ClaimContainer; - const pathHash = await ClaimContainer.getHash(dms.id); - const claimContainer = await ClaimContainer.container(pathHash); - const dstFile = path.join(claimContainer.client.root, pathHash, dms.file); - await fs.unlink(dstFile); - await models.ClaimDms.removeFile(ctx, dms.id); - } - if (tx) await tx.commit(); - - return oldDms; - } catch (e) { - if (tx) await tx.rollback(); - - if (fs.existsSync(srcFile)) - await fs.unlink(srcFile); - - throw e; - } - }; -}; diff --git a/modules/claim/back/models/claim.js b/modules/claim/back/models/claim.js index 339eb6051..18b9b3c87 100644 --- a/modules/claim/back/models/claim.js +++ b/modules/claim/back/models/claim.js @@ -8,5 +8,4 @@ module.exports = Self => { require('../methods/claim/updateClaimAction')(Self); require('../methods/claim/isEditable')(Self); require('../methods/claim/downloadFile')(Self); - require('../methods/claim/deleteOldFiles')(Self); }; diff --git a/modules/invoiceIn/front/dueDay/index.html b/modules/invoiceIn/front/dueDay/index.html index 579ef3609..1a1935e72 100644 --- a/modules/invoiceIn/front/dueDay/index.html +++ b/modules/invoiceIn/front/dueDay/index.html @@ -25,6 +25,9 @@ ng-model="invoiceInDueDay.bankFk" url="Banks" show-field="bank" + select-fields="['id','bank']" + order="id" + search-function="$ctrl.bankSearchFunc($search)" rule> {{id}}: {{bank}} diff --git a/modules/invoiceIn/front/dueDay/index.js b/modules/invoiceIn/front/dueDay/index.js index 22b697f7e..3cc1c81e8 100644 --- a/modules/invoiceIn/front/dueDay/index.js +++ b/modules/invoiceIn/front/dueDay/index.js @@ -17,6 +17,12 @@ class Controller extends Section { this.card.reload(); }); } + + bankSearchFunc($search) { + return /^\d+$/.test($search) + ? {id: $search} + : {bank: {like: '%' + $search + '%'}}; + } } ngModule.vnComponent('vnInvoiceInDueDay', { From 66685e7541c12d02a0786e003d4c950913c43953 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 4 May 2022 10:35:31 +0200 Subject: [PATCH 02/10] feat(ticket.expedition): add popover --- .../10451-april/00-aclExpeditionState.sql | 2 + db/dump/fixtures.sql | 39 +++++++---- .../back/methods/expedition-state/filter.js | 41 ++++++++++++ .../expedition-state/specs/filter.spec.js | 21 ++++++ .../ticket/back/methods/expedition/filter.js | 7 +- modules/ticket/back/model-config.json | 3 + .../ticket/back/models/expedition-state.js | 3 + .../ticket/back/models/expedition-state.json | 28 ++++++++ modules/ticket/front/expedition/index.html | 66 ++++++++++++++----- modules/ticket/front/expedition/index.js | 5 ++ modules/ticket/front/expedition/index.spec.js | 22 ++++++- modules/ticket/front/expedition/locale/es.yml | 1 + 12 files changed, 207 insertions(+), 31 deletions(-) create mode 100644 db/changes/10451-april/00-aclExpeditionState.sql create mode 100644 modules/ticket/back/methods/expedition-state/filter.js create mode 100644 modules/ticket/back/methods/expedition-state/specs/filter.spec.js create mode 100644 modules/ticket/back/models/expedition-state.js create mode 100644 modules/ticket/back/models/expedition-state.json create mode 100644 modules/ticket/front/expedition/locale/es.yml diff --git a/db/changes/10451-april/00-aclExpeditionState.sql b/db/changes/10451-april/00-aclExpeditionState.sql new file mode 100644 index 000000000..d26117bbf --- /dev/null +++ b/db/changes/10451-april/00-aclExpeditionState.sql @@ -0,0 +1,2 @@ +INSERT INTO `salix`.`ACL`(`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) +VALUES('ExpeditionState', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 0849e6708..076c6f566 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -883,18 +883,35 @@ INSERT INTO `vn`.`packaging`(`id`, `volume`, `width`, `height`, `depth`, `isPack ('cc', 1640038.00, 56.00, 220.00, 128.00, 1, CURDATE(), 15, 90.00), ('pallet 100', 2745600.00, 100.00, 220.00, 120.00, 1, CURDATE(), 16, 0.00); -INSERT INTO `vn`.`expedition`(`id`, `agencyModeFk`, `ticketFk`, `isBox`, `created`, `itemFk`, `counter`, `checked`, `workerFk`, `externalId`, `packagingFk`) +INSERT INTO `vn`.`expeditionStateType`(`id`, `description`, `code`) VALUES - (1, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 15, 1, 1, 18, 'UR9000006041', 94), - (2, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 16, 2, 1, 18, 'UR9000006041', 94), - (3, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 3, 1, 18, 'UR9000006041', 94), - (4, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 4, 1, 18, 'UR9000006041', 94), - (5, 1, 2, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 1, 1, 18, NULL, 94), - (6, 7, 3, 71, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), NULL, 1, 1, 18, NULL, 94), - (7, 2, 4, 71, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), NULL, 1, 1, 18, NULL, 94), - (8, 3, 5, 71, DATE_ADD(CURDATE(), INTERVAL -4 MONTH), NULL, 1, 1, 18, NULL, 94), - (9, 3, 6, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 1, 1, 18, NULL, 94), - (10, 7, 7, 71, NOW(), NULL, 1, 1, 18, NULL, 94); + (1, 'En reparto', 'ON DELIVERY'), + (2, 'Entregada', 'DELIVERED'), + (3, 'Perdida', 'LOST'); + + +INSERT INTO `vn`.`expedition`(`id`, `agencyModeFk`, `ticketFk`, `isBox`, `created`, `itemFk`, `counter`, `checked`, `workerFk`, `externalId`, `packagingFk`, `stateTypeFk`) + VALUES + (1, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 15, 1, 1, 18, 'UR9000006041', 94, 1), + (2, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 16, 2, 1, 18, 'UR9000006041', 94, 1), + (3, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 3, 1, 18, 'UR9000006041', 94, 2), + (4, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 4, 1, 18, 'UR9000006041', 94, 2), + (5, 1, 2, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 1, 1, 18, NULL, 94, 3), + (6, 7, 3, 71, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), NULL, 1, 1, 18, NULL, 94, 3), + (7, 2, 4, 71, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), NULL, 1, 1, 18, NULL, 94, NULL), + (8, 3, 5, 71, DATE_ADD(CURDATE(), INTERVAL -4 MONTH), NULL, 1, 1, 18, NULL, 94, 1), + (9, 3, 6, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 1, 1, 18, NULL, 94, 2), + (10, 7, 7, 71, NOW(), NULL, 1, 1, 18, NULL, 94, 3); + + +INSERT INTO `vn`.`expeditionState`(`id`, `created`, `expeditionFk`, `typeFk`, `userFk`) + VALUES + (1, CURDATE(), 1, 1, 1), + (2, CURDATE(), 2, 1, 1), + (3, CURDATE(), 3, 1, 1), + (4, CURDATE(), 3, 2, 1106), + (5, CURDATE(), 5, 1, 1106), + (6, CURDATE(), 5, 3, 1106); INSERT INTO `vn`.`ticketPackaging`(`id`, `ticketFk`, `packagingFk`, `quantity`, `created`, `pvp`) VALUES diff --git a/modules/ticket/back/methods/expedition-state/filter.js b/modules/ticket/back/methods/expedition-state/filter.js new file mode 100644 index 000000000..43c293d7d --- /dev/null +++ b/modules/ticket/back/methods/expedition-state/filter.js @@ -0,0 +1,41 @@ +const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; + +module.exports = Self => { + Self.remoteMethod('filter', { + description: 'Find all instances of the model matched by filter from the data source.', + accessType: 'READ', + accepts: [ + { + arg: 'filter', + type: 'object', + description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', + http: {source: 'query'}, + }, + ], + returns: { + type: ['object'], + root: true, + }, + http: { + path: `/filter`, + verb: 'GET', + }, + }); + + Self.filter = async(filter, options) => { + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const stmt = new ParameterizedSQL( + `SELECT es.created, u.name, u.id workerFk, est.description + FROM vn.expeditionState es + JOIN vn.expeditionStateType est ON est.id = es.typeFk + JOIN account.user u ON u.id = es.userFk + `); + stmt.merge(Self.buildSuffix(filter, 'es')); + + return Self.rawStmt(stmt, myOptions); + }; +}; diff --git a/modules/ticket/back/methods/expedition-state/specs/filter.spec.js b/modules/ticket/back/methods/expedition-state/specs/filter.spec.js new file mode 100644 index 000000000..f144606eb --- /dev/null +++ b/modules/ticket/back/methods/expedition-state/specs/filter.spec.js @@ -0,0 +1,21 @@ +const models = require('vn-loopback/server/server').models; + +describe('expeditionState filter()', () => { + it('should return the expedition states matching the filter', async() => { + const tx = await models.ExpeditionState.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const filter = {where: {expeditionFk: 5}}; + const response = await models.ExpeditionState.filter(filter, options); + + expect(response.length).toEqual(2); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/ticket/back/methods/expedition/filter.js b/modules/ticket/back/methods/expedition/filter.js index 5eb7510b7..508e55617 100644 --- a/modules/ticket/back/methods/expedition/filter.js +++ b/modules/ticket/back/methods/expedition/filter.js @@ -47,9 +47,10 @@ module.exports = Self => { e.packagingFk, es.workerFk expeditionScanWorkerFk, su.name scannerUserName, - es.scanned - FROM - vn.expedition e + es.scanned, + est.description + FROM vn.expedition e + LEFT JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk LEFT JOIN vn.item i2 ON i2.id = e.itemFk INNER JOIN vn.item i1 ON i1.id = e.isBox LEFT JOIN vn.packaging p ON p.id = e.packagingFk diff --git a/modules/ticket/back/model-config.json b/modules/ticket/back/model-config.json index 5d5f08694..41885ee33 100644 --- a/modules/ticket/back/model-config.json +++ b/modules/ticket/back/model-config.json @@ -14,6 +14,9 @@ "Expedition": { "dataSource": "vn" }, + "ExpeditionState": { + "dataSource": "vn" + }, "Packaging": { "dataSource": "vn" }, diff --git a/modules/ticket/back/models/expedition-state.js b/modules/ticket/back/models/expedition-state.js new file mode 100644 index 000000000..af76af718 --- /dev/null +++ b/modules/ticket/back/models/expedition-state.js @@ -0,0 +1,3 @@ +module.exports = function(Self) { + require('../methods/expedition-state/filter')(Self); +}; diff --git a/modules/ticket/back/models/expedition-state.json b/modules/ticket/back/models/expedition-state.json new file mode 100644 index 000000000..262eb2e38 --- /dev/null +++ b/modules/ticket/back/models/expedition-state.json @@ -0,0 +1,28 @@ +{ + "name": "ExpeditionState", + "base": "VnModel", + "options": { + "mysql": { + "table": "expeditionState" + } + }, + "properties": { + "id": { + "id": true, + "type": "number", + "description": "Identifier" + }, + "created": { + "type": "date" + }, + "expeditionFk": { + "type": "number" + }, + "typeFk": { + "type": "number" + }, + "userFk": { + "type": "number" + } + } +} diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index bdbb2c3e8..946e923ba 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -19,10 +19,9 @@ Package type Counter externalId - Packager Created - Palletizer - Scanned + State + @@ -33,7 +32,7 @@ vn-tooltip="Delete expedition"> - {{expedition.id | zeroFill:6}} + {{expedition.id | zeroFill:6}} {{::expedition.freightItemName}} {{::expedition.counter}} {{::expedition.externalId}} - - - {{::expedition.userName | dashIfEmpty}} - - {{::expedition.created | date:'dd/MM/yyyy HH:mm'}} + {{::expedition.description}} - - {{::expedition.scannerUserName | dashIfEmpty}} - + + - {{::expedition.scanned | date:'dd/MM/yyyy HH:mm'}} @@ -77,4 +71,44 @@ on-accept="$ctrl.onDialogAccept($data)" question="Delete expedition" message="Are you sure you want to delete this expedition?"> - \ No newline at end of file + + + + + + + + + + + State + Worker + Created + + + + + {{::expeditionState.description}} + + + {{::expeditionState.name || 'System' | translate}} + + + {{::expeditionState.created | date:'dd/MM/yyyy HH:mm'}} + + + + + + + + \ No newline at end of file diff --git a/modules/ticket/front/expedition/index.js b/modules/ticket/front/expedition/index.js index 0c395e6ce..120d89bb2 100644 --- a/modules/ticket/front/expedition/index.js +++ b/modules/ticket/front/expedition/index.js @@ -6,6 +6,11 @@ class Controller extends Section { return this.$http.delete(`Expeditions/${id}`) .then(() => this.$.model.refresh()); } + + showLog(expedition) { + this.expedition = expedition; + this.$.statusLog.show(); + } } ngModule.vnComponent('vnTicketExpedition', { diff --git a/modules/ticket/front/expedition/index.spec.js b/modules/ticket/front/expedition/index.spec.js index 425539aef..586ef2109 100644 --- a/modules/ticket/front/expedition/index.spec.js +++ b/modules/ticket/front/expedition/index.spec.js @@ -5,10 +5,12 @@ describe('Ticket', () => { let controller; let $scope; let $httpBackend; + let $window; beforeEach(ngModule('ticket')); - beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => { + beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _$window_) => { + $window = _$window_; $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); $scope.model = { @@ -30,5 +32,23 @@ describe('Ticket', () => { expect($scope.model.refresh).toHaveBeenCalledWith(); }); }); + + describe('showLog()', () => { + it('should show the popover status log', () => { + controller.$.statusLog = {show: () => {}}; + jest.spyOn(controller.$.statusLog, 'show'); + + const expedition = {id: 1}; + + const event = new MouseEvent('click', { + view: $window, + bubbles: true, + cancelable: true + }); + controller.showLog(event, expedition); + + expect(controller.$.statusLog.show).toHaveBeenCalledWith(); + }); + }); }); }); diff --git a/modules/ticket/front/expedition/locale/es.yml b/modules/ticket/front/expedition/locale/es.yml new file mode 100644 index 000000000..d23cf25af --- /dev/null +++ b/modules/ticket/front/expedition/locale/es.yml @@ -0,0 +1 @@ +Status log: Hitorial de estados \ No newline at end of file From dcd5d07a28b06c368214f04446d6eeb0063e14c1 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 4 May 2022 10:43:40 +0200 Subject: [PATCH 03/10] menu order --- modules/supplier/front/routes.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/supplier/front/routes.json b/modules/supplier/front/routes.json index 86bfba40c..61420b40d 100644 --- a/modules/supplier/front/routes.json +++ b/modules/supplier/front/routes.json @@ -12,12 +12,12 @@ {"state": "supplier.card.basicData", "icon": "settings"}, {"state": "supplier.card.fiscalData", "icon": "account_balance"}, {"state": "supplier.card.billingData", "icon": "icon-payment"}, - {"state": "supplier.card.address.index", "icon": "icon-delivery"}, + {"state": "supplier.card.log", "icon": "history"}, {"state": "supplier.card.account", "icon": "icon-account"}, {"state": "supplier.card.contact", "icon": "contact_phone"}, - {"state": "supplier.card.agencyTerm.index", "icon": "icon-agency-term"}, - {"state": "supplier.card.log", "icon": "history"}, - {"state": "supplier.card.consumption", "icon": "show_chart"} + {"state": "supplier.card.address.index", "icon": "icon-delivery"}, + {"state": "supplier.card.consumption", "icon": "show_chart"}, + {"state": "supplier.card.agencyTerm.index", "icon": "icon-agency-term"} ] }, "keybindings": [ @@ -97,7 +97,7 @@ "url": "/index", "state": "supplier.card.agencyTerm.index", "component": "vn-supplier-agency-term-index", - "description": "Autonomous", + "description": "Agency Agreement", "params": { "supplier": "$ctrl.supplier" } From 38f5541ef49f112c0874b818c24da771908e97ac Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 4 May 2022 11:27:03 +0200 Subject: [PATCH 04/10] execute jenkins test --- modules/ticket/front/expedition/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index 946e923ba..e5b84509f 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -72,7 +72,7 @@ question="Delete expedition" message="Are you sure you want to delete this expedition?"> - + Date: Wed, 4 May 2022 12:00:39 +0200 Subject: [PATCH 05/10] comment frontTest --- modules/ticket/front/expedition/index.spec.js | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/modules/ticket/front/expedition/index.spec.js b/modules/ticket/front/expedition/index.spec.js index 586ef2109..bb2604132 100644 --- a/modules/ticket/front/expedition/index.spec.js +++ b/modules/ticket/front/expedition/index.spec.js @@ -33,22 +33,22 @@ describe('Ticket', () => { }); }); - describe('showLog()', () => { - it('should show the popover status log', () => { - controller.$.statusLog = {show: () => {}}; - jest.spyOn(controller.$.statusLog, 'show'); + // describe('showLog()', () => { + // it('should show the popover status log', () => { + // controller.$.statusLog = {show: () => {}}; + // jest.spyOn(controller.$.statusLog, 'show'); - const expedition = {id: 1}; + // const expedition = {id: 1}; - const event = new MouseEvent('click', { - view: $window, - bubbles: true, - cancelable: true - }); - controller.showLog(event, expedition); + // const event = new MouseEvent('click', { + // view: $window, + // bubbles: true, + // cancelable: true + // }); + // controller.showLog(event, expedition); - expect(controller.$.statusLog.show).toHaveBeenCalledWith(); - }); - }); + // expect(controller.$.statusLog.show).toHaveBeenCalledWith(); + // }); + // }); }); }); From 93e3ea103acc002b37cb933e768086cc9ad55a4f Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 4 May 2022 12:05:46 +0200 Subject: [PATCH 06/10] added frontTest --- modules/ticket/front/expedition/index.spec.js | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/modules/ticket/front/expedition/index.spec.js b/modules/ticket/front/expedition/index.spec.js index bb2604132..586ef2109 100644 --- a/modules/ticket/front/expedition/index.spec.js +++ b/modules/ticket/front/expedition/index.spec.js @@ -33,22 +33,22 @@ describe('Ticket', () => { }); }); - // describe('showLog()', () => { - // it('should show the popover status log', () => { - // controller.$.statusLog = {show: () => {}}; - // jest.spyOn(controller.$.statusLog, 'show'); + describe('showLog()', () => { + it('should show the popover status log', () => { + controller.$.statusLog = {show: () => {}}; + jest.spyOn(controller.$.statusLog, 'show'); - // const expedition = {id: 1}; + const expedition = {id: 1}; - // const event = new MouseEvent('click', { - // view: $window, - // bubbles: true, - // cancelable: true - // }); - // controller.showLog(event, expedition); + const event = new MouseEvent('click', { + view: $window, + bubbles: true, + cancelable: true + }); + controller.showLog(event, expedition); - // expect(controller.$.statusLog.show).toHaveBeenCalledWith(); - // }); - // }); + expect(controller.$.statusLog.show).toHaveBeenCalledWith(); + }); + }); }); }); From a6b867430253eeff957d5a4dd55c6404291ccf05 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 9 May 2022 14:34:20 +0200 Subject: [PATCH 07/10] feat(invoiceIn.tax): add button for create an expence --- db/changes/10451-april/00-aclExpense.sql | 5 +++ modules/invoiceIn/front/tax/index.html | 45 ++++++++++++++++++++++- modules/invoiceIn/front/tax/index.js | 21 +++++++++++ modules/invoiceIn/front/tax/index.spec.js | 30 ++++++++++++++- modules/invoiceIn/front/tax/locale/es.yml | 6 +++ modules/item/back/models/expense.json | 13 +------ 6 files changed, 106 insertions(+), 14 deletions(-) create mode 100644 db/changes/10451-april/00-aclExpense.sql create mode 100644 modules/invoiceIn/front/tax/locale/es.yml diff --git a/db/changes/10451-april/00-aclExpense.sql b/db/changes/10451-april/00-aclExpense.sql new file mode 100644 index 000000000..55ca8c389 --- /dev/null +++ b/db/changes/10451-april/00-aclExpense.sql @@ -0,0 +1,5 @@ +INSERT INTO `salix`.`ACL`(`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES('Expense', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); + +INSERT INTO `salix`.`ACL`(`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES('Expense', '*', 'WRITE', 'ALLOW', 'ROLE', 'administrative'); diff --git a/modules/invoiceIn/front/tax/index.html b/modules/invoiceIn/front/tax/index.html index c495d44d2..7a3a9b333 100644 --- a/modules/invoiceIn/front/tax/index.html +++ b/modules/invoiceIn/front/tax/index.html @@ -33,6 +33,13 @@ show-field="id" rule> {{id}}: {{name}} + + + + - \ No newline at end of file + + + + + +
+
{{$ctrl.$t('New expence')}}
+ + + + + + + + + + +
+
+ + + + +
\ No newline at end of file diff --git a/modules/invoiceIn/front/tax/index.js b/modules/invoiceIn/front/tax/index.js index 53cfc5598..48fb98d4e 100644 --- a/modules/invoiceIn/front/tax/index.js +++ b/modules/invoiceIn/front/tax/index.js @@ -1,5 +1,6 @@ import ngModule from '../module'; import Section from 'salix/components/section'; +import UserError from 'core/lib/user-error'; class Controller extends Section { taxRate(invoiceInTax, taxRateSelection) { @@ -26,6 +27,26 @@ class Controller extends Section { this.card.reload(); }); } + + onResponse() { + if (!this.expence) + throw new UserError(`The fields can't be empty`); + else if (!this.expence.code) + throw new UserError(`The code can't be empty`); + else if (!this.expence.description) + throw new UserError(`The description can't be empty`); + + const params = []; + params.push({ + id: this.expence.code, + isWithheld: this.expence.isWithheld, + name: this.expence.description + }); + + this.$http.post(`Expenses`, params) .then(() => { + this.vnApp.showSuccess(this.$t('Expence saved!')); + }); + } } ngModule.vnComponent('vnInvoiceInTax', { diff --git a/modules/invoiceIn/front/tax/index.spec.js b/modules/invoiceIn/front/tax/index.spec.js index 20d5d40d8..bc7963899 100644 --- a/modules/invoiceIn/front/tax/index.spec.js +++ b/modules/invoiceIn/front/tax/index.spec.js @@ -7,10 +7,12 @@ describe('InvoiceIn', () => { let controller; let $scope; let vnApp; + let $httpBackend; beforeEach(ngModule('invoiceIn')); - beforeEach(inject(($componentController, $rootScope, _vnApp_) => { + beforeEach(inject(($componentController, $rootScope, _vnApp_, _$httpBackend_) => { + $httpBackend = _$httpBackend_; vnApp = _vnApp_; jest.spyOn(vnApp, 'showError'); $scope = $rootScope.$new(); @@ -19,6 +21,7 @@ describe('InvoiceIn', () => { const $element = angular.element(''); controller = $componentController('vnInvoiceInTax', {$element, $scope}); + controller.$.model = crudModel; controller.invoiceIn = {id: 1}; })); @@ -55,5 +58,30 @@ describe('InvoiceIn', () => { expect(controller.card.reload).toHaveBeenCalledWith(); }); }); + + describe('onResponse()', () => { + it('should return success message', () => { + controller.expence = { + code: 7050000005, + isWithheld: 0, + description: 'Test' + }; + + const params = [{ + id: controller.expence.code, + isWithheld: controller.expence.isWithheld, + name: controller.expence.description + }]; + + jest.spyOn(controller.vnApp, 'showSuccess'); + $httpBackend.expect('POST', `Expenses`, params).respond(); + + controller.onResponse(); + $httpBackend.flush(); + + expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Expence saved!'); + }); + }); }); }); + diff --git a/modules/invoiceIn/front/tax/locale/es.yml b/modules/invoiceIn/front/tax/locale/es.yml new file mode 100644 index 000000000..220802d9a --- /dev/null +++ b/modules/invoiceIn/front/tax/locale/es.yml @@ -0,0 +1,6 @@ +Create expence: Crear gasto +New expence: Nuevo gasto +It's a withholding: Es una retención +The fields can't be empty: Los campos no pueden estar vacíos +The code can't be empty: El código no puede estar vacío +The description can't be empty: La descripción no puede estar vacía \ No newline at end of file diff --git a/modules/item/back/models/expense.json b/modules/item/back/models/expense.json index 65af02013..5120f07bc 100644 --- a/modules/item/back/models/expense.json +++ b/modules/item/back/models/expense.json @@ -17,9 +17,6 @@ }, "isWithheld": { "type": "number" - }, - "taxTypeFk": { - "type": "number" } }, "relations": { @@ -28,13 +25,5 @@ "model": "TaxType", "foreignKey": "taxTypeFk" } - }, - "acls": [ - { - "accessType": "READ", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" - } - ] + } } \ No newline at end of file From f08a384a7cd304211272b55a3452011ac9305fb9 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 9 May 2022 14:49:37 +0200 Subject: [PATCH 08/10] fix: e2e test --- e2e/helpers/selectors.js | 2 +- modules/invoiceIn/front/tax/index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 799eb8fe7..189b7be67 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -982,7 +982,7 @@ export default { save: 'vn-invoice-in-basic-data button[type=submit]' }, invoiceInTax: { - addTaxButton: 'vn-invoice-in-tax vn-icon-button[icon="add_circle"]', + addTaxButton: 'vn-invoice-in-tax vn-icon-button[vn-tooltip="Add tax"]', thirdExpence: 'vn-invoice-in-tax vn-horizontal:nth-child(3) > vn-autocomplete[ng-model="invoiceInTax.expenseFk"]', thirdTaxableBase: 'vn-invoice-in-tax vn-horizontal:nth-child(3) > vn-input-number[ng-model="invoiceInTax.taxableBase"]', thirdTaxType: 'vn-invoice-in-tax vn-horizontal:nth-child(3) > vn-autocomplete[ng-model="invoiceInTax.taxTypeSageFk"]', diff --git a/modules/invoiceIn/front/tax/index.html b/modules/invoiceIn/front/tax/index.html index 7a3a9b333..44ceef807 100644 --- a/modules/invoiceIn/front/tax/index.html +++ b/modules/invoiceIn/front/tax/index.html @@ -105,7 +105,7 @@ - + From 568579f46170736aeeaffa6fb1eb4d53aa9fd50f Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 12 May 2022 08:27:04 +0200 Subject: [PATCH 09/10] refactor: pull request changes --- modules/invoiceIn/front/tax/index.html | 17 +++++----- modules/invoiceIn/front/tax/index.js | 35 ++++++++++--------- modules/invoiceIn/front/tax/index.spec.js | 41 +++++++++++++++++++---- modules/invoiceIn/front/tax/locale/es.yml | 7 ++-- 4 files changed, 67 insertions(+), 33 deletions(-) diff --git a/modules/invoiceIn/front/tax/index.html b/modules/invoiceIn/front/tax/index.html index 44ceef807..acc9cf492 100644 --- a/modules/invoiceIn/front/tax/index.html +++ b/modules/invoiceIn/front/tax/index.html @@ -35,7 +35,7 @@ {{id}}: {{name}} @@ -105,31 +105,32 @@ - + -
-
{{$ctrl.$t('New expence')}}
+
+
{{$ctrl.$t('New expense')}}
+ ng-model="$ctrl.expense.code" + required="true" + vn-focus> + ng-model="$ctrl.expense.isWithheld"> diff --git a/modules/invoiceIn/front/tax/index.js b/modules/invoiceIn/front/tax/index.js index 48fb98d4e..d05a77f29 100644 --- a/modules/invoiceIn/front/tax/index.js +++ b/modules/invoiceIn/front/tax/index.js @@ -3,6 +3,10 @@ import Section from 'salix/components/section'; import UserError from 'core/lib/user-error'; class Controller extends Section { + constructor($element, $, vnWeekDays) { + super($element, $); + this.expense = {}; + } taxRate(invoiceInTax, taxRateSelection) { const taxTypeSage = taxRateSelection && taxRateSelection.rate; const taxableBase = invoiceInTax && invoiceInTax.taxableBase; @@ -29,23 +33,24 @@ class Controller extends Section { } onResponse() { - if (!this.expence) - throw new UserError(`The fields can't be empty`); - else if (!this.expence.code) - throw new UserError(`The code can't be empty`); - else if (!this.expence.description) - throw new UserError(`The description can't be empty`); + try { + if (!this.expense.code) + throw new Error(`The code can't be empty`); + if (!this.expense.description) + throw new UserError(`The description can't be empty`); - const params = []; - params.push({ - id: this.expence.code, - isWithheld: this.expence.isWithheld, - name: this.expence.description - }); + const data = [{ + id: this.expense.code, + isWithheld: this.expense.isWithheld, + name: this.expense.description + }]; - this.$http.post(`Expenses`, params) .then(() => { - this.vnApp.showSuccess(this.$t('Expence saved!')); - }); + this.$http.post(`Expenses`, data) .then(() => { + this.vnApp.showSuccess(this.$t('Expense saved!')); + }); + } catch (e) { + this.vnApp.showError(this.$t(e.message)); + } } } diff --git a/modules/invoiceIn/front/tax/index.spec.js b/modules/invoiceIn/front/tax/index.spec.js index bc7963899..c62ada9ca 100644 --- a/modules/invoiceIn/front/tax/index.spec.js +++ b/modules/invoiceIn/front/tax/index.spec.js @@ -1,6 +1,7 @@ import './index.js'; import watcher from 'core/mocks/watcher'; import crudModel from 'core/mocks/crud-model'; +const UserError = require('vn-loopback/util/user-error'); describe('InvoiceIn', () => { describe('Component tax', () => { @@ -61,25 +62,51 @@ describe('InvoiceIn', () => { describe('onResponse()', () => { it('should return success message', () => { - controller.expence = { + controller.expense = { code: 7050000005, isWithheld: 0, description: 'Test' }; - const params = [{ - id: controller.expence.code, - isWithheld: controller.expence.isWithheld, - name: controller.expence.description + const data = [{ + id: controller.expense.code, + isWithheld: controller.expense.isWithheld, + name: controller.expense.description }]; jest.spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.expect('POST', `Expenses`, params).respond(); + $httpBackend.expect('POST', `Expenses`, data).respond(); controller.onResponse(); $httpBackend.flush(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Expence saved!'); + expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Expense saved!'); + }); + + it('should return an error if code is empty', () => { + controller.expense = { + code: null, + isWithheld: 0, + description: 'Test' + }; + + jest.spyOn(controller.vnApp, 'showError'); + controller.onResponse(); + + expect(controller.vnApp.showError).toHaveBeenCalledWith(`The code can't be empty`); + }); + + it('should return an error if description is empty', () => { + controller.expense = { + code: 7050000005, + isWithheld: 0, + description: null + }; + + jest.spyOn(controller.vnApp, 'showError'); + controller.onResponse(); + + expect(controller.vnApp.showError).toHaveBeenCalledWith(`The description can't be empty`); }); }); }); diff --git a/modules/invoiceIn/front/tax/locale/es.yml b/modules/invoiceIn/front/tax/locale/es.yml index 220802d9a..3ff68ea40 100644 --- a/modules/invoiceIn/front/tax/locale/es.yml +++ b/modules/invoiceIn/front/tax/locale/es.yml @@ -1,6 +1,7 @@ -Create expence: Crear gasto -New expence: Nuevo gasto +Create expense: Crear gasto +New expense: Nuevo gasto It's a withholding: Es una retención The fields can't be empty: Los campos no pueden estar vacíos The code can't be empty: El código no puede estar vacío -The description can't be empty: La descripción no puede estar vacía \ No newline at end of file +The description can't be empty: La descripción no puede estar vacía +Expense saved!: Gasto guardado! \ No newline at end of file From 644139324978d74a39249e9dd635fdf87c550e22 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 12 May 2022 08:47:17 +0200 Subject: [PATCH 10/10] refactor: pull request changes --- modules/ticket/back/methods/expedition-state/filter.js | 2 +- modules/ticket/back/methods/expedition/filter.js | 2 +- modules/ticket/front/expedition/index.html | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/ticket/back/methods/expedition-state/filter.js b/modules/ticket/back/methods/expedition-state/filter.js index 43c293d7d..1483780f7 100644 --- a/modules/ticket/back/methods/expedition-state/filter.js +++ b/modules/ticket/back/methods/expedition-state/filter.js @@ -29,7 +29,7 @@ module.exports = Self => { Object.assign(myOptions, options); const stmt = new ParameterizedSQL( - `SELECT es.created, u.name, u.id workerFk, est.description + `SELECT es.created, u.name, u.id workerFk, est.description state FROM vn.expeditionState es JOIN vn.expeditionStateType est ON est.id = es.typeFk JOIN account.user u ON u.id = es.userFk diff --git a/modules/ticket/back/methods/expedition/filter.js b/modules/ticket/back/methods/expedition/filter.js index 508e55617..538e19938 100644 --- a/modules/ticket/back/methods/expedition/filter.js +++ b/modules/ticket/back/methods/expedition/filter.js @@ -48,7 +48,7 @@ module.exports = Self => { es.workerFk expeditionScanWorkerFk, su.name scannerUserName, es.scanned, - est.description + est.description state FROM vn.expedition e LEFT JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk LEFT JOIN vn.item i2 ON i2.id = e.itemFk diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index e5b84509f..a41d368f6 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -20,7 +20,7 @@ Counter externalId Created - State + State @@ -45,7 +45,7 @@ {{::expedition.counter}} {{::expedition.externalId}} {{::expedition.created | date:'dd/MM/yyyy HH:mm'}} - {{::expedition.description}} + {{::expedition.state}} - {{::expeditionState.description}} + {{::expeditionState.state}}