From e60d485111c3e25958ebe103f29629e81992a642 Mon Sep 17 00:00:00 2001 From: Joan Date: Fri, 23 Nov 2018 14:30:01 +0100 Subject: [PATCH 1/3] fixed infinite claim detail save #866 --- client/claim/src/action/index.spec.js | 4 ++-- client/claim/src/detail/index.html | 12 ++++++------ client/claim/src/detail/index.js | 27 +++++++++++++++------------ client/claim/src/detail/index.spec.js | 17 +++++++++-------- 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/client/claim/src/action/index.spec.js b/client/claim/src/action/index.spec.js index f67d0ecc4..70684ac49 100644 --- a/client/claim/src/action/index.spec.js +++ b/client/claim/src/action/index.spec.js @@ -110,7 +110,7 @@ describe('claim', () => { }); describe('importToNewRefundTicket()', () => { - it('should perform a post query', () => { + it('should perform a post query and add lines from a new ticket', () => { spyOn(controller.$.model, 'refresh'); spyOn(controller.vnApp, 'showSuccess'); $httpBackend.expect('POST', `claim/api/ClaimBeginnings/1/importToNewRefundTicket`).respond({}); @@ -134,7 +134,7 @@ describe('claim', () => { }); describe('importTicketLines()', () => { - it('should perform a post query', () => { + it('should perform a post query and add lines from an existent ticket', () => { spyOn(controller.$.model, 'refresh'); spyOn(controller.vnApp, 'showSuccess'); spyOn(controller.$.lastTicketsPopover, 'hide'); diff --git a/client/claim/src/detail/index.html b/client/claim/src/detail/index.html index f9b77c470..da53aad34 100644 --- a/client/claim/src/detail/index.html +++ b/client/claim/src/detail/index.html @@ -2,7 +2,7 @@ vn-id="model" url="claim/api/ClaimBeginnings" filter="$ctrl.filter" - data="$ctrl.salesClaimed"> + data="$ctrl.salesClaimed" on-data-change="$ctrl.calculateTotals()"> @@ -32,7 +32,7 @@ - + @@ -100,8 +100,8 @@ - - {{sale.saleFk}} + + {{sale.saleFk}} {{$index}} {{sale.landed | dateTime: 'dd/MM/yyyy'}} {{sale.quantity}} {{sale.concept}} @@ -112,7 +112,7 @@ - + No results diff --git a/client/claim/src/detail/index.js b/client/claim/src/detail/index.js index 3fdc8ef20..4da589712 100644 --- a/client/claim/src/detail/index.js +++ b/client/claim/src/detail/index.js @@ -38,22 +38,24 @@ class Controller { }); } - addClaimedSale(saleFk) { - let saleToAdd = {saleFk: saleFk, claimFk: this.claim.id, quantity: 0}; + addClaimedSale(index) { + let sale = this.salesToClaim[index]; + let saleToAdd = {saleFk: sale.saleFk, claimFk: this.claim.id, quantity: 0}; let query = `claim/api/ClaimBeginnings/`; this.$http.post(query, saleToAdd).then(() => { - this.$.model.refresh(); this.$.addSales.hide(); + this.$.model.refresh(); this.vnApp.showSuccess(this.$translate.instant('Data saved!')); }); } - deleteClaimedSale(id) { - let json = encodeURIComponent(JSON.stringify(id)); - let query = `claim/api/ClaimBeginnings/${json}`; + deleteClaimedSale(index) { + let sale = this.salesClaimed[index]; + let query = `claim/api/ClaimBeginnings/${sale.id}`; this.$http.delete(query).then(() => { - this.$.model.refresh(); this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.$.model.remove(index); + this.calculateTotals(); }); } @@ -61,18 +63,19 @@ class Controller { let params = {id: id, quantity: claimedQuantity}; let query = `claim/api/ClaimBeginnings/`; this.$http.patch(query, params).then(() => { - this.$.model.refresh(); this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.calculateTotals(); }); } calculateTotals() { + let salesClaimed = this.$.model.data; + if (!salesClaimed) return; + this.paidTotal = 0; - this.salesClaimed.forEach(sale => { - this.paidTotal += (sale.sale.quantity * sale.sale.price) - ((sale.sale.discount * (sale.sale.quantity * sale.sale.price)) / 100); - }); this.claimedTotal = 0; - this.salesClaimed.forEach(sale => { + salesClaimed.forEach(sale => { + this.paidTotal += (sale.sale.quantity * sale.sale.price) - ((sale.sale.discount * (sale.sale.quantity * sale.sale.price)) / 100); this.claimedTotal += (sale.quantity * sale.sale.price) - ((sale.sale.discount * (sale.quantity * sale.sale.price)) / 100); }); } diff --git a/client/claim/src/detail/index.spec.js b/client/claim/src/detail/index.spec.js index b75063d2c..b492ba29a 100644 --- a/client/claim/src/detail/index.spec.js +++ b/client/claim/src/detail/index.spec.js @@ -1,4 +1,5 @@ import './index.js'; +import {crudModel} from '../../../helpers/crudModelHelper'; describe('claim', () => { describe('Component vnClaimDetail', () => { @@ -20,8 +21,10 @@ describe('claim', () => { $state.params.id = 1; controller = $componentController('vnClaimDetail', {$state: $state}); + controller.salesToClaim = [{saleFk: 1}, {saleFk: 2}]; + controller.salesClaimed = [{id: 1}]; controller.claim = {ticketFk: 1}; - controller.$.model = {refresh: () => {}}; + controller.$.model = crudModel; controller.$.addSales = { hide: () => {}, show: () => {} @@ -50,7 +53,7 @@ describe('claim', () => { }); }); - describe('addClaimedSale(saleFk)', () => { + describe('addClaimedSale(index)', () => { it('should make a post and call refresh, hide and showSuccess', () => { spyOn(controller.$.model, 'refresh'); spyOn(controller.$.addSales, 'hide'); @@ -65,28 +68,26 @@ describe('claim', () => { }); }); - describe('deleteClaimedSale(id)', () => { + describe('deleteClaimedSale(index)', () => { it('should make a delete and call refresh and showSuccess', () => { - spyOn(controller.$.model, 'refresh'); + spyOn(controller.$.model, 'remove'); spyOn(controller.vnApp, 'showSuccess'); $httpBackend.expectDELETE(`claim/api/ClaimBeginnings/1`).respond({}); - controller.deleteClaimedSale(1); + controller.deleteClaimedSale(0); $httpBackend.flush(); - expect(controller.$.model.refresh).toHaveBeenCalledWith(); + expect(controller.$.model.remove).toHaveBeenCalledWith(0); expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); }); }); describe('setClaimedQuantity(id, claimedQuantity)', () => { it('should make a patch and call refresh and showSuccess', () => { - spyOn(controller.$.model, 'refresh'); spyOn(controller.vnApp, 'showSuccess'); $httpBackend.expectPATCH(`claim/api/ClaimBeginnings/`).respond({}); controller.setClaimedQuantity(1, 1); $httpBackend.flush(); - expect(controller.$.model.refresh).toHaveBeenCalledWith(); expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); }); }); From 5f4dfe6d7556f2f9720cfa27519b1025dc4f71ab Mon Sep 17 00:00:00 2001 From: Gerard Date: Mon, 26 Nov 2018 09:53:34 +0100 Subject: [PATCH 2/3] #865 hacer que los eventos de guardado funcionen correctamente --- client/core/src/components/textfield/textfield.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/client/core/src/components/textfield/textfield.js b/client/core/src/components/textfield/textfield.js index 1155e5239..20cb4c61d 100644 --- a/client/core/src/components/textfield/textfield.js +++ b/client/core/src/components/textfield/textfield.js @@ -30,13 +30,19 @@ export default class Textfield extends Input { }); this.input.addEventListener('blur', () => { - if (this.onChange && !this.cancelled && (this.oldValue != this.value)) + if (this.onChange && !this.cancelled && (this.oldValue != this.value)) { this.onChange(); - else + this.saveOldValue(); + } else this.cancelled = false; }); } + $postLink() { + this.saveOldValue(); + console.log(this.value, this.oldValue); + } + saveOldValue() { this.oldValue = this.value; } From e8b9e509b1e40448baf81fb575d0d2e99a87f796 Mon Sep 17 00:00:00 2001 From: Gerard Date: Mon, 26 Nov 2018 10:05:06 +0100 Subject: [PATCH 3/3] console.log deleted --- client/core/src/components/textfield/textfield.js | 1 - 1 file changed, 1 deletion(-) diff --git a/client/core/src/components/textfield/textfield.js b/client/core/src/components/textfield/textfield.js index 20cb4c61d..f47b3de37 100644 --- a/client/core/src/components/textfield/textfield.js +++ b/client/core/src/components/textfield/textfield.js @@ -40,7 +40,6 @@ export default class Textfield extends Input { $postLink() { this.saveOldValue(); - console.log(this.value, this.oldValue); } saveOldValue() {