Refresh total on sale changes
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-07-01 15:00:48 +02:00
parent c801d8a969
commit 23664dd3c5
2 changed files with 15 additions and 0 deletions

View File

@ -221,6 +221,7 @@ class Controller extends Section {
this.$http.post(query, {newPrice}).then(res => { this.$http.post(query, {newPrice}).then(res => {
sale.price = res.data.price; sale.price = res.data.price;
this.edit = null; this.edit = null;
this.refreshTotal();
this.vnApp.showSuccess(this.$t('Data saved!')); this.vnApp.showSuccess(this.$t('Data saved!'));
}).finally(() => this.resetChanges()); }).finally(() => this.resetChanges());
} }
@ -286,6 +287,7 @@ class Controller extends Section {
sale.discount = this.edit.discount; sale.discount = this.edit.discount;
this.edit = null; this.edit = null;
this.refreshTotal();
}).finally(() => this.resetChanges()); }).finally(() => this.resetChanges());
} }
@ -398,6 +400,7 @@ class Controller extends Section {
updateQuantity(sale) { updateQuantity(sale) {
const data = {quantity: sale.quantity}; const data = {quantity: sale.quantity};
this.$http.post(`Sales/${sale.id}/updateQuantity`, data).then(() => { this.$http.post(`Sales/${sale.id}/updateQuantity`, data).then(() => {
this.refreshTotal();
this.vnApp.showSuccess(this.$t('Data saved!')); this.vnApp.showSuccess(this.$t('Data saved!'));
}).catch(e => { }).catch(e => {
this.$.model.refresh(); this.$.model.refresh();
@ -440,6 +443,7 @@ class Controller extends Section {
sale.price = newSale.price; sale.price = newSale.price;
sale.item = newSale.item; sale.item = newSale.item;
this.refreshTotal();
this.vnApp.showSuccess(this.$t('Data saved!')); this.vnApp.showSuccess(this.$t('Data saved!'));
}).finally(() => this.resetChanges()); }).finally(() => this.resetChanges());
} }
@ -461,6 +465,7 @@ class Controller extends Section {
this.$http.post(query).then(() => { this.$http.post(query).then(() => {
this.vnApp.showSuccess(this.$t('Data saved!')); this.vnApp.showSuccess(this.$t('Data saved!'));
this.$.model.refresh(); this.$.model.refresh();
this.refreshTotal();
}); });
} }

View File

@ -353,6 +353,7 @@ describe('Ticket', () => {
describe('updatePrice()', () => { describe('updatePrice()', () => {
it('should make an HTTP POST query, update the sale price and then call to the resetChanges() method', () => { it('should make an HTTP POST query, update the sale price and then call to the resetChanges() method', () => {
jest.spyOn(controller, 'refreshTotal').mockReturnThis();
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis(); jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
jest.spyOn(controller, 'resetChanges').mockReturnThis(); jest.spyOn(controller, 'resetChanges').mockReturnThis();
@ -369,6 +370,7 @@ describe('Ticket', () => {
$httpBackend.flush(); $httpBackend.flush();
expect(selectedSale.price).toEqual(2); expect(selectedSale.price).toEqual(2);
expect(controller.refreshTotal).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.$.editPricePopover.hide).toHaveBeenCalledWith(); expect(controller.$.editPricePopover.hide).toHaveBeenCalledWith();
expect(controller.resetChanges).toHaveBeenCalledWith(); expect(controller.resetChanges).toHaveBeenCalledWith();
@ -447,6 +449,7 @@ describe('Ticket', () => {
it('should make an HTTP POST query, update the sales discount and then call to the resetChanges() method', () => { it('should make an HTTP POST query, update the sales discount and then call to the resetChanges() method', () => {
jest.spyOn(controller, 'resetChanges').mockReturnThis(); jest.spyOn(controller, 'resetChanges').mockReturnThis();
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis(); jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
jest.spyOn(controller, 'refreshTotal').mockReturnThis();
const expectedDiscount = 10; const expectedDiscount = 10;
const firstSelectedSale = controller.sales[0]; const firstSelectedSale = controller.sales[0];
@ -468,6 +471,7 @@ describe('Ticket', () => {
expect(firstSelectedSale.discount).toEqual(expectedDiscount); expect(firstSelectedSale.discount).toEqual(expectedDiscount);
expect(secondSelectedSale.discount).toEqual(expectedDiscount); expect(secondSelectedSale.discount).toEqual(expectedDiscount);
expect(controller.refreshTotal).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.resetChanges).toHaveBeenCalledWith(); expect(controller.resetChanges).toHaveBeenCalledWith();
}); });
@ -616,6 +620,7 @@ describe('Ticket', () => {
describe('updateQuantity()', () => { describe('updateQuantity()', () => {
it('should make a POST query saving sale quantity', () => { it('should make a POST query saving sale quantity', () => {
jest.spyOn(controller, 'refreshTotal').mockReturnThis();
jest.spyOn(controller, 'resetChanges').mockReturnThis(); jest.spyOn(controller, 'resetChanges').mockReturnThis();
const selectedSale = controller.sales[0]; const selectedSale = controller.sales[0];
@ -627,6 +632,7 @@ describe('Ticket', () => {
controller.updateQuantity(selectedSale); controller.updateQuantity(selectedSale);
$httpBackend.flush(); $httpBackend.flush();
expect(controller.refreshTotal).toHaveBeenCalledWith();
expect(controller.resetChanges).toHaveBeenCalledWith(); expect(controller.resetChanges).toHaveBeenCalledWith();
}); });
}); });
@ -651,6 +657,7 @@ describe('Ticket', () => {
describe('addSale()', () => { describe('addSale()', () => {
it('should make a POST query adding a new sale', () => { it('should make a POST query adding a new sale', () => {
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis(); jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
jest.spyOn(controller, 'refreshTotal').mockReturnThis();
jest.spyOn(controller, 'resetChanges').mockReturnThis(); jest.spyOn(controller, 'resetChanges').mockReturnThis();
const newSale = {itemFk: 4, quantity: 10}; const newSale = {itemFk: 4, quantity: 10};
@ -672,6 +679,7 @@ describe('Ticket', () => {
$httpBackend.flush(); $httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.refreshTotal).toHaveBeenCalledWith();
expect(controller.resetChanges).toHaveBeenCalledWith(); expect(controller.resetChanges).toHaveBeenCalledWith();
}); });
}); });
@ -702,6 +710,7 @@ describe('Ticket', () => {
it('should make an HTTP post query ', () => { it('should make an HTTP post query ', () => {
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis(); jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
jest.spyOn(controller.$.model, 'refresh').mockReturnThis(); jest.spyOn(controller.$.model, 'refresh').mockReturnThis();
jest.spyOn(controller, 'refreshTotal').mockReturnThis();
const selectedSale = controller.sales[0]; const selectedSale = controller.sales[0];
selectedSale.checked = true; selectedSale.checked = true;
@ -712,6 +721,7 @@ describe('Ticket', () => {
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.$.model.refresh).toHaveBeenCalledWith(); expect(controller.$.model.refresh).toHaveBeenCalledWith();
expect(controller.refreshTotal).toHaveBeenCalledWith();
}); });
}); });
}); });