From ca7601a9f2116ff8b470de3ce85ff8f553b4504b Mon Sep 17 00:00:00 2001 From: joan Date: Thu, 15 Oct 2020 11:53:01 +0200 Subject: [PATCH 01/23] 2433 - Added sage fields --- .../client/specs/updateFiscalData.spec.js | 1 - .../back/methods/client/updateFiscalData.js | 12 ++++++ modules/client/back/model-config.json | 6 +++ modules/client/back/models/client.json | 28 ++++++++++++- modules/client/back/models/sage-tax-type.json | 33 +++++++++++++++ .../back/models/sage-transaction-type.json | 33 +++++++++++++++ modules/client/front/fiscal-data/index.html | 41 +++++++++++++++++++ modules/client/front/fiscal-data/index.js | 6 +++ .../client/front/fiscal-data/locale/es.yml | 6 ++- 9 files changed, 163 insertions(+), 3 deletions(-) create mode 100644 modules/client/back/models/sage-tax-type.json create mode 100644 modules/client/back/models/sage-transaction-type.json diff --git a/modules/client/back/methods/client/specs/updateFiscalData.spec.js b/modules/client/back/methods/client/specs/updateFiscalData.spec.js index a2b8f3d583..288183fb69 100644 --- a/modules/client/back/methods/client/specs/updateFiscalData.spec.js +++ b/modules/client/back/methods/client/specs/updateFiscalData.spec.js @@ -29,7 +29,6 @@ describe('Client updateFiscalData', () => { const ctx = {req: {accessToken: {userId: 5}}}; ctx.args = {postcode: 46680}; - const client = await app.models.Client.findById(clientId); expect(client.postcode).toEqual('46460'); diff --git a/modules/client/back/methods/client/updateFiscalData.js b/modules/client/back/methods/client/updateFiscalData.js index f16b0ef2b5..48cc6df88c 100644 --- a/modules/client/back/methods/client/updateFiscalData.js +++ b/modules/client/back/methods/client/updateFiscalData.js @@ -43,6 +43,18 @@ module.exports = Self => { arg: 'provinceFk', type: 'number' }, + { + arg: 'sageTaxTypeFk', + type: 'number' + }, + { + arg: 'sageTransactionTypeFk', + type: 'number' + }, + { + arg: 'transferorFk', + type: 'number' + }, { arg: 'hasToInvoiceByAddress', type: 'boolean' diff --git a/modules/client/back/model-config.json b/modules/client/back/model-config.json index cdb54f6b69..340ddeb18d 100644 --- a/modules/client/back/model-config.json +++ b/modules/client/back/model-config.json @@ -83,6 +83,12 @@ "SmsConfig": { "dataSource": "vn" }, + "SageTaxType": { + "dataSource": "vn" + }, + "SageTransactionType": { + "dataSource": "vn" + }, "TpvError": { "dataSource": "vn" }, diff --git a/modules/client/back/models/client.json b/modules/client/back/models/client.json index 631fce3aa1..b4682579af 100644 --- a/modules/client/back/models/client.json +++ b/modules/client/back/models/client.json @@ -118,6 +118,18 @@ }, "created": { "type": "Date" + }, + "sageTaxTypeFk": { + "type": "number", + "mysql": { + "columnName": "taxTypeSageFk" + } + }, + "sageTransactionTypeFk": { + "type": "number", + "mysql": { + "columnName": "transactionTypeSageFk" + } } }, "relations": { @@ -200,6 +212,20 @@ "type": "hasOne", "model": "ClaimRatio", "foreignKey": "clientFk" + }, + "transferor": { + "type": "belongsTo", + "model": "Client", + "foreignKey": "transferorFk" } - } + }, + "scopes": { + "isActive": { + "where": { + "isActive": { + "neq": false + } + } + } + } } \ No newline at end of file diff --git a/modules/client/back/models/sage-tax-type.json b/modules/client/back/models/sage-tax-type.json new file mode 100644 index 0000000000..858627c054 --- /dev/null +++ b/modules/client/back/models/sage-tax-type.json @@ -0,0 +1,33 @@ +{ + "name": "SageTaxType", + "base": "VnModel", + "options": { + "mysql": { + "table": "sage.TiposIva" + } + }, + "properties": { + "id": { + "type": "Number", + "id": true, + "description": "Identifier", + "mysql": { + "columnName": "CodigoIva" + } + }, + "vat": { + "type": "string", + "mysql": { + "columnName": "Iva" + } + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] +} \ No newline at end of file diff --git a/modules/client/back/models/sage-transaction-type.json b/modules/client/back/models/sage-transaction-type.json new file mode 100644 index 0000000000..dbe8f3b39a --- /dev/null +++ b/modules/client/back/models/sage-transaction-type.json @@ -0,0 +1,33 @@ +{ + "name": "SageTransactionType", + "base": "VnModel", + "options": { + "mysql": { + "table": "sage.TiposTransacciones" + } + }, + "properties": { + "id": { + "type": "Number", + "id": true, + "description": "Identifier", + "mysql": { + "columnName": "CodigoTransaccion" + } + }, + "transaction": { + "type": "string", + "mysql": { + "columnName": "Transaccion" + } + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] +} \ No newline at end of file diff --git a/modules/client/front/fiscal-data/index.html b/modules/client/front/fiscal-data/index.html index b3789b34a4..9cd8f39f49 100644 --- a/modules/client/front/fiscal-data/index.html +++ b/modules/client/front/fiscal-data/index.html @@ -18,6 +18,18 @@ data="countries" order="country"> + + + +
@@ -44,6 +56,35 @@ rule> + + + + + + + + {{clientId}} ya tiene este teléfono o email.
¿Quieres continuar? \ No newline at end of file +Found a client with this phone or email: El cliente con id {{clientId}} ya tiene este teléfono o email.
¿Quieres continuar? +Sage tax type: Tipo de impuesto Sage +Sage transaction type: Tipo de transacción Sage +Previous client: Cliente anterior +In case of a company succession, specify the grantor company: En el caso de que haya habido una sucesión de empresa, indicar la empresa cedente \ No newline at end of file From 6412f2968580d82bdbc898f44e248c1b8ab43a04 Mon Sep 17 00:00:00 2001 From: joan Date: Fri, 16 Oct 2020 10:40:45 +0200 Subject: [PATCH 02/23] 2428 - Added anchor directive --- front/core/directives/anchor.js | 32 +++++++++++++++++++++++++++ front/core/directives/index.js | 1 + modules/client/front/index/index.html | 5 +++-- 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 front/core/directives/anchor.js diff --git a/front/core/directives/anchor.js b/front/core/directives/anchor.js new file mode 100644 index 0000000000..48c2da4937 --- /dev/null +++ b/front/core/directives/anchor.js @@ -0,0 +1,32 @@ +import ngModule from '../module'; + +/** + * Allows changing state for nested anchor + * + * @param {Object} $parse + * @param {Object} $state + * @return {Object} The directive + */ +export function directive($parse, $state) { + return { + restrict: 'A', + link: function($scope, $element, $attrs) { + const state = $scope.$eval($attrs.vnAnchor); + // const element = $element[0]; + $element.on('click', event => { + const params = []; + + for (let param in state.params) + console.log(param); + + // $state.go(state.url, state.params); + event.preventDefault(); + event.stopPropagation(); + }); + } + }; +} + +directive.$inject = ['$parse', '$state']; + +ngModule.directive('vnAnchor', directive); diff --git a/front/core/directives/index.js b/front/core/directives/index.js index af05c9b38e..e0f42aef56 100644 --- a/front/core/directives/index.js +++ b/front/core/directives/index.js @@ -15,3 +15,4 @@ import './smart-table'; import './droppable'; import './http-click'; import './http-submit'; +import './anchor'; diff --git a/modules/client/front/index/index.html b/modules/client/front/index/index.html index 7493ecacee..dc65d60252 100644 --- a/modules/client/front/index/index.html +++ b/modules/client/front/index/index.html @@ -40,8 +40,7 @@ vn-tooltip="Client frozen" icon="icon-frozen"> - @@ -51,6 +50,8 @@ icon="desktop_windows"> + +
From cf8ed6f8d3de07a42982611c476c939707da0b95 Mon Sep 17 00:00:00 2001 From: joan Date: Mon, 19 Oct 2020 07:35:24 +0200 Subject: [PATCH 03/23] Anchor directive functionality --- front/core/directives/anchor.js | 57 ++++++++++++++++++---- front/core/directives/specs/anchor.spec.js | 22 +++++++++ 2 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 front/core/directives/specs/anchor.spec.js diff --git a/front/core/directives/anchor.js b/front/core/directives/anchor.js index 48c2da4937..a0ae62a980 100644 --- a/front/core/directives/anchor.js +++ b/front/core/directives/anchor.js @@ -7,26 +7,63 @@ import ngModule from '../module'; * @param {Object} $state * @return {Object} The directive */ -export function directive($parse, $state) { +export function directive($state, $window) { + let ctrlPressed = false; + + $window.addEventListener('keydown', event => { + if (event.key == 'Control') + ctrlPressed = true; + }); + + $window.addEventListener('keyup', event => { + if (event.key == 'Control') + ctrlPressed = false; + }); + + function changeState(event, state) { + const params = stringifyParams(state); + $state.go(state.url, params); + + event.preventDefault(); + event.stopPropagation(); + } + + function newTab(event, state) { + const params = stringifyParams(state); + const url = $state.href(state.url, params); + $window.open(url); + + event.preventDefault(); + event.stopPropagation(); + } + + function stringifyParams(state) { + const params = Object.assign({}, state.params); + for (let param in params) + params[param] = JSON.stringify(params[param]); + + return params; + } + return { restrict: 'A', link: function($scope, $element, $attrs) { const state = $scope.$eval($attrs.vnAnchor); - // const element = $element[0]; $element.on('click', event => { - const params = []; + if (ctrlPressed) + newTab(event, state); + else + changeState(event, state); + }); - for (let param in state.params) - console.log(param); - - // $state.go(state.url, state.params); - event.preventDefault(); - event.stopPropagation(); + $element.on('mousedown', event => { + if (event.button == 1) + newTab(event, state); }); } }; } -directive.$inject = ['$parse', '$state']; +directive.$inject = ['$state', '$window']; ngModule.directive('vnAnchor', directive); diff --git a/front/core/directives/specs/anchor.spec.js b/front/core/directives/specs/anchor.spec.js new file mode 100644 index 0000000000..fc3c053b35 --- /dev/null +++ b/front/core/directives/specs/anchor.spec.js @@ -0,0 +1,22 @@ + +fdescribe('Directive vnAnchor', () => { + let $scope; + let $element; + let compile; + + beforeEach(ngModule('vnCore')); + + compile = _element => { + inject(($compile, $rootScope) => { + $scope = $rootScope.$new(); + $element = angular.element(_element); + $compile($element)($scope); + $scope.$digest(); + }); + }; + + it(`should throw an error when there's no id defined`, () => { + let html = ``; + compile(html); + }); +}); From 011bba16606101ad786087c3dfd0125f45ddde9c Mon Sep 17 00:00:00 2001 From: joan Date: Mon, 19 Oct 2020 09:05:38 +0200 Subject: [PATCH 04/23] Added vn-anchor to client and ticket index --- front/core/directives/anchor.js | 26 +++++++++---------- modules/client/front/descriptor/locale/es.yml | 3 ++- modules/client/front/index/index.html | 2 +- modules/ticket/front/index/index.html | 2 +- modules/ticket/front/index/index.js | 5 ---- modules/worker/front/index/index.html | 2 +- 6 files changed, 18 insertions(+), 22 deletions(-) diff --git a/front/core/directives/anchor.js b/front/core/directives/anchor.js index a0ae62a980..4b35f14752 100644 --- a/front/core/directives/anchor.js +++ b/front/core/directives/anchor.js @@ -20,25 +20,25 @@ export function directive($state, $window) { ctrlPressed = false; }); - function changeState(event, state) { - const params = stringifyParams(state); - $state.go(state.url, params); + function changeState(event, data) { + const params = stringifyParams(data); + $state.go(data.state, params); event.preventDefault(); event.stopPropagation(); } - function newTab(event, state) { - const params = stringifyParams(state); - const url = $state.href(state.url, params); - $window.open(url); + function newTab(event, data) { + const params = stringifyParams(data); + const href = $state.href(data.state, params); + $window.open(href); event.preventDefault(); event.stopPropagation(); } - function stringifyParams(state) { - const params = Object.assign({}, state.params); + function stringifyParams(data) { + const params = Object.assign({}, data.params); for (let param in params) params[param] = JSON.stringify(params[param]); @@ -48,17 +48,17 @@ export function directive($state, $window) { return { restrict: 'A', link: function($scope, $element, $attrs) { - const state = $scope.$eval($attrs.vnAnchor); + const data = $scope.$eval($attrs.vnAnchor); $element.on('click', event => { if (ctrlPressed) - newTab(event, state); + newTab(event, data); else - changeState(event, state); + changeState(event, data); }); $element.on('mousedown', event => { if (event.button == 1) - newTab(event, state); + newTab(event, data); }); } }; diff --git a/modules/client/front/descriptor/locale/es.yml b/modules/client/front/descriptor/locale/es.yml index 3f59aede8d..03cf17e7bf 100644 --- a/modules/client/front/descriptor/locale/es.yml +++ b/modules/client/front/descriptor/locale/es.yml @@ -1,4 +1,5 @@ Simple ticket: Ticket simple View consumer report: Ver informe de consumo From date: Fecha desde -To date: Fecha hasta \ No newline at end of file +To date: Fecha hasta +Go to user: Ir al usuario \ No newline at end of file diff --git a/modules/client/front/index/index.html b/modules/client/front/index/index.html index dc65d60252..3c64fe55fa 100644 --- a/modules/client/front/index/index.html +++ b/modules/client/front/index/index.html @@ -40,7 +40,7 @@ vn-tooltip="Client frozen" icon="icon-frozen"> - diff --git a/modules/ticket/front/index/index.html b/modules/ticket/front/index/index.html index e9066a41b9..902d1f5a47 100644 --- a/modules/ticket/front/index/index.html +++ b/modules/ticket/front/index/index.html @@ -119,7 +119,7 @@ diff --git a/modules/ticket/front/index/index.js b/modules/ticket/front/index/index.js index 32c2f0baac..cae9c403cc 100644 --- a/modules/ticket/front/index/index.js +++ b/modules/ticket/front/index/index.js @@ -114,11 +114,6 @@ export default class Controller extends Section { return 'warning'; } - goToLines(ticketFk) { - let url = this.$state.href('ticket.card.sale', {id: ticketFk}, {absolute: true}); - window.open(url, '_blank'); - } - preview(ticket) { this.selectedTicket = ticket; this.$.summary.show(); diff --git a/modules/worker/front/index/index.html b/modules/worker/front/index/index.html index 3d383ae040..c994e7a7b1 100644 --- a/modules/worker/front/index/index.html +++ b/modules/worker/front/index/index.html @@ -29,7 +29,7 @@ Date: Tue, 20 Oct 2020 07:43:36 +0200 Subject: [PATCH 05/23] Added unit test --- front/core/directives/anchor.js | 58 ++++++++++++---------- front/core/directives/specs/anchor.spec.js | 39 ++++++++++++--- modules/client/front/index/index.html | 2 - 3 files changed, 63 insertions(+), 36 deletions(-) diff --git a/front/core/directives/anchor.js b/front/core/directives/anchor.js index 4b35f14752..58d5a688fe 100644 --- a/front/core/directives/anchor.js +++ b/front/core/directives/anchor.js @@ -1,5 +1,32 @@ import ngModule from '../module'; +export function newTab($state, $window, event, data) { + const params = stringifyParams(data); + const href = $state.href(data.state, params); + $window.open(href); + + event.preventDefault(); + event.stopPropagation(); +} + +export function stringifyParams(data) { + console.log('stringifyParams', 'called'); + const params = Object.assign({}, data.params); + for (let param in params) + params[param] = JSON.stringify(params[param]); + + return params; +} + +export function changeState($state, event, data) { + // console.log('changeState called!'); + const params = stringifyParams(data); + $state.go(data.state, params); + + event.preventDefault(); + event.stopPropagation(); +} + /** * Allows changing state for nested anchor * @@ -20,40 +47,17 @@ export function directive($state, $window) { ctrlPressed = false; }); - function changeState(event, data) { - const params = stringifyParams(data); - $state.go(data.state, params); - - event.preventDefault(); - event.stopPropagation(); - } - - function newTab(event, data) { - const params = stringifyParams(data); - const href = $state.href(data.state, params); - $window.open(href); - - event.preventDefault(); - event.stopPropagation(); - } - - function stringifyParams(data) { - const params = Object.assign({}, data.params); - for (let param in params) - params[param] = JSON.stringify(params[param]); - - return params; - } - return { restrict: 'A', link: function($scope, $element, $attrs) { const data = $scope.$eval($attrs.vnAnchor); $element.on('click', event => { + // console.log('evento click'); + if (ctrlPressed) - newTab(event, data); + newTab($state, $window, event, data); else - changeState(event, data); + changeState($state, event, data); }); $element.on('mousedown', event => { diff --git a/front/core/directives/specs/anchor.spec.js b/front/core/directives/specs/anchor.spec.js index fc3c053b35..2eea2cac65 100644 --- a/front/core/directives/specs/anchor.spec.js +++ b/front/core/directives/specs/anchor.spec.js @@ -1,22 +1,47 @@ +// import {changeState} from '../anchor'; +import * as vnAnchor from '../anchor'; -fdescribe('Directive vnAnchor', () => { +xdescribe('Directive vnAnchor', () => { let $scope; - let $element; + let element; let compile; beforeEach(ngModule('vnCore')); - compile = _element => { + compile = (_element, _childElement) => { inject(($compile, $rootScope) => { $scope = $rootScope.$new(); - $element = angular.element(_element); - $compile($element)($scope); + element = angular.element(_element); + $compile(element)($scope); $scope.$digest(); + element = $element[0]; }); }; - it(`should throw an error when there's no id defined`, () => { - let html = ``; + xit(`should throw an error when there's no id defined`, () => { + let html = `
`; + jest.spyOn(anchor, 'changeState'); compile(html); + + // element[0].click(); + + element[0].changeState = anchor.changeState; + element[0].dispatchEvent(new Event('click')); + + expect(element[0].changeState).toHaveBeenCalledWith(); + }); + + xit(`changeState()`, () => { + jest.spyOn(vnAnchor, 'stringifyParams'); + + const $state = { + go: () => {} + }; + const $event = new Event('click'); + const data = {state: 'hey', params: {}}; + + vnAnchor.changeState($state, $event, data); + + expect(vnAnchor.stringifyParams).toHaveBeenCalledWith(); }); }); diff --git a/modules/client/front/index/index.html b/modules/client/front/index/index.html index 3c64fe55fa..abbbe60e51 100644 --- a/modules/client/front/index/index.html +++ b/modules/client/front/index/index.html @@ -50,8 +50,6 @@ icon="desktop_windows">
- - From 12bf0e6df74c86ee5375c4bc19ee28bb2781296f Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 20 Oct 2020 11:44:14 +0200 Subject: [PATCH 06/23] Credit insurance hotfix --- .../client/front/credit-insurance/insurance/create/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/client/front/credit-insurance/insurance/create/index.html b/modules/client/front/credit-insurance/insurance/create/index.html index f3de7fbe75..0a3189bd12 100644 --- a/modules/client/front/credit-insurance/insurance/create/index.html +++ b/modules/client/front/credit-insurance/insurance/create/index.html @@ -1,6 +1,6 @@ @@ -34,7 +34,7 @@ + ui-sref="client.card.creditInsurance.insurance.index({classificationId: $ctrl.$params.classificationId})"> \ No newline at end of file From f7e9372bf0681b6aa47e598f6ea1c42212c4e6d3 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 20 Oct 2020 14:54:23 +0200 Subject: [PATCH 07/23] 2525 - Change to past date --- .../00-ticket_componentPreview.sql | 107 ++++++++++++++++++ loopback/locale/en.json | 17 +-- loopback/locale/es.json | 13 ++- .../back/methods/ticket/componentUpdate.js | 68 ++++++++--- 4 files changed, 175 insertions(+), 30 deletions(-) create mode 100644 db/changes/10240-allSaints/00-ticket_componentPreview.sql diff --git a/db/changes/10240-allSaints/00-ticket_componentPreview.sql b/db/changes/10240-allSaints/00-ticket_componentPreview.sql new file mode 100644 index 0000000000..8f2a5e1ebf --- /dev/null +++ b/db/changes/10240-allSaints/00-ticket_componentPreview.sql @@ -0,0 +1,107 @@ +USE `vn`; +DROP procedure IF EXISTS `ticket_componentPreview`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `ticket_componentPreview`( + vTicketFk INT, + vLanded DATE, + vAddressFk INT, + vZoneFk INT, + vWarehouseFk SMALLINT) +BEGIN +/** + * Calcula los componentes de los articulos de un ticket + * + * @param vTicketFk id del ticket + * @param vLanded nueva fecha de entrega + * @param vAddressFk nuevo consignatario + * @param vZoneFk nueva zona + * @param vWarehouseFk nuevo warehouse + * + * @return tmp.ticketComponentPreview (warehouseFk, itemFk, componentFk, cost) + */ + DECLARE vHasDataChanged BOOL DEFAULT FALSE; + DECLARE vHasAddressChanged BOOL; + DECLARE vHasZoneChanged BOOL DEFAULT FALSE; + DECLARE vHasWarehouseChanged BOOL DEFAULT FALSE; + + DECLARE vShipped DATE; + DECLARE vAddressTypeRateFk INT DEFAULT NULL; + DECLARE vAgencyModeTypeRateFk INT DEFAULT NULL; + + DECLARE vHasChangeAll BOOL DEFAULT FALSE; + + SELECT DATE(landed) <> vLanded, + addressFk <> vAddressFk, + zoneFk <> vZoneFk, + warehouseFk <> vWarehouseFk + INTO + vHasDataChanged, + vHasAddressChanged, + vHasZoneChanged, + vHasWarehouseChanged + FROM vn.ticket t + WHERE t.id = vTicketFk; + + IF vHasDataChanged OR vHasWarehouseChanged THEN + SET vHasChangeAll = TRUE; + END IF; + + IF vHasAddressChanged THEN + SET vAddressTypeRateFk = 5; + END IF; + + IF vHasZoneChanged THEN + SET vAgencyModeTypeRateFk = 6; + END IF; + + SELECT TIMESTAMPADD(DAY, -travelingDays, vLanded) INTO vShipped + FROM zone + WHERE id = vZoneFk; + + CALL buyUltimate(vWarehouseFk, vShipped); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; + CREATE TEMPORARY TABLE tmp.ticketLot ENGINE = MEMORY ( + SELECT + vWarehouseFk AS warehouseFk, + NULL AS available, + s.itemFk, + bu.buyFk, + vZoneFk zoneFk + FROM sale s + LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk + WHERE s.ticketFk = vTicketFk + GROUP BY bu.warehouseFk, bu.itemFk); + + CALL catalog_componentPrepare(); + CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk); + + REPLACE INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost) + SELECT t.warehouseFk, s.itemFk, sc.componentFk, sc.value + FROM saleComponent sc + JOIN sale s ON s.id = sc.saleFk + JOIN ticket t ON t.id = s.ticketFk + JOIN `component` c ON c.id = sc.componentFk + WHERE s.ticketFk = vTicketFk + AND (c.isRenewable = FALSE + OR + (NOT vHasChangeAll + AND (NOT (c.typeFk <=> vAddressTypeRateFk + OR c.typeFk <=> vAgencyModeTypeRateFk)))); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentPreview; + CREATE TEMPORARY TABLE tmp.ticketComponentPreview + SELECT * FROM tmp.ticketComponent; + + CALL catalog_componentPurge(); + DROP TEMPORARY TABLE tmp.buyUltimate; + + IF vShipped IS NULL THEN + CALL util.throw('NO_ZONE_AVAILABLE'); + END IF; +END$$ + +DELIMITER ; + diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 04cc887b66..7243bccd51 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -57,12 +57,12 @@ "The postcode doesn't exist. Please enter a correct one": "The postcode doesn't exist. Please enter a correct one", "Can't create stowaway for this ticket": "Can't create stowaway for this ticket", "Swift / BIC can't be empty": "Swift / BIC can't be empty", - "MESSAGE_BOUGHT_UNITS": "Bought {{quantity}} units of {{concept}} (#{{itemId}}) for the ticket id [#{{ticketId}}]({{{url}}})", - "MESSAGE_INSURANCE_CHANGE": "I have changed the insurence credit of client [{{clientName}} (#{{clientId}})]({{{url}}}) to *{{credit}} €*", - "MESSAGE_CHANGED_PAYMETHOD": "I have changed the pay method for client [{{clientName}} (#{{clientId}})]({{{url}}})", - "Sent units from ticket": "I sent *{{quantity}}* units of [{{concept}} (#{{itemId}})]({{{itemUrl}}}) to *\"{{nickname}}\"* coming from ticket id [#{{ticketId}}]({{{ticketUrl}}})", - "Claim will be picked": "The product from the claim (#{{claimId}})]({{{claimUrl}}}) from the client *{{clientName}}* will be picked", - "This ticket is not an stowaway anymore": "The ticket id [#{{ticketId}}]({{{ticketUrl}}}) is not an stowaway anymore", + "MESSAGE_BOUGHT_UNITS": "Bought {{quantity}} units of {{concept}} ({{itemId}}) for the ticket id [{{ticketId}}]({{{url}}})", + "MESSAGE_INSURANCE_CHANGE": "I have changed the insurence credit of client [{{clientName}} ({{clientId}})]({{{url}}}) to *{{credit}} €*", + "MESSAGE_CHANGED_PAYMETHOD": "I have changed the pay method for client [{{clientName}} ({{clientId}})]({{{url}}})", + "Sent units from ticket": "I sent *{{quantity}}* units of [{{concept}} ({{itemId}})]({{{itemUrl}}}) to *\"{{nickname}}\"* coming from ticket id [{{ticketId}}]({{{ticketUrl}}})", + "Claim will be picked": "The product from the claim ({{claimId}})]({{{claimUrl}}}) from the client *{{clientName}}* will be picked", + "This ticket is not an stowaway anymore": "The ticket id [{{ticketId}}]({{{ticketUrl}}}) is not an stowaway anymore", "Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member", "Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member", "Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}", @@ -70,6 +70,7 @@ "NOT_ZONE_WITH_THIS_PARAMETERS": "There's no zone available for this day", "Created absence": "The worker {{author}} has added an absence of type '{{absenceType}}' to {{employee}} for day {{dated}}.", "Deleted absence": "The worker {{author}} has deleted an absence of type '{{absenceType}}' to {{employee}} for day {{dated}}.", - "I have deleted the ticket id": "I have deleted the ticket id [#{{id}}]({{{url}}})", - "I have restored the ticket id": "I have restored the ticket id [#{{id}}]({{{url}}})" + "I have deleted the ticket id": "I have deleted the ticket id [{{id}}]({{{url}}})", + "I have restored the ticket id": "I have restored the ticket id [{{id}}]({{{url}}})", + "Changed this data from the ticket": "I have changed the data from the ticket [{{ticketId}}]({{{ticketUrl}}}): ```{{{changes}}}```" } \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index db17262b42..4a2d48d5e0 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -121,12 +121,12 @@ "Swift / BIC can't be empty": "Swift / BIC no puede estar vacío", "Customs agent is required for a non UEE member": "El agente de aduanas es requerido para los clientes extracomunitarios", "Incoterms is required for a non UEE member": "El incoterms es requerido para los clientes extracomunitarios", - "MESSAGE_BOUGHT_UNITS": "Se ha comprado {{quantity}} unidades de {{concept}} (#{{itemId}}) para el ticket id [#{{ticketId}}]({{{url}}})", + "MESSAGE_BOUGHT_UNITS": "Se ha comprado {{quantity}} unidades de {{concept}} (#{{itemId}}) para el ticket id [{{ticketId}}]({{{url}}})", "MESSAGE_INSURANCE_CHANGE": "He cambiado el crédito asegurado del cliente [{{clientName}} (#{{clientId}})]({{{url}}}) a *{{credit}} €*", "MESSAGE_CHANGED_PAYMETHOD": "He cambiado la forma de pago del cliente [{{clientName}} (#{{clientId}})]({{{url}}})", - "Sent units from ticket": "Envio *{{quantity}}* unidades de [{{concept}} (#{{itemId}})]({{{itemUrl}}}) a *\"{{nickname}}\"* provenientes del ticket id [#{{ticketId}}]({{{ticketUrl}}})", + "Sent units from ticket": "Envio *{{quantity}}* unidades de [{{concept}} (#{{itemId}})]({{{itemUrl}}}) a *\"{{nickname}}\"* provenientes del ticket id [{{ticketId}}]({{{ticketUrl}}})", "Claim will be picked": "Se recogerá el género de la reclamación (#{{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}*", - "This ticket is not an stowaway anymore": "El ticket id [#{{ticketId}}]({{{ticketUrl}}}) ha dejado de ser un polizón", + "This ticket is not an stowaway anymore": "El ticket id [{{ticketId}}]({{{ticketUrl}}}) ha dejado de ser un polizón", "Client checked as validated despite of duplication": "Cliente comprobado a pesar de que existe el cliente id {{clientId}}", "ORDER_ROW_UNAVAILABLE": "No hay disponibilidad de este producto", "Distance must be lesser than 1000": "La distancia debe ser inferior a 1000", @@ -146,7 +146,8 @@ "Absence change notification on the labour calendar": "Notificacion de cambio de ausencia en el calendario laboral", "Created absence": "El empleado {{author}} ha añadido una ausencia de tipo '{{absenceType}}' a {{employee}} para el día {{dated}}.", "Deleted absence": "El empleado {{author}} ha eliminado una ausencia de tipo '{{absenceType}}' a {{employee}} del día {{dated}}.", - "I have deleted the ticket id": "He eliminado el ticket id [#{{id}}]({{{url}}})", - "I have restored the ticket id": "He restaurado el ticket id [#{{id}}]({{{url}}})", - "You can only restore a ticket within the first hour after deletion": "Únicamente puedes restaurar el ticket dentro de la primera hora después de su eliminación" + "I have deleted the ticket id": "He eliminado el ticket id [{{id}}]({{{url}}})", + "I have restored the ticket id": "He restaurado el ticket id [{{id}}]({{{url}}})", + "You can only restore a ticket within the first hour after deletion": "Únicamente puedes restaurar el ticket dentro de la primera hora después de su eliminación", + "Changed this data from the ticket": "He cambiado estos datos del ticket [{{ticketId}}]({{{ticketUrl}}}): ```{{{changes}}}```" } \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/componentUpdate.js b/modules/ticket/back/methods/ticket/componentUpdate.js index 15cfa05975..1899f6ab7d 100644 --- a/modules/ticket/back/methods/ticket/componentUpdate.js +++ b/modules/ticket/back/methods/ticket/componentUpdate.js @@ -76,6 +76,7 @@ module.exports = Self => { companyFk, shipped, landed, isDeleted, option) => { const userId = ctx.req.accessToken.userId; const models = Self.app.models; + const $t = ctx.req.__; // $translate const isEditable = await models.Ticket.isEditable(ctx, id); if (!isEditable) @@ -88,29 +89,26 @@ module.exports = Self => { if (!zoneShipped || zoneShipped.zoneFk != zoneFk) throw new UserError(`You don't have privileges to change the zone`); } - const originalTicket = await models.Ticket.findById(id, {fields: - ['id', 'clientFk', 'agencyModeFk', 'addressFk', 'zoneFk', + const originalTicket = await models.Ticket.findById(id, { + include: { + relation: 'client', + scope: { + fields: 'salesPersonFk' + } + }, + fields: ['id', 'clientFk', 'agencyModeFk', 'addressFk', 'zoneFk', 'warehouseFk', 'companyFk', 'shipped', 'landed', 'isDeleted'] }); const updatedTicket = Object.assign({}, ctx.args); delete updatedTicket.ctx; delete updatedTicket.option; + // Force unroute const hasToBeUnrouted = true; - const propertiesChange = diff(originalTicket, updatedTicket); + const changedProperties = diff(originalTicket, updatedTicket); - let logRecord = { - originFk: id, - userFk: userId, - action: 'update', - changedModel: 'Ticket', - changedModelId: id, - oldInstance: originalTicket, - newInstance: propertiesChange - }; - - let query = 'CALL vn.ticket_componentMakeUpdate(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; - let res = await Self.rawSql(query, [ + const query = 'CALL vn.ticket_componentMakeUpdate(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + const res = await Self.rawSql(query, [ id, clientFk, agencyModeFk, @@ -125,7 +123,45 @@ module.exports = Self => { option ]); - await models.TicketLog.create(logRecord); + await models.TicketLog.create({ + originFk: id, + userFk: userId, + action: 'update', + changedModel: 'Ticket', + changedModelId: id, + oldInstance: originalTicket, + newInstance: changedProperties + }); + + const salesPersonId = originalTicket.client().salesPersonFk; + if (salesPersonId) { + const origin = ctx.req.headers.origin; + + let changesMade = ''; + for (let change in changedProperties) { + let value = changedProperties[change]; + if (value instanceof Date) { + value = new Intl.DateTimeFormat('es', { + year: '2-digit', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + second: '2-digit' + }).format(value); + } + + changesMade += `${change}: ${value}\r\n`; + } + + const message = $t('Changed this data from the ticket', { + ticketId: id, + ticketUrl: `${origin}/#!/ticket/${id}/summary`, + changes: changesMade + }); + await models.Chat.send(ctx, '@joan', message); + } + return res; }; }; From 611e1a38027824bc5b7842ab3216dfc84208bfac Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 20 Oct 2020 15:01:02 +0200 Subject: [PATCH 08/23] Updated unit test --- .../back/methods/ticket/specs/componentUpdate.spec.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js index 8954e6d479..55dd29c165 100644 --- a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js +++ b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js @@ -42,7 +42,14 @@ describe('ticket componentUpdate()', () => { let ctx = { args: {clientFk: 102, agencyModeFk: 8}, - req: {accessToken: {userId: 101}}}; + req: { + accessToken: {userId: 101}, + headers: {origin: 'http://localhost'}, + __: (value, params) => { + return params.nickname; + } + } + }; await app.models.Ticket.componentUpdate(ctx, ticketId, clientId, agencyModeId, addressId, zoneId, warehouseId, companyId, shipped, landed, isDeleted, option); From 86d3e2d689c373696d95d078997aec5cad5af2dd Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 20 Oct 2020 16:03:07 +0200 Subject: [PATCH 09/23] Changed message destinatary --- modules/ticket/back/methods/ticket/componentUpdate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/componentUpdate.js b/modules/ticket/back/methods/ticket/componentUpdate.js index 1899f6ab7d..9010fc3aca 100644 --- a/modules/ticket/back/methods/ticket/componentUpdate.js +++ b/modules/ticket/back/methods/ticket/componentUpdate.js @@ -159,7 +159,7 @@ module.exports = Self => { ticketUrl: `${origin}/#!/ticket/${id}/summary`, changes: changesMade }); - await models.Chat.send(ctx, '@joan', message); + await models.Chat.sendCheckingPresence(ctx, salesPersonId, message); } return res; From 392bb420c6f716f21a4356597e0182252162075c Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Wed, 21 Oct 2020 09:29:42 +0200 Subject: [PATCH 10/23] updated client.fiscalData e2e path --- e2e/helpers/selectors.js | 3 +++ .../02-client/03_edit_fiscal_data.spec.js | 21 +++++++++++++++++++ package.json | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 3bcce51a26..a2ce49b8d4 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -83,6 +83,9 @@ export default { equalizationTaxCheckbox: 'vn-client-fiscal-data vn-check[ng-model="$ctrl.client.isEqualizated"]', address: 'vn-client-fiscal-data vn-textfield[ng-model="$ctrl.client.street"]', postcode: 'vn-client-fiscal-data vn-datalist[ng-model="$ctrl.client.postcode"]', + sageTax: 'vn-client-fiscal-data vn-autocomplete[ng-model="$ctrl.client.sageTaxTypeFk"]', + sageTransaction: 'vn-client-fiscal-data vn-autocomplete[ng-model="$ctrl.client.sageTransactionTypeFk"]', + transferor: 'vn-client-fiscal-data vn-autocomplete[ng-model="$ctrl.client.transferorFk"]', city: 'vn-client-fiscal-data vn-datalist[ng-model="$ctrl.client.city"]', province: 'vn-client-fiscal-data vn-autocomplete[ng-model="$ctrl.client.provinceFk"]', country: 'vn-client-fiscal-data vn-autocomplete[ng-model="$ctrl.client.countryFk"]', diff --git a/e2e/paths/02-client/03_edit_fiscal_data.spec.js b/e2e/paths/02-client/03_edit_fiscal_data.spec.js index b2279062a8..774f56b219 100644 --- a/e2e/paths/02-client/03_edit_fiscal_data.spec.js +++ b/e2e/paths/02-client/03_edit_fiscal_data.spec.js @@ -66,6 +66,9 @@ describe('Client Edit fiscalData path', () => { await page.autocompleteSearch(selectors.clientFiscalData.province, 'Province one'); await page.clearInput(selectors.clientFiscalData.city); await page.write(selectors.clientFiscalData.city, 'Valencia'); + await page.autocompleteSearch(selectors.clientFiscalData.sageTax, 'operaciones no sujetas'); + await page.autocompleteSearch(selectors.clientFiscalData.sageTransaction, 'regularización de inversiones'); + await page.autocompleteSearch(selectors.clientFiscalData.transferor, 'Max Eisenhardt'); await page.clearInput(selectors.clientFiscalData.postcode); await page.write(selectors.clientFiscalData.postcode, '46000'); await page.waitToClick(selectors.clientFiscalData.activeCheckbox); @@ -188,6 +191,24 @@ describe('Client Edit fiscalData path', () => { expect(result).toContain('46000'); }); + it('should confirm the sageTax have been edited', async() => { + const result = await page.waitToGetProperty(selectors.clientFiscalData.sageTax, 'value'); + + expect(result).toEqual('Operaciones no sujetas'); + }); + + it('should confirm the sageTransaction have been edited', async() => { + const result = await page.waitToGetProperty(selectors.clientFiscalData.sageTransaction, 'value'); + + expect(result).toEqual('Regularización de inversiones'); + }); + + it('should confirm the transferor have been edited', async() => { + const result = await page.waitToGetProperty(selectors.clientFiscalData.transferor, 'value'); + + expect(result).toEqual('Max Eisenhardt'); + }); + it('should confirm the city have been autocompleted', async() => { const result = await page.waitToGetProperty(selectors.clientFiscalData.city, 'value'); diff --git a/package.json b/package.json index 69d1111173..5840384e4c 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "babel-preset-es2015": "^6.24.1", "css-loader": "^2.1.0", "del": "^2.2.2", - "eslint": "^5.14.0", + "eslint": "^7.11.0", "eslint-config-google": "^0.11.0", "eslint-plugin-jasmine": "^2.10.1", "fancy-log": "^1.3.2", From adfeb2c358cf08194b34b1b21c134bfadd348963 Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 21 Oct 2020 10:26:28 +0200 Subject: [PATCH 11/23] Updated directive --- front/core/directives/anchor.js | 31 +++++++------- front/core/directives/specs/anchor.spec.js | 47 ---------------------- 2 files changed, 14 insertions(+), 64 deletions(-) delete mode 100644 front/core/directives/specs/anchor.spec.js diff --git a/front/core/directives/anchor.js b/front/core/directives/anchor.js index 58d5a688fe..9a079affdf 100644 --- a/front/core/directives/anchor.js +++ b/front/core/directives/anchor.js @@ -1,16 +1,6 @@ import ngModule from '../module'; -export function newTab($state, $window, event, data) { - const params = stringifyParams(data); - const href = $state.href(data.state, params); - $window.open(href); - - event.preventDefault(); - event.stopPropagation(); -} - export function stringifyParams(data) { - console.log('stringifyParams', 'called'); const params = Object.assign({}, data.params); for (let param in params) params[param] = JSON.stringify(params[param]); @@ -19,7 +9,6 @@ export function stringifyParams(data) { } export function changeState($state, event, data) { - // console.log('changeState called!'); const params = stringifyParams(data); $state.go(data.state, params); @@ -27,11 +16,20 @@ export function changeState($state, event, data) { event.stopPropagation(); } +export function openNewTab($state, $window, event, data) { + const params = stringifyParams(data); + const href = $state.href(data.state, params); + $window.open(href); + + event.preventDefault(); + event.stopPropagation(); +} + /** * Allows changing state for nested anchor * - * @param {Object} $parse * @param {Object} $state + * @param {Object} $window * @return {Object} The directive */ export function directive($state, $window) { @@ -52,17 +50,16 @@ export function directive($state, $window) { link: function($scope, $element, $attrs) { const data = $scope.$eval($attrs.vnAnchor); $element.on('click', event => { - // console.log('evento click'); - if (ctrlPressed) - newTab($state, $window, event, data); + openNewTab($state, $window, event, data); else changeState($state, event, data); }); $element.on('mousedown', event => { - if (event.button == 1) - newTab(event, data); + const mouseWheel = 1; + if (event.button == mouseWheel) + openNewTab($state, $window, event, data); }); } }; diff --git a/front/core/directives/specs/anchor.spec.js b/front/core/directives/specs/anchor.spec.js deleted file mode 100644 index 2eea2cac65..0000000000 --- a/front/core/directives/specs/anchor.spec.js +++ /dev/null @@ -1,47 +0,0 @@ -// import {changeState} from '../anchor'; -import * as vnAnchor from '../anchor'; - -xdescribe('Directive vnAnchor', () => { - let $scope; - let element; - let compile; - - beforeEach(ngModule('vnCore')); - - compile = (_element, _childElement) => { - inject(($compile, $rootScope) => { - $scope = $rootScope.$new(); - element = angular.element(_element); - $compile(element)($scope); - $scope.$digest(); - element = $element[0]; - }); - }; - - xit(`should throw an error when there's no id defined`, () => { - let html = `
`; - jest.spyOn(anchor, 'changeState'); - compile(html); - - // element[0].click(); - - element[0].changeState = anchor.changeState; - element[0].dispatchEvent(new Event('click')); - - expect(element[0].changeState).toHaveBeenCalledWith(); - }); - - xit(`changeState()`, () => { - jest.spyOn(vnAnchor, 'stringifyParams'); - - const $state = { - go: () => {} - }; - const $event = new Event('click'); - const data = {state: 'hey', params: {}}; - - vnAnchor.changeState($state, $event, data); - - expect(vnAnchor.stringifyParams).toHaveBeenCalledWith(); - }); -}); From c87783b4468784d1d3eddcad29951d9b04c04e70 Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 21 Oct 2020 13:25:52 +0200 Subject: [PATCH 12/23] 2528 - Rocket notifications hotfix --- back/methods/chat/sendCheckingPresence.js | 18 ++++++++++-------- loopback/locale/en.json | 10 +++++++++- loopback/locale/es.json | 11 +++++++++-- .../back/methods/ticket/componentUpdate.js | 4 +++- .../ticket/specs/componentUpdate.spec.js | 12 +++++++++--- 5 files changed, 40 insertions(+), 15 deletions(-) diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index 6fa029b702..cfae728569 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -3,7 +3,7 @@ module.exports = Self => { description: 'Sends a RocketChat message to a working worker or department channel', accessType: 'WRITE', accepts: [{ - arg: 'workerId', + arg: 'recipientId', type: 'Number', required: true, description: 'The worker id of the destinatary' @@ -23,21 +23,23 @@ module.exports = Self => { } }); - Self.sendCheckingPresence = async(ctx, workerId, message) => { - if (!workerId) return false; + Self.sendCheckingPresence = async(ctx, recipientId, message) => { + if (!recipientId) return false; const models = Self.app.models; - const account = await models.Account.findById(workerId); + const account = await models.Account.findById(recipientId); const userId = ctx.req.accessToken.userId; + if (recipientId == userId) return false; + if (!account) - throw new Error(`Could not send message "${message}" to worker id ${workerId} from user ${userId}`); + throw new Error(`Could not send message "${message}" to worker id ${recipientId} from user ${userId}`); const query = `SELECT worker_isWorking(?) isWorking`; - const [result] = await Self.rawSql(query, [workerId]); + const [result] = await Self.rawSql(query, [recipientId]); if (!result.isWorking) { - const workerDepartment = await models.WorkerDepartment.findById(workerId, { + const workerDepartment = await models.WorkerDepartment.findById(recipientId, { include: { relation: 'department' } @@ -46,7 +48,7 @@ module.exports = Self => { const channelName = department && department.chatName; if (channelName) - return Self.send(ctx, `#${channelName}`, `@${account.name} => ${message}`); + return Self.send(ctx, `#${channelName}`, `@${account.name} ➔ ${message}`); } return Self.send(ctx, `@${account.name}`, message); diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 7243bccd51..4986358326 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -72,5 +72,13 @@ "Deleted absence": "The worker {{author}} has deleted an absence of type '{{absenceType}}' to {{employee}} for day {{dated}}.", "I have deleted the ticket id": "I have deleted the ticket id [{{id}}]({{{url}}})", "I have restored the ticket id": "I have restored the ticket id [{{id}}]({{{url}}})", - "Changed this data from the ticket": "I have changed the data from the ticket [{{ticketId}}]({{{ticketUrl}}}): ```{{{changes}}}```" + "Changed this data from the ticket": "I have changed the data from the ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", + "agencyModeFk": "Agency", + "clientFk": "Client", + "zoneFk": "Zone", + "warehouseFk": "Warehouse", + "shipped": "Shipped", + "landed": "Landed", + "addressFk": "Address", + "companyFk": "Company" } \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 4a2d48d5e0..3fcac3d58d 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -140,7 +140,6 @@ "Role already assigned": "Role already assigned", "Invalid role name": "Invalid role name", "Role name must be written in camelCase": "Role name must be written in camelCase", - "can't be set": "can't be set", "Email already exists": "Email already exists", "User already exists": "User already exists", "Absence change notification on the labour calendar": "Notificacion de cambio de ausencia en el calendario laboral", @@ -149,5 +148,13 @@ "I have deleted the ticket id": "He eliminado el ticket id [{{id}}]({{{url}}})", "I have restored the ticket id": "He restaurado el ticket id [{{id}}]({{{url}}})", "You can only restore a ticket within the first hour after deletion": "Únicamente puedes restaurar el ticket dentro de la primera hora después de su eliminación", - "Changed this data from the ticket": "He cambiado estos datos del ticket [{{ticketId}}]({{{ticketUrl}}}): ```{{{changes}}}```" + "Changed this data from the ticket": "He cambiado estos datos del ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", + "agencyModeFk": "Agencia", + "clientFk": "Cliente", + "zoneFk": "Zona", + "warehouseFk": "Almacén", + "shipped": "F. envío", + "landed": "F. entrega", + "addressFk": "Consignatario", + "companyFk": "Empresa" } \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/componentUpdate.js b/modules/ticket/back/methods/ticket/componentUpdate.js index 9010fc3aca..91d867a305 100644 --- a/modules/ticket/back/methods/ticket/componentUpdate.js +++ b/modules/ticket/back/methods/ticket/componentUpdate.js @@ -140,6 +140,7 @@ module.exports = Self => { let changesMade = ''; for (let change in changedProperties) { let value = changedProperties[change]; + let oldValue = originalTicket[change]; if (value instanceof Date) { value = new Intl.DateTimeFormat('es', { year: '2-digit', @@ -149,9 +150,10 @@ module.exports = Self => { minute: '2-digit', second: '2-digit' }).format(value); + oldValue = value; } - changesMade += `${change}: ${value}\r\n`; + changesMade += `\r\n~${$t(change)}: ${value}~ ➔ *${$t(change)}: ${oldValue}*`; } const message = $t('Changed this data from the ticket', { diff --git a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js index 55dd29c165..256def165d 100644 --- a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js +++ b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js @@ -45,8 +45,8 @@ describe('ticket componentUpdate()', () => { req: { accessToken: {userId: 101}, headers: {origin: 'http://localhost'}, - __: (value, params) => { - return params.nickname; + __: value => { + return value; } } }; @@ -79,7 +79,13 @@ describe('ticket componentUpdate()', () => { let ctx = { args: {clientFk: 102, agencyModeFk: 7}, - req: {accessToken: {userId: 101}}}; + req: { + accessToken: {userId: 101}, + headers: {origin: 'http://localhost'}, + __: value => { + return value; + } + }}; await app.models.Ticket.componentUpdate(ctx, ticketId, clientId, agencyModeId, addressId, zoneId, warehouseId, companyId, shipped, landed, isDeleted, option); From 628154b7e89601c4c5f8cb9fca53fae19196f26d Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 21 Oct 2020 13:40:54 +0200 Subject: [PATCH 13/23] Trigger jenkins --- modules/ticket/back/methods/ticket/componentUpdate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/componentUpdate.js b/modules/ticket/back/methods/ticket/componentUpdate.js index 91d867a305..3edecbd614 100644 --- a/modules/ticket/back/methods/ticket/componentUpdate.js +++ b/modules/ticket/back/methods/ticket/componentUpdate.js @@ -103,7 +103,7 @@ module.exports = Self => { delete updatedTicket.ctx; delete updatedTicket.option; - // Force unroute + // Force to unroute ticket const hasToBeUnrouted = true; const changedProperties = diff(originalTicket, updatedTicket); From 537d61e27ec860ff73f0f3008e73b52a5795f2f6 Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 21 Oct 2020 13:53:46 +0200 Subject: [PATCH 14/23] Updated locale --- loopback/locale/es.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 3fcac3d58d..c3fe287eb9 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -121,11 +121,11 @@ "Swift / BIC can't be empty": "Swift / BIC no puede estar vacío", "Customs agent is required for a non UEE member": "El agente de aduanas es requerido para los clientes extracomunitarios", "Incoterms is required for a non UEE member": "El incoterms es requerido para los clientes extracomunitarios", - "MESSAGE_BOUGHT_UNITS": "Se ha comprado {{quantity}} unidades de {{concept}} (#{{itemId}}) para el ticket id [{{ticketId}}]({{{url}}})", - "MESSAGE_INSURANCE_CHANGE": "He cambiado el crédito asegurado del cliente [{{clientName}} (#{{clientId}})]({{{url}}}) a *{{credit}} €*", - "MESSAGE_CHANGED_PAYMETHOD": "He cambiado la forma de pago del cliente [{{clientName}} (#{{clientId}})]({{{url}}})", - "Sent units from ticket": "Envio *{{quantity}}* unidades de [{{concept}} (#{{itemId}})]({{{itemUrl}}}) a *\"{{nickname}}\"* provenientes del ticket id [{{ticketId}}]({{{ticketUrl}}})", - "Claim will be picked": "Se recogerá el género de la reclamación (#{{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}*", + "MESSAGE_BOUGHT_UNITS": "Se ha comprado {{quantity}} unidades de {{concept}} ({{itemId}}) para el ticket id [{{ticketId}}]({{{url}}})", + "MESSAGE_INSURANCE_CHANGE": "He cambiado el crédito asegurado del cliente [{{clientName}} ({{clientId}})]({{{url}}}) a *{{credit}} €*", + "MESSAGE_CHANGED_PAYMETHOD": "He cambiado la forma de pago del cliente [{{clientName}} ({{clientId}})]({{{url}}})", + "Sent units from ticket": "Envio *{{quantity}}* unidades de [{{concept}} ({{itemId}})]({{{itemUrl}}}) a *\"{{nickname}}\"* provenientes del ticket id [{{ticketId}}]({{{ticketUrl}}})", + "Claim will be picked": "Se recogerá el género de la reclamación ({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}*", "This ticket is not an stowaway anymore": "El ticket id [{{ticketId}}]({{{ticketUrl}}}) ha dejado de ser un polizón", "Client checked as validated despite of duplication": "Cliente comprobado a pesar de que existe el cliente id {{clientId}}", "ORDER_ROW_UNAVAILABLE": "No hay disponibilidad de este producto", From d3532608e13c2c61cd3b4bd9e8ee986fa5a1579f Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 21 Oct 2020 14:05:14 +0200 Subject: [PATCH 15/23] Changed oldValue --- .../ticket/back/methods/ticket/componentUpdate.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/ticket/back/methods/ticket/componentUpdate.js b/modules/ticket/back/methods/ticket/componentUpdate.js index 3edecbd614..6947cdc3b7 100644 --- a/modules/ticket/back/methods/ticket/componentUpdate.js +++ b/modules/ticket/back/methods/ticket/componentUpdate.js @@ -150,10 +150,20 @@ module.exports = Self => { minute: '2-digit', second: '2-digit' }).format(value); - oldValue = value; } - changesMade += `\r\n~${$t(change)}: ${value}~ ➔ *${$t(change)}: ${oldValue}*`; + if (oldValue instanceof Date) { + oldValue = new Intl.DateTimeFormat('es', { + year: '2-digit', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + second: '2-digit' + }).format(oldValue); + } + + changesMade += `\r\n~${$t(change)}: ${oldValue}~ ➔ *${$t(change)}: ${value}*`; } const message = $t('Changed this data from the ticket', { From da68ab3ffc6feddba7b42059e5901587b5f2d342 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Wed, 21 Oct 2020 14:25:40 +0200 Subject: [PATCH 16/23] client credit insurance e2e path --- e2e/helpers/extensions.js | 12 ++--- e2e/helpers/selectors.js | 8 +++ .../02-client/20_credit_insurance.spec.js | 51 +++++++++++++++++++ 3 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 e2e/paths/02-client/20_credit_insurance.spec.js diff --git a/e2e/helpers/extensions.js b/e2e/helpers/extensions.js index a3c52748df..5413733ee8 100644 --- a/e2e/helpers/extensions.js +++ b/e2e/helpers/extensions.js @@ -399,16 +399,16 @@ let actions = { pickDate: async function(selector, date) { date = date || new Date(); - const tzoffset = date.getTimezoneOffset() * 60000; - const localIso = (new Date(date.getTime() - tzoffset)) - .toISOString(); + const timeZoneOffset = date.getTimezoneOffset() * 60000; + const localDate = (new Date(date.getTime() - timeZoneOffset)) + .toISOString().substr(0, 10); await this.wait(selector); - await this.evaluate((selector, localIso) => { + await this.evaluate((selector, localDate) => { let input = document.querySelector(selector).$ctrl.input; - input.value = localIso.substr(0, 10); + input.value = localDate; input.dispatchEvent(new Event('change')); - }, selector, localIso); + }, selector, localDate); }, pickTime: async function(selector, time) { diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index a2ce49b8d4..10dd56c38a 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -202,6 +202,14 @@ export default { firstDocWorker: 'vn-client-dms-index vn-td:nth-child(8) > span', firstDocWorkerDescriptor: '.vn-popover.shown vn-worker-descriptor' }, + clientCreditInsurance: { + addNewContract: 'vn-client-credit-insurance-index vn-float-button[ui-sref="client.card.creditInsurance.create"]', + newCredit: 'vn-client-credit-insurance-create vn-input-number[ng-model="$ctrl.creditClassification.credit"]', + newGrade: 'vn-client-credit-insurance-create vn-input-number[ng-model="$ctrl.creditClassification.grade"]', + newStartingDate: 'vn-client-credit-insurance-create vn-date-picker[ng-model="$ctrl.creditClassification.started"]', + endCurrentContract: 'vn-client-credit-insurance-index vn-icon-button[icon="lock"]', + saveNewContract: 'vn-client-credit-insurance-create vn-submit' + }, clientContacts: { addContactButton: 'vn-client-contact vn-icon[icon="add_circle"]', name: 'vn-client-contact vn-textfield[ng-model="contact.name"]', diff --git a/e2e/paths/02-client/20_credit_insurance.spec.js b/e2e/paths/02-client/20_credit_insurance.spec.js new file mode 100644 index 0000000000..5ae56d52f8 --- /dev/null +++ b/e2e/paths/02-client/20_credit_insurance.spec.js @@ -0,0 +1,51 @@ +import selectors from '../../helpers/selectors.js'; +import getBrowser from '../../helpers/puppeteer'; + +describe('Client credit insurance path', () => { + let browser; + let page; + let previousMonth = new Date(); + previousMonth.setMonth(previousMonth.getMonth() - 1); + + beforeAll(async() => { + browser = await getBrowser(); + page = browser.page; + await page.loginAndModule('insurance', 'client'); + await page.accessToSearchResult('Tony Stark'); + await page.accessToSection('client.card.creditInsurance.index'); + }); + + afterAll(async() => { + await browser.close(); + }); + + it('should open the create a new credit contract form', async() => { + await page.waitToClick(selectors.clientCreditInsurance.addNewContract); + await page.waitForState('client.card.creditInsurance.create'); + }); + + it('should create a new credit contract', async() => { + await page.write(selectors.clientCreditInsurance.newCredit, '1000'); + await page.write(selectors.clientCreditInsurance.newGrade, '1'); + await page.pickDate(selectors.clientCreditInsurance.newStartingDate, previousMonth); + await page.waitToClick(selectors.clientCreditInsurance.saveNewContract); + await page.waitForState('client.card.creditInsurance.index'); + }); + + it(`should verify the addNewContract button is not present since there's an active contract`, async() => { + await page.waitForSelector(selectors.clientCreditInsurance.addNewContract, {hidden: true}); + }); + + it(`should bring the current contract to an end`, async() => { + await page.waitToClick(selectors.clientCreditInsurance.endCurrentContract); + await page.waitToClick(selectors.globalItems.acceptButton); + }); + + it(`should verify the addNewContract button is now present since there's no active contract`, async() => { + await page.waitForSelector(selectors.clientCreditInsurance.addNewContract, {visible: true}); + }); + + it(`should verify the endCurrentContract button is not present since there's no active contract`, async() => { + await page.waitForSelector(selectors.clientCreditInsurance.endCurrentContract, {hidden: true}); + }); +}); From b5c5d78d3aaeb9cd040b9d2e3598ffb7e1820fec Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 21 Oct 2020 14:51:07 +0200 Subject: [PATCH 17/23] Param name hotfix --- back/methods/chat/sendCheckingPresence.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index cfae728569..8f682bb663 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -3,7 +3,7 @@ module.exports = Self => { description: 'Sends a RocketChat message to a working worker or department channel', accessType: 'WRITE', accepts: [{ - arg: 'recipientId', + arg: 'workerId', type: 'Number', required: true, description: 'The worker id of the destinatary' From 0466d50c005a0c7ff46c8f594ba68e552d05bfa8 Mon Sep 17 00:00:00 2001 From: joan Date: Thu, 22 Oct 2020 07:50:01 +0200 Subject: [PATCH 18/23] 2518 - Item tag search --- modules/item/front/tags/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/item/front/tags/index.html b/modules/item/front/tags/index.html index d353454510..900374eec0 100644 --- a/modules/item/front/tags/index.html +++ b/modules/item/front/tags/index.html @@ -41,7 +41,7 @@ Date: Thu, 22 Oct 2020 11:24:53 +0200 Subject: [PATCH 19/23] Added loggable utils --- .../chat/spec/sendCheckingPresence.spec.js | 2 +- loopback/util/log.js | 83 +++++++++++++++++++ .../back/methods/ticket/componentUpdate.js | 39 +++------ 3 files changed, 94 insertions(+), 30 deletions(-) create mode 100644 loopback/util/log.js diff --git a/back/methods/chat/spec/sendCheckingPresence.spec.js b/back/methods/chat/spec/sendCheckingPresence.spec.js index 1523cb1d04..4fbd368d4b 100644 --- a/back/methods/chat/spec/sendCheckingPresence.spec.js +++ b/back/methods/chat/spec/sendCheckingPresence.spec.js @@ -38,7 +38,7 @@ describe('chat sendCheckingPresence()', () => { expect(response.statusCode).toEqual(200); expect(response.message).toEqual('Fake notification sent'); - expect(chatModel.send).toHaveBeenCalledWith(ctx, '#cooler', '@HankPym => I changed something'); + expect(chatModel.send).toHaveBeenCalledWith(ctx, '#cooler', '@HankPym ➔ I changed something'); }); it(`should call to send() method with the worker username when the worker is working`, async() => { diff --git a/loopback/util/log.js b/loopback/util/log.js new file mode 100644 index 0000000000..59a4e46794 --- /dev/null +++ b/loopback/util/log.js @@ -0,0 +1,83 @@ +/** + * Translates to a readable values + * @param {Object} instance - The model or context instance + * @param {Object} changes - Object containing changes + */ +exports.translateValues = async(instance, changes) => { + const models = instance.app.models; + + function getRelation(instance, property) { + const relations = instance.definition.settings.relations; + for (let relationName in relations) { + const relation = relations[relationName]; + if (relation.foreignKey == property) + return relation; + } + + return; + } + + function getValue(rawData) { + const row = JSON.parse(JSON.stringify(rawData)); + for (column in row) + return row[column]; + } + + function formatDate(date) { + return new Intl.DateTimeFormat('es', { + year: '2-digit', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + second: '2-digit' + }).format(date); + } + + const properties = Object.assign({}, changes); + for (let property in properties) { + const relation = getRelation(instance, property); + const value = properties[property]; + + let finalValue = value; + if (relation) { + const model = relation.model; + const row = await models[model].findById(value, { + fields: ['alias', 'name', 'code', 'description'] + }); + const newValue = getValue(row); + if (newValue) finalValue = newValue; + } + + if (finalValue instanceof Date) + finalValue = formatDate(finalValue); + + properties[property] = finalValue; + } + + return properties; +}; + +/** + * Returns the changes between two objects + * @param {*} original - Original object + * @param {*} changes - New changes + * @return {Object} Old and new values + */ +exports.getChanges = (original, changes) => { + const oldChanges = {}; + const newChanges = {}; + for (let property in changes) { + if (changes[property] != original[property]) { + newChanges[property] = changes[property]; + + if (original[property] != undefined) + oldChanges[property] = original[property]; + } + } + + return { + old: oldChanges, + new: newChanges + }; +}; diff --git a/modules/ticket/back/methods/ticket/componentUpdate.js b/modules/ticket/back/methods/ticket/componentUpdate.js index 6947cdc3b7..557a76e2be 100644 --- a/modules/ticket/back/methods/ticket/componentUpdate.js +++ b/modules/ticket/back/methods/ticket/componentUpdate.js @@ -1,5 +1,5 @@ const UserError = require('vn-loopback/util/user-error'); -const diff = require('object-diff'); +const loggable = require('vn-loopback/util/log'); module.exports = Self => { Self.remoteMethodCtx('componentUpdate', { @@ -105,8 +105,6 @@ module.exports = Self => { // Force to unroute ticket const hasToBeUnrouted = true; - const changedProperties = diff(originalTicket, updatedTicket); - const query = 'CALL vn.ticket_componentMakeUpdate(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; const res = await Self.rawSql(query, [ id, @@ -123,14 +121,18 @@ module.exports = Self => { option ]); + const changes = loggable.getChanges(originalTicket, updatedTicket); + const oldProperties = await loggable.translateValues(Self, changes.old); + const newProperties = await loggable.translateValues(Self, changes.new); + await models.TicketLog.create({ originFk: id, userFk: userId, action: 'update', changedModel: 'Ticket', changedModelId: id, - oldInstance: originalTicket, - newInstance: changedProperties + oldInstance: oldProperties, + newInstance: newProperties }); const salesPersonId = originalTicket.client().salesPersonFk; @@ -138,30 +140,9 @@ module.exports = Self => { const origin = ctx.req.headers.origin; let changesMade = ''; - for (let change in changedProperties) { - let value = changedProperties[change]; - let oldValue = originalTicket[change]; - if (value instanceof Date) { - value = new Intl.DateTimeFormat('es', { - year: '2-digit', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - second: '2-digit' - }).format(value); - } - - if (oldValue instanceof Date) { - oldValue = new Intl.DateTimeFormat('es', { - year: '2-digit', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - second: '2-digit' - }).format(oldValue); - } + for (let change in newProperties) { + let value = newProperties[change]; + let oldValue = oldProperties[change]; changesMade += `\r\n~${$t(change)}: ${oldValue}~ ➔ *${$t(change)}: ${value}*`; } From 5e93e454529748cf8dbd91ad75461814ba6a4413 Mon Sep 17 00:00:00 2001 From: joan Date: Thu, 22 Oct 2020 12:01:45 +0200 Subject: [PATCH 20/23] Updated doc --- loopback/util/log.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/loopback/util/log.js b/loopback/util/log.js index 59a4e46794..cf12dcb2fb 100644 --- a/loopback/util/log.js +++ b/loopback/util/log.js @@ -60,8 +60,8 @@ exports.translateValues = async(instance, changes) => { /** * Returns the changes between two objects - * @param {*} original - Original object - * @param {*} changes - New changes + * @param {Object} original - Original object + * @param {Object} changes - New changes * @return {Object} Old and new values */ exports.getChanges = (original, changes) => { From 787b7df4afacb08b0d68f2ddf3df625614be9aa1 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Thu, 22 Oct 2020 14:33:51 +0200 Subject: [PATCH 21/23] e2e now check different type of grades --- e2e/helpers/selectors.js | 15 ++++-- .../02-client/20_credit_insurance.spec.js | 47 +++++++++++++++++-- 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 10dd56c38a..8cea469649 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -204,11 +204,18 @@ export default { }, clientCreditInsurance: { addNewContract: 'vn-client-credit-insurance-index vn-float-button[ui-sref="client.card.creditInsurance.create"]', - newCredit: 'vn-client-credit-insurance-create vn-input-number[ng-model="$ctrl.creditClassification.credit"]', - newGrade: 'vn-client-credit-insurance-create vn-input-number[ng-model="$ctrl.creditClassification.grade"]', - newStartingDate: 'vn-client-credit-insurance-create vn-date-picker[ng-model="$ctrl.creditClassification.started"]', + newCreditClassification: 'vn-client-credit-insurance-create vn-input-number[ng-model="$ctrl.creditClassification.credit"]', + newInsuranceCredit: 'vn-client-credit-insurance-insurance-create vn-input-number[ng-model="$ctrl.insurance.credit"]', + newClassificationGrade: 'vn-client-credit-insurance-create vn-input-number[ng-model="$ctrl.creditClassification.grade"]', + newInsuranceGrade: 'vn-client-credit-insurance-insurance-create vn-input-number[ng-model="$ctrl.insurance.grade"]', + newClassificationStartingDate: 'vn-client-credit-insurance-create vn-date-picker[ng-model="$ctrl.creditClassification.started"]', + newInsuranceStartingDate: 'vn-client-credit-insurance-insurance-create vn-date-picker[ng-model="$ctrl.insurance.created"]', endCurrentContract: 'vn-client-credit-insurance-index vn-icon-button[icon="lock"]', - saveNewContract: 'vn-client-credit-insurance-create vn-submit' + firstContratViewCreditButton: 'vn-client-credit-insurance-index vn-card > vn-horizontal:nth-child(1) vn-icon-button[icon="desktop_windows"]', + addNewCredit: 'vn-client-credit-insurance-insurance-index vn-float-button vn-icon[icon="add"]', + saveNewContract: 'vn-client-credit-insurance-create vn-submit', + saveNewInsuranceCredit: 'vn-client-credit-insurance-insurance-create button[type="submit"]', + anyCreditInsuranceLine: 'vn-client-credit-insurance-insurance-index vn-tbody > vn-tr', }, clientContacts: { addContactButton: 'vn-client-contact vn-icon[icon="add_circle"]', diff --git a/e2e/paths/02-client/20_credit_insurance.spec.js b/e2e/paths/02-client/20_credit_insurance.spec.js index 5ae56d52f8..278eb861a6 100644 --- a/e2e/paths/02-client/20_credit_insurance.spec.js +++ b/e2e/paths/02-client/20_credit_insurance.spec.js @@ -25,9 +25,9 @@ describe('Client credit insurance path', () => { }); it('should create a new credit contract', async() => { - await page.write(selectors.clientCreditInsurance.newCredit, '1000'); - await page.write(selectors.clientCreditInsurance.newGrade, '1'); - await page.pickDate(selectors.clientCreditInsurance.newStartingDate, previousMonth); + await page.write(selectors.clientCreditInsurance.newCreditClassification, '1000'); + await page.write(selectors.clientCreditInsurance.newClassificationGrade, '1'); + await page.pickDate(selectors.clientCreditInsurance.newClassificationStartingDate, previousMonth); await page.waitToClick(selectors.clientCreditInsurance.saveNewContract); await page.waitForState('client.card.creditInsurance.index'); }); @@ -36,7 +36,46 @@ describe('Client credit insurance path', () => { await page.waitForSelector(selectors.clientCreditInsurance.addNewContract, {hidden: true}); }); - it(`should bring the current contract to an end`, async() => { + it(`should click the view credits button`, async() => { + await page.waitToClick(selectors.clientCreditInsurance.firstContratViewCreditButton); + await page.waitForState('client.card.creditInsurance.insurance.index'); + }); + + it('should click the add new credit button which opens the new credit form', async() => { + await page.waitToClick(selectors.clientCreditInsurance.addNewCredit); + await page.waitForState('client.card.creditInsurance.insurance.create'); + }); + + it('should fill the form but provide no grade to the new credit hence fail', async() => { + await page.write(selectors.clientCreditInsurance.newInsuranceCredit, '2000'); + await page.pickDate(selectors.clientCreditInsurance.newInsuranceStartingDate, previousMonth); + await page.waitToClick(selectors.clientCreditInsurance.saveNewInsuranceCredit); + const message = await page.waitForSnackbar(); + + expect(message.text).toEqual('The grade must be similar to the last one'); + }); + + it('should provide a correct grade and succesfully save a new credit then be redirected to the credit index', async() => { + await page.write(selectors.clientCreditInsurance.newInsuranceGrade, '999'); + await page.waitToClick(selectors.clientCreditInsurance.saveNewInsuranceCredit); + const message = await page.waitForSnackbar(); + await page.waitForState('client.card.creditInsurance.insurance.index'); + + expect(message.text).toEqual('Data saved!'); + }); + + it('should check the amount of credits is the expected', async() => { + const result = await page.countElement(selectors.clientCreditInsurance.anyCreditInsuranceLine); + + expect(result).toEqual(2); + }); + + it('should navigate to the credit insurance section', async() => { + await page.waitToClick(`vn-left-menu li > a[ui-sref="client.card.creditInsurance.index"]`); + await page.waitForState('client.card.creditInsurance.index'); + }); + + it('should bring the current contract to an end', async() => { await page.waitToClick(selectors.clientCreditInsurance.endCurrentContract); await page.waitToClick(selectors.globalItems.acceptButton); }); From a797a2db8b926af9ac4dd912441eaa38fe7e663d Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Fri, 23 Oct 2020 13:34:57 +0200 Subject: [PATCH 22/23] fixed the absences unit test --- .../methods/calendar/specs/absences.spec.js | 36 ++++++++----------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/modules/worker/back/methods/calendar/specs/absences.spec.js b/modules/worker/back/methods/calendar/specs/absences.spec.js index 5cd27127b9..42b97e2fc6 100644 --- a/modules/worker/back/methods/calendar/specs/absences.spec.js +++ b/modules/worker/back/methods/calendar/specs/absences.spec.js @@ -1,7 +1,6 @@ const app = require('vn-loopback/server/server'); -// 2066 -xdescribe('Worker absences()', () => { +describe('Worker absences()', () => { it('should get the absence calendar for a full year contract', async() => { let ctx = {req: {accessToken: {userId: 106}}}; let workerFk = 106; @@ -84,14 +83,16 @@ xdescribe('Worker absences()', () => { yearStart.setDate(1); const yearEnd = new Date(); - yearEnd.setHours(23, 59, 59, 59); - yearEnd.setMonth(11); - yearEnd.setDate(31); + const currentYear = yearEnd.getFullYear(); + yearEnd.setFullYear(currentYear + 1); + yearEnd.setHours(0, 0, 0, 0); + yearEnd.setMonth(0); + yearEnd.setDate(1); const startedTime = yearStart.getTime(); const endedTime = yearEnd.getTime(); const dayTimestamp = 1000 * 60 * 60 * 24; - const daysInYear = Math.floor((endedTime - startedTime) / dayTimestamp); + const daysInYear = Math.round((endedTime - startedTime) / dayTimestamp); // sets the holidays per year to the amount of days in the current year let holidaysConfig = await app.models.WorkCenterHoliday.findOne({ @@ -102,17 +103,11 @@ xdescribe('Worker absences()', () => { let originalHolidaysValue = holidaysConfig.days; - await app.models.WorkCenterHoliday.updateAll( - { - workCenterFk: 1, - year: today.getFullYear() - }, - { - days: daysInYear - } - ); + await holidaysConfig.updateAttribute('days', daysInYear); + // normal test begins - const contract = await app.models.WorkerLabour.findById(106); + const userId = 106; + const contract = await app.models.WorkerLabour.findById(userId); const contractStartDate = contract.started; const startingContract = new Date(); @@ -121,14 +116,13 @@ xdescribe('Worker absences()', () => { startingContract.setDate(1); await app.models.WorkerLabour.rawSql( - `UPDATE postgresql.business SET date_start = ? WHERE business_id = ?`, - [startingContract, contract.businessFk] + `UPDATE postgresql.business SET date_start = ?, date_end = ? WHERE business_id = ?`, + [startingContract, yearEnd, contract.businessFk] ); - let ctx = {req: {accessToken: {userId: 106}}}; - let workerFk = 106; + let ctx = {req: {accessToken: {userId: userId}}}; - let result = await app.models.Calendar.absences(ctx, workerFk, yearStart, yearEnd); + let result = await app.models.Calendar.absences(ctx, userId, yearStart, yearEnd); let calendar = result[0]; let absences = result[1]; From 915728397c2c97bc87468abb281b0e947b325f42 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Fri, 23 Oct 2020 15:34:09 +0200 Subject: [PATCH 23/23] minor refactor --- e2e/paths/02-client/20_credit_insurance.spec.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/e2e/paths/02-client/20_credit_insurance.spec.js b/e2e/paths/02-client/20_credit_insurance.spec.js index 278eb861a6..904a51145e 100644 --- a/e2e/paths/02-client/20_credit_insurance.spec.js +++ b/e2e/paths/02-client/20_credit_insurance.spec.js @@ -55,15 +55,18 @@ describe('Client credit insurance path', () => { expect(message.text).toEqual('The grade must be similar to the last one'); }); - it('should provide a correct grade and succesfully save a new credit then be redirected to the credit index', async() => { + it('should provide a correct grade and succesfully save a new credit', async() => { await page.write(selectors.clientCreditInsurance.newInsuranceGrade, '999'); await page.waitToClick(selectors.clientCreditInsurance.saveNewInsuranceCredit); const message = await page.waitForSnackbar(); - await page.waitForState('client.card.creditInsurance.insurance.index'); expect(message.text).toEqual('Data saved!'); }); + it('should be redirected to the credit index', async() => { + await page.waitForState('client.card.creditInsurance.insurance.index'); + }); + it('should check the amount of credits is the expected', async() => { const result = await page.countElement(selectors.clientCreditInsurance.anyCreditInsuranceLine);