diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index c09c10f50..a9a66c616 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -61,7 +61,7 @@ export default { fiscalDataButton: 'vn-left-menu a[ui-sref="client.card.fiscalData"]', socialNameInput: `vn-textfield input[name="socialName"]`, fiscalIdInput: `vn-textfield input[name="fi"]`, - equalizationTaxCheckbox: 'vn-check[label="Is equalizated"]', + equalizationTaxCheckbox: 'vn-check[ng-model="$ctrl.client.isEqualizated"]', acceptPropagationButton: 'vn-client-fiscal-data > vn-confirm button[response=ACCEPT]', addressInput: `vn-textfield input[name="street"]`, postcodeInput: `vn-textfield input[name="postcode"]`, @@ -482,7 +482,7 @@ export default { addRequestButton: 'vn-ticket-request-index > a > vn-float-button > button', request: 'vn-ticket-request-index vn-table vn-tr', descriptionInput: 'vn-ticket-request-create > form > div > vn-card > div > vn-horizontal:nth-child(1) > vn-textfield input', - atenderAutocomplete: 'vn-ticket-request-create vn-autocomplete[ng-model="$ctrl.ticketRequest.atenderFk"]', + atenderAutocomplete: 'vn-ticket-request-create vn-autocomplete[ng-model="$ctrl.ticketRequest.attenderFk"]', quantityInput: 'vn-ticket-request-create vn-input-number input[name=quantity]', priceInput: 'vn-ticket-request-create vn-input-number input[name=price]', firstRemoveRequestButton: 'vn-ticket-request-index vn-icon[icon="delete"]:nth-child(1)', @@ -534,7 +534,7 @@ export default { itemDescriptorPopover: '.vn-popover.shown vn-item-descriptor', itemDescriptorPopoverItemDiaryButton: '.vn-popover.shown vn-item-descriptor a[href="#!/item/2/diary"]', firstDevelopmentWorker: 'vn-claim-summary vn-horizontal > vn-auto:nth-child(5) vn-table > div > vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(4) > span', - firstDevelopmentWorkerGoToClientButton: '.vn-popover.shown vn-worker-descriptor div.quicklinks > a[href="#!/client/21/summary"]', + firstDevelopmentWorkerGoToClientButton: '.vn-popover.shown vn-worker-descriptor vn-quick-links > a[href="#!/client/21/summary"]', firstActionTicketId: 'vn-claim-summary > vn-card > div > vn-horizontal > vn-auto:nth-child(6) vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > span', firstActionTicketDescriptor: '.vn-popover.shown vn-ticket-descriptor' }, diff --git a/front/core/directives/focus.js b/front/core/directives/focus.js index 55e7d3496..b9527479b 100644 --- a/front/core/directives/focus.js +++ b/front/core/directives/focus.js @@ -3,7 +3,7 @@ import ngModule from '../module'; const regex = /Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone/i; export const isMobile = regex.test(navigator.userAgent); -export function focus(input) { +export function focus($scope, input) { if (isMobile) return; const element = input; @@ -23,9 +23,9 @@ export function focus(input) { } input.focus(); - - if (input.select) + $scope.$applyAsync(() => { input.select(); + }); } /** @@ -37,7 +37,7 @@ export function directive() { return { restrict: 'A', link: function($scope, $element) { - $scope.$watch('', () => focus($element[0])); + $scope.$watch('', () => focus($scope, $element[0])); } }; } diff --git a/front/core/directives/specs/focus.spec.js b/front/core/directives/specs/focus.spec.js index ecf28a692..4034657b4 100644 --- a/front/core/directives/specs/focus.spec.js +++ b/front/core/directives/specs/focus.spec.js @@ -40,6 +40,7 @@ describe('Directive focus', () => { it('should call select function on the element', () => { let html = ``; compile(html); + $scope.$apply(); expect($element[0].select).toHaveBeenCalledWith(); }); diff --git a/front/salix/components/descriptor/index.html b/front/salix/components/descriptor/index.html index a3ee34563..3804be627 100644 --- a/front/salix/components/descriptor/index.html +++ b/front/salix/components/descriptor/index.html @@ -1,7 +1,7 @@ + ui-sref="{{::$ctrl.links.btnOne.state}}"> @@ -9,7 +9,7 @@ + ui-sref="{{::$ctrl.links.btnTwo.state}}"> @@ -17,7 +17,7 @@ + ui-sref="{{::$ctrl.links.btnThree.state}}"> diff --git a/modules/claim/front/action/index.spec.js b/modules/claim/front/action/index.spec.js index d1f8f9766..e526680c3 100644 --- a/modules/claim/front/action/index.spec.js +++ b/modules/claim/front/action/index.spec.js @@ -82,17 +82,6 @@ describe('claim', () => { }); }); - describe('setClaimDestination(id, claimDestinationFk)', () => { - it('should make a patch and call refresh and showSuccess', () => { - spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.expectPATCH(`claim/api/ClaimEnds/`).respond({}); - controller.setClaimDestination(1, 1); - $httpBackend.flush(); - - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); - }); - }); - describe('calculateTotals()', () => { it('should calculate the total price of the items claimed', () => { controller.salesClaimed = [ diff --git a/modules/item/front/index/index.html b/modules/item/front/index/index.html index 3ed297baa..2f53c9c08 100644 --- a/modules/item/front/index/index.html +++ b/modules/item/front/index/index.html @@ -8,12 +8,11 @@
- + suggested-filter="{isActive: true}"> + order="shipped ASC, isOk ASC">
- - - - + + - - - - - Ticket ID - Shipped - Warehouse - SalesPerson - Description - Quantity - Price - Atender - Item - Concept - Sale quantity - State - - - - - - - {{request.ticketFk}} - - - - - {{::request.shipped | date: 'dd/MM/yyyy'}} - - - {{::request.warehouse}} - - - {{::request.salesPersonNickname}} - - - {{::request.description}} - {{::request.quantity}} - {{::request.price | currency: 'EUR':2}} - - - {{::request.atenderNickname}} - - - - {{request.itemFk}} - - - - - - - - {{::request.itemDescription}} - - - - {{request.saleQuantity}} - - - - - - {{::$ctrl.getState(request.isOk)}} - - - - - - - - - - - + + + + + + Ticket ID + Shipped + Warehouse + SalesPerson + Description + Requested + Price + Atender + Item + Achieved + Concept + State + + + + + + + {{request.ticketFk}} + + + + + {{::request.shipped | date: 'dd/MM/yyyy'}} + + + {{::request.warehouse}} + + + {{::request.salesPersonNickname}} + + + {{::request.description}} + {{::request.quantity}} + {{::request.price | currency: 'EUR':2}} + + + {{::request.atenderNickname}} + + + + {{request.itemFk}} + + + + + + + {{request.saleQuantity}} + + + + + + + + {{request.itemDescription}} + + + {{$ctrl.getState(request.isOk)}} + + + + + + + + + + +
+ on-response="$ctrl.denyRequest(response)"> - -
Indicate the reasons to deny this request
-
+
Specify the reasons to deny this request
- - - -
+ + + +
\ No newline at end of file diff --git a/modules/item/front/request/index.js b/modules/item/front/request/index.js index f887be9a8..c18800001 100644 --- a/modules/item/front/request/index.js +++ b/modules/item/front/request/index.js @@ -9,8 +9,23 @@ export default class Controller { this.$ = $; this.vnApp = vnApp; this._ = $translate; - if (!$stateParams.q) - this.filter = {isOk: false, mine: true}; + if (!$stateParams.q) { + const today = new Date(); + today.setHours(23, 59, 59, 59); + + const lastWeek = new Date(); + lastWeek.setHours(0, 0, 0, 0); + lastWeek.setDate(lastWeek.getDate() - 7); + + this.filter = { + where: { + isOk: false, + mine: true, + from: lastWeek, + to: today + } + }; + } } $postLink() { @@ -21,7 +36,7 @@ export default class Controller { getState(isOk) { if (isOk === null) return 'Nueva'; - else if (isOk === -1 || isOk === 1) + else if (isOk === -1 || isOk) return 'Aceptada'; else return 'Denegada'; @@ -34,14 +49,12 @@ export default class Controller { quantity: request.saleQuantity }; - let endpoint = `/api/TicketRequests/${request.id}/confirm`; + let query = `/api/TicketRequests/${request.id}/confirm`; + this.$http.post(query, params).then(res => { + request.itemDescription = res.data.concept; + request.isOk = true; - this.$http.post(endpoint, params).then(() => { this.vnApp.showSuccess(this._.instant('Data saved!')); - this.$.model.refresh(); - }).catch( e => { - this.$.model.refresh(); - throw e; }); } } @@ -56,10 +69,7 @@ export default class Controller { this.$http.patch(endpoint, params).then(() => { this.vnApp.showSuccess(this._.instant('Data saved!')); - }).catch( e => { - this.$.model.refresh(); - throw e; - }); + }).then(() => this.confirmRequest(request)); } else this.confirmRequest(request); } @@ -86,7 +96,7 @@ export default class Controller { } showDenyReason(event, requestId) { - this.denyRequestId = requestId; + this.selectedRequest = requestId; this.$.denyReason.parent = event.target; this.$.denyReason.show(); document.querySelector('vn-item-request vn-textarea textArea').focus(); @@ -96,17 +106,21 @@ export default class Controller { delete this.denyRequestId; } - denyRequest() { + denyRequest(response) { + if (response !== 'ACCEPT') return; + let params = { observation: this.denyObservation }; - let endpoint = `/api/TicketRequests/${this.denyRequestId}/deny`; + let query = `/api/TicketRequests/${this.selectedRequest.id}/deny`; + this.$http.post(query, params).then(res => { + const request = res.data; + this.selectedRequest.isOk = request.isOk; + this.selectedRequest.attenderFk = request.attenderFk; + this.selectedRequest.response = request.response; - this.$http.post(endpoint, params).then(() => { this.vnApp.showSuccess(this._.instant('Data saved!')); - this.$.model.refresh(); - this.$.denyReason.hide(); this.denyObservation = null; }); } diff --git a/modules/item/front/request/index.spec.js b/modules/item/front/request/index.spec.js index e27bc3879..1704c61a1 100644 --- a/modules/item/front/request/index.spec.js +++ b/modules/item/front/request/index.spec.js @@ -53,15 +53,15 @@ describe('Item', () => { let model = controller.$.model; spyOn(model, 'refresh'); + const expectedResult = {concept: 'Melee Weapon'}; let request = {itemFk: 1, saleQuantity: 1, id: 1}; - $httpBackend.when('POST', `/api/TicketRequests/${request.id}/confirm`).respond(); - $httpBackend.expect('POST', `/api/TicketRequests/${request.id}/confirm`).respond(); + $httpBackend.when('POST', `/api/TicketRequests/${request.id}/confirm`).respond(expectedResult); + $httpBackend.expect('POST', `/api/TicketRequests/${request.id}/confirm`).respond(expectedResult); controller.confirmRequest(request); $httpBackend.flush(); expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); - expect($scope.model.refresh).toHaveBeenCalledWith(); }); }); @@ -110,20 +110,17 @@ describe('Item', () => { describe('denyRequest()', () => { it(`should perform a query and call vnApp.showSuccess(), refresh(), hide() and set denyObservation to null in the controller`, () => { spyOn(controller.vnApp, 'showSuccess'); - let model = controller.$.model; - spyOn(model, 'refresh'); - spyOn(controller.$.denyReason, 'hide'); - controller.denyRequestId = 1; + const request = {id: 1}; + const expectedResult = {isOk: false, attenderFk: 106, response: 'Denied!'}; + controller.selectedRequest = request; - $httpBackend.when('POST', `/api/TicketRequests/${controller.denyRequestId}/deny`).respond(); - $httpBackend.expect('POST', `/api/TicketRequests/${controller.denyRequestId}/deny`).respond(); - controller.denyRequest(); + $httpBackend.when('POST', `/api/TicketRequests/${request.id}/deny`).respond(expectedResult); + $httpBackend.expect('POST', `/api/TicketRequests/${request.id}/deny`).respond(expectedResult); + controller.denyRequest('ACCEPT'); $httpBackend.flush(); expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); - expect($scope.model.refresh).toHaveBeenCalledWith(); - expect($scope.denyReason.hide).toHaveBeenCalledWith(); }); }); }); diff --git a/modules/item/front/request/locale/es.yml b/modules/item/front/request/locale/es.yml index 760f30bd3..33710a327 100644 --- a/modules/item/front/request/locale/es.yml +++ b/modules/item/front/request/locale/es.yml @@ -1,5 +1,6 @@ Discard: Descartar -Indicate the reasons to deny this request: Indique las razones para descartar esta peticion +Specify the reasons to deny this request: Especifica las razones para descartar la peticiĆ³n Buy requests: Peticiones de compra Search request by id or alias: Buscar peticiones por identificador o alias -Sale quantity: C. conseguida \ No newline at end of file +Requested: Solicitado +Achieved: Conseguido \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket-request/confirm.js b/modules/ticket/back/methods/ticket-request/confirm.js index 92dd06dae..53fb2527c 100644 --- a/modules/ticket/back/methods/ticket-request/confirm.js +++ b/modules/ticket/back/methods/ticket-request/confirm.js @@ -38,27 +38,27 @@ module.exports = Self => { try { let options = {transaction: tx}; - let item = await models.Item.findById(ctx.args.itemFk); + let item = await models.Item.findById(ctx.args.itemFk, null, options); if (!item) throw new UserError(`That item doesn't exists`); let request = await models.TicketRequest.findById(ctx.args.id, { include: {relation: 'ticket'} - }); + }, options); let [[stock]] = await Self.rawSql(`CALL vn.getItemVisibleAvailable(?,?,?,?)`, [ ctx.args.itemFk, request.ticket().shipped, request.ticket().warehouseFk, false - ]); + ], options); if (stock.available < 0) throw new UserError(`This item is not available`); if (request.saleFk) { - sale = await models.Sale.findById(request.saleFk); + sale = await models.Sale.findById(request.saleFk, null, options); sale.updateAttributes({ itemFk: ctx.args.itemFk, quantity: ctx.args.quantity, @@ -71,7 +71,11 @@ module.exports = Self => { quantity: ctx.args.quantity, concept: item.name }, options); - request.updateAttributes({saleFk: sale.id, itemFk: sale.itemFk, isOk: true}, options); + request.updateAttributes({ + saleFk: sale.id, + itemFk: sale.itemFk, + isOk: true + }, options); } query = `CALL vn.ticketCalculateSale(?)`; @@ -86,6 +90,8 @@ module.exports = Self => { }, options); await tx.commit(); + + return sale; } catch (error) { await tx.rollback(); throw error; diff --git a/modules/ticket/back/methods/ticket-request/deny.js b/modules/ticket/back/methods/ticket-request/deny.js index 817c90782..e663ef1bc 100644 --- a/modules/ticket/back/methods/ticket-request/deny.js +++ b/modules/ticket/back/methods/ticket-request/deny.js @@ -29,7 +29,7 @@ module.exports = Self => { let params = { isOk: false, - atenderFk: worker.id, + attenderFk: worker.id, response: ctx.args.observation, }; diff --git a/modules/ticket/back/methods/ticket-request/filter.js b/modules/ticket/back/methods/ticket-request/filter.js index 40c1f7652..82e1ee8e0 100644 --- a/modules/ticket/back/methods/ticket-request/filter.js +++ b/modules/ticket/back/methods/ticket-request/filter.js @@ -28,7 +28,7 @@ module.exports = Self => { type: 'Number', description: `Search by warehouse` }, { - arg: 'atenderFk', + arg: 'attenderFk', type: 'Number', description: `Search requests atended by the given worker` }, { @@ -65,7 +65,7 @@ module.exports = Self => { let worker = await Self.app.models.Worker.findOne({where: {userFk: userId}}); if (ctx.args.mine) - ctx.args.atenderFk = worker.id; + ctx.args.attenderFk = worker.id; let where = buildFilter(ctx.args, (param, value) => { switch (param) { @@ -75,7 +75,7 @@ module.exports = Self => { : {'t.nickname': {like: `%${value}%`}}; case 'ticketFk': return {'t.id': value}; - case 'atenderFk': + case 'attenderFk': return {'tr.atenderFk': value}; case 'isOk': return {'tr.isOk': value}; @@ -106,13 +106,13 @@ module.exports = Self => { tr.ticketFk, tr.quantity, tr.price, - tr.atenderFk, + tr.atenderFk attenderFk, tr.description, tr.response, tr.saleFk, tr.isOk, s.quantity AS saleQuantity, - s.itemFK, + s.itemFk, i.name AS itemDescription, t.shipped, t.nickname, diff --git a/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js b/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js index 574469d86..2383fe560 100644 --- a/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js +++ b/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js @@ -1,27 +1,14 @@ const app = require('vn-loopback/server/server'); describe('ticket-request confirm()', () => { - let request; - let sale; + let originalRequest; + let originalSale; let createdSaleId; afterAll(async done => { - const paramsForRequest = { - saleFk: request.saleFk, - isOk: request.isOk, - itemFk: request.itemFk, - ticketFk: request.ticketFk - }; - - const paramsForSale = { - itemFk: sale.itemFk, - quantity: sale.quantity, - concept: sale.concept, - }; - - await request.updateAttributes(paramsForRequest); - await sale.updateAttributes(paramsForSale); - app.models.Sale.destroyById(createdSaleId); + await originalRequest.updateAttributes(originalRequest); + await originalSale.updateAttributes(originalSale); + await app.models.Sale.destroyById(createdSaleId); done(); }); @@ -65,10 +52,11 @@ describe('ticket-request confirm()', () => { const itemId = 1; const quantity = 10; - request = await app.models.TicketRequest.findById(requestId); - sale = await app.models.Sale.findById(saleId); + originalRequest = await app.models.TicketRequest.findById(requestId); + originalSale = await app.models.Sale.findById(saleId); - request.updateAttributes({saleFk: saleId}); + const request = await app.models.TicketRequest.findById(requestId); + await request.updateAttributes({saleFk: saleId}); let ctx = {req: {accessToken: {userId: 9}}, args: { itemFk: itemId, @@ -89,7 +77,8 @@ describe('ticket-request confirm()', () => { const itemId = 1; const quantity = 10; - request.updateAttributes({saleFk: null}); + const request = await app.models.TicketRequest.findById(requestId); + await request.updateAttributes({saleFk: null}); let ctx = {req: {accessToken: {userId: 9}}, args: { itemFk: itemId, diff --git a/modules/ticket/back/methods/ticket-request/specs/deny.spec.js b/modules/ticket/back/methods/ticket-request/specs/deny.spec.js index cac63586e..04152fa21 100644 --- a/modules/ticket/back/methods/ticket-request/specs/deny.spec.js +++ b/modules/ticket/back/methods/ticket-request/specs/deny.spec.js @@ -5,7 +5,7 @@ describe('ticket-request deny()', () => { afterAll(async done => { let params = { isOk: null, - atenderFk: request.atenderFk, + attenderFk: request.attenderFk, response: null, }; diff --git a/modules/ticket/back/methods/ticket-request/specs/filter.spec.js b/modules/ticket/back/methods/ticket-request/specs/filter.spec.js index 24e74e4df..329688866 100644 --- a/modules/ticket/back/methods/ticket-request/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket-request/specs/filter.spec.js @@ -37,7 +37,7 @@ describe('ticket-request filter()', () => { }); it('should return the ticket request matching the atender ID', async() => { - let ctx = {req: {accessToken: {userId: 9}}, args: {atenderFk: 35}}; + let ctx = {req: {accessToken: {userId: 9}}, args: {attenderFk: 35}}; let result = await app.models.TicketRequest.filter(ctx); let requestId = result[0].id; diff --git a/modules/ticket/back/models/ticket-request.json b/modules/ticket/back/models/ticket-request.json index dfb609e3c..7f1cb4b02 100644 --- a/modules/ticket/back/models/ticket-request.json +++ b/modules/ticket/back/models/ticket-request.json @@ -33,9 +33,12 @@ "isOk": { "type": "Boolean" }, - "atenderFk": { + "attenderFk": { "type": "Number", - "required": true + "required": true, + "mysql": { + "columnName": "atenderFk" + } }, "response": { "type": "String" @@ -55,7 +58,7 @@ "atender": { "type": "belongsTo", "model": "Worker", - "foreignKey": "atenderFk" + "foreignKey": "attenderFk" }, "requester": { "type": "belongsTo", diff --git a/modules/ticket/front/descriptor/index.js b/modules/ticket/front/descriptor/index.js index a33e57e14..05b4e719a 100644 --- a/modules/ticket/front/descriptor/index.js +++ b/modules/ticket/front/descriptor/index.js @@ -176,7 +176,7 @@ class Controller { links.btnTwo = { icon: 'icon-stowaway', state: `ticket.card.summary({id: ${value.stowaway.shipFk}})`, - tooltip: 'Ship' + tooltip: 'Ship stowaways' }; } diff --git a/modules/ticket/front/request/create/index.html b/modules/ticket/front/request/create/index.html index 1b7044c20..dd10d8afe 100644 --- a/modules/ticket/front/request/create/index.html +++ b/modules/ticket/front/request/create/index.html @@ -18,7 +18,7 @@ + ng-click="$ctrl.showWorkerDescriptor($event, request.attenderFk)"> {{::request.atender.user.nickname | dashIfEmpty}}