diff --git a/db/changes/10180-holyWeek/00-claimState.sql b/db/changes/10180-holyWeek/00-claimState.sql new file mode 100644 index 000000000..b4e8c68da --- /dev/null +++ b/db/changes/10180-holyWeek/00-claimState.sql @@ -0,0 +1,17 @@ +ALTER TABLE `vn`.`claimState` +DROP FOREIGN KEY `roleFgn`; +ALTER TABLE `vn`.`claimState` +ADD COLUMN `code` VARCHAR(45) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' NULL AFTER `id`, +CHANGE COLUMN `roleFk` `roleFk` INT(10) UNSIGNED NOT NULL DEFAULT '1' ; +ALTER TABLE `vn`.`claimState` +ADD CONSTRAINT `roleFgn` + FOREIGN KEY (`roleFk`) + REFERENCES `account`.`role` (`id`) + ON UPDATE CASCADE; + +UPDATE `vn`.`claimState` SET `code` = 'pending' WHERE (`id` = '1'); +UPDATE `vn`.`claimState` SET `code` = 'canceled' WHERE (`id` = '4'); +UPDATE `vn`.`claimState` SET `code` = 'resolved' WHERE (`id` = '3'); +UPDATE `vn`.`claimState` SET `code` = 'disputed' WHERE (`id` = '5'); +UPDATE `vn`.`claimState` SET `code` = 'mana' WHERE (`id` = '6'); +UPDATE `vn`.`claimState` SET `code` = 'managed' WHERE (`id` = '2'); diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index acdf645a3..f9bbce092 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1473,14 +1473,14 @@ INSERT INTO `vn`.`clientSample`(`id`, `clientFk`, `typeFk`, `created`, `workerFk (4, 102, 2, CURDATE(), 18, 18, 567), (5, 102, 3, CURDATE(), 19, 19, 567); -INSERT INTO `vn`.`claimState`(`id`, `description`, `roleFk`) +INSERT INTO `vn`.`claimState`(`id`, `code`, `description`, `roleFk`) VALUES - ( 1, 'Pendiente', 1), - ( 2, 'Gestionado', 1), - ( 3, 'Resuelto', 21), - ( 4, 'Anulado', 1), - ( 5, 'Cuestionado', 21), - ( 6, 'Mana', 1); + ( 1, 'pending', 'Pendiente', 1), + ( 2, 'managed', 'Gestionado', 1), + ( 3, 'resolved', 'Resuelto', 21), + ( 4, 'canceled', 'Anulado', 1), + ( 5, 'disputed', 'Cuestionado', 21), + ( 6, 'mana', 'Mana', 1); INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `observation`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created` ) VALUES diff --git a/front/core/filters/specs/currency.spec.js b/front/core/filters/specs/currency.spec.js index ecb94efe0..ed0262b45 100644 --- a/front/core/filters/specs/currency.spec.js +++ b/front/core/filters/specs/currency.spec.js @@ -1,8 +1,9 @@ describe('Currency filter', () => { beforeEach(ngModule('vnCore')); let currencyFilter; - beforeEach(inject(_currencyFilter_ => { + beforeEach(inject((_currencyFilter_, $translate) => { currencyFilter = _currencyFilter_; + jest.spyOn($translate, 'use').mockReturnValue('en-US'); })); it('should return a ONE decimal number as per the argument', () => { diff --git a/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js b/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js index db8a89802..8ebe41f25 100644 --- a/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js @@ -12,7 +12,10 @@ describe('regularizeClaim()', () => { afterAll(async done => { let claim = await app.models.Claim.findById(claimFk); - await claim.updateAttributes({claimStateFk: pendentState}); + await claim.updateAttributes({ + claimStateFk: pendentState, + hasToPickUp: false + }); await app.models.Ticket.destroyById(trashTicket.id); claimEnds.forEach(async line => { diff --git a/modules/claim/back/models/claim-state.json b/modules/claim/back/models/claim-state.json index bf2554f38..08d9cb12b 100644 --- a/modules/claim/back/models/claim-state.json +++ b/modules/claim/back/models/claim-state.json @@ -12,6 +12,10 @@ "id": true, "description": "Identifier" }, + "code": { + "type": "String", + "required": true + }, "description": { "type": "String", "required": true diff --git a/modules/claim/front/action/index.html b/modules/claim/front/action/index.html index a9c179134..ad05082bb 100644 --- a/modules/claim/front/action/index.html +++ b/modules/claim/front/action/index.html @@ -1,6 +1,7 @@ @@ -90,7 +91,7 @@ {{::saleClaimed.sale.ticketFk}} - + @@ -124,47 +125,12 @@ - - - -

Claimable sales from ticket

{{$ctrl.claim.ticketFk}}

- - - - Id - Landed - Quantity - Description - Price - Disc. - Total - - - - - {{sale.saleFk}} - {{sale.landed | date: 'dd/MM/yyyy'}} - {{sale.quantity}} - {{sale.concept}} - {{sale.price | currency: 'EUR':2}} - {{sale.discount}} % - - {{sale.quantity * sale.price * ((100 - sale.discount) * / 100) | currency: 'EUR':2}} - - - - -
-
{ - if (res.data) - this.claimedSales = res.data; - }); - } - - addClaimedSale(saleFk) { - let saleToAdd = {saleFk: saleFk, claimFk: this.claim.id, workerFk: this.claim.workerFk, claimDestinationFk: 1}; - let query = `ClaimEnds/`; - this.$http.post(query, saleToAdd).then(() => { - this.$.model.refresh(); - this.$.addSales.hide(); - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); - }); - } - - deleteClaimedSale(id) { - let query = `ClaimEnds/${id}`; - this.$http.delete(query).then(() => { - this.$.model.refresh(); - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); - }); + getResolvedState() { + const query = `ClaimStates/findOne`; + const params = { + filter: { + where: { + code: 'resolved' + } + } + }; + this.$http.get(query, params).then(res => + this.resolvedStateId = res.data.id + ); } importToNewRefundTicket() { @@ -80,7 +62,9 @@ export default class Controller extends Section { calculateTotals() { this.claimedTotal = 0; this.salesClaimed.forEach(sale => { - this.claimedTotal += (sale.sale.quantity * sale.sale.price) - ((sale.sale.discount * (sale.sale.quantity * sale.sale.price)) / 100); + const price = sale.sale.quantity * sale.sale.price; + const discount = (sale.sale.discount * (sale.sale.quantity * sale.sale.price)) / 100; + this.claimedTotal += price - discount; }); } diff --git a/modules/claim/front/action/index.spec.js b/modules/claim/front/action/index.spec.js index 8302f0ac9..503571f5b 100644 --- a/modules/claim/front/action/index.spec.js +++ b/modules/claim/front/action/index.spec.js @@ -32,56 +32,16 @@ describe('claim', () => { show: () => {} }; controller.card = {reload: () => {}}; + $httpBackend.expectGET(`ClaimStates/findOne`).respond({}); })); - describe('openAddSalesDialog()', () => { - it('should call getClaimableFromTicket and $.addSales.show', () => { - controller.$ = {addSales: {show: () => {}}}; - jest.spyOn(controller, 'getClaimedSales'); - jest.spyOn(controller.$.addSales, 'show'); - controller.openAddSalesDialog(); - - expect(controller.getClaimedSales).toHaveBeenCalledWith(); - expect(controller.$.addSales.show).toHaveBeenCalledWith(); - }); - }); - - describe('getClaimedSales()', () => { - it('should make a query and set salesToClaim', () => { - controller.claim.id = 1; - $httpBackend.expectGET(`ClaimBeginnings/1`).respond(200, 1); - controller.getClaimedSales(); + describe('getResolvedState()', () => { + it('should return the resolved state id', () => { + $httpBackend.expectGET(`ClaimStates/findOne`).respond({id: 1}); + controller.getResolvedState(); $httpBackend.flush(); - expect(controller.claimedSales).toEqual(1); - }); - }); - - describe('addClaimedSale(saleFk)', () => { - it('should make a post and call refresh, hide and showSuccess', () => { - jest.spyOn(controller.$.model, 'refresh'); - jest.spyOn(controller.$.addSales, 'hide'); - jest.spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.expectPOST(`ClaimEnds/`).respond({}); - controller.addClaimedSale(1); - $httpBackend.flush(); - - expect(controller.$.model.refresh).toHaveBeenCalledWith(); - expect(controller.$.addSales.hide).toHaveBeenCalledWith(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); - }); - }); - - describe('deleteClaimedSale(id)', () => { - it('should make a delete and call refresh and showSuccess', () => { - jest.spyOn(controller.$.model, 'refresh'); - jest.spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.expectDELETE(`ClaimEnds/1`).respond({}); - controller.deleteClaimedSale(1); - $httpBackend.flush(); - - expect(controller.$.model.refresh).toHaveBeenCalledWith(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + expect(controller.resolvedStateId).toEqual(1); }); }); @@ -102,6 +62,7 @@ describe('claim', () => { it('should perform a post query and add lines from a new ticket', () => { jest.spyOn(controller.$.model, 'refresh'); jest.spyOn(controller.vnApp, 'showSuccess'); + $httpBackend.expect('POST', `ClaimBeginnings/1/importToNewRefundTicket`).respond({}); controller.importToNewRefundTicket(); $httpBackend.flush(); @@ -115,6 +76,7 @@ describe('claim', () => { it('should get a list of tickets and call lastTicketsPopover show() method', () => { jest.spyOn(controller.$.lastTicketsModel, 'refresh'); jest.spyOn(controller.$.lastTicketsPopover, 'show'); + controller.showLastTickets({}); expect(controller.$.lastTicketsModel.refresh).toHaveBeenCalledWith(); @@ -127,6 +89,7 @@ describe('claim', () => { jest.spyOn(controller.$.model, 'refresh'); jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.$.lastTicketsPopover, 'hide'); + let data = {claimFk: 1, ticketFk: 1}; $httpBackend.expect('POST', `ClaimEnds/importTicketSales`, data).respond({}); controller.importTicketLines(1);