deprecated vat and subTotal related methods + tests fixed

This commit is contained in:
Carlos Jimenez Ruiz 2021-03-24 16:43:54 +01:00
parent 412dd34229
commit 41bb4cbaab
4 changed files with 5 additions and 85 deletions

View File

@ -376,7 +376,8 @@ describe('Ticket Edit sale path', () => {
expect(result).toBeFalsy();
});
it('should update all sales discount', async() => {
// tickets no longer update their totals instantly, a task performed ever 5-10 mins does it. disabled this test until it changes.
xit('should update all sales discount', async() => {
await page.closePopup();
await page.waitToClick(selectors.ticketSales.moreMenu);
await page.waitToClick(selectors.ticketSales.moreMenuUpdateDiscount);

View File

@ -43,9 +43,9 @@
</vn-button>
</vn-tool-bar>
<vn-one class="taxes" ng-if="$ctrl.sales.length > 0">
<p><vn-label translate>Subtotal</vn-label> {{$ctrl.subtotal | currency: 'EUR': 2}}</p>
<p><vn-label translate>VAT</vn-label> {{$ctrl.VAT | currency: 'EUR': 2}}</p>
<p><vn-label><strong>Total</strong></vn-label> <strong>{{$ctrl.total | currency: 'EUR': 2}}</strong></p>
<p><vn-label translate>Subtotal</vn-label> {{$ctrl.ticket.totalWithoutVat | currency: 'EUR':2}}</p>
<p><vn-label translate>VAT</vn-label> {{$ctrl.ticket.totalWithVat - $ctrl.ticket.totalWithoutVat | currency: 'EUR':2}}</p>
<p><vn-label><strong>Total</strong></vn-label> <strong>{{$ctrl.ticket.totalWithVat | currency: 'EUR':2}}</strong></p>
</vn-one>
</vn-horizontal>
<vn-table model="model">

View File

@ -24,7 +24,6 @@ class Controller extends Section {
set sales(value) {
this._sales = value;
this.refreshTotal();
}
get ticketState() {
@ -33,17 +32,6 @@ class Controller extends Section {
return this.ticket.ticketState.state.code;
}
get total() {
return this.subtotal + this.VAT;
}
getSubTotal() {
if (!this.$params.id || !this.sales) return;
this.$http.get(`Tickets/${this.$params.id}`).then(res => {
this.subtotal = res.data.totalWithoutVat || 0.0;
});
}
getSaleTotal(sale) {
if (sale.quantity == null || sale.price == null)
return null;
@ -59,19 +47,6 @@ class Controller extends Section {
.then(res => this.edit.mana = res.data);
}
getVat() {
this.VAT = 0.0;
if (!this.$params.id || !this.sales) return;
this.$http.get(`Tickets/${this.$params.id}`).then(res => {
this.VAT = res.data.totalWithVat - res.data.totalWithoutVat || 0.0;
});
}
refreshTotal() {
this.getSubTotal();
this.getVat();
}
/**
* Returns checked instances
*
@ -158,8 +133,6 @@ class Controller extends Section {
const index = this.sales.indexOf(sale);
this.sales.splice(index, 1);
});
this.refreshTotal();
}
createClaim() {
@ -221,7 +194,6 @@ class Controller extends Section {
this.$http.post(query, {newPrice}).then(res => {
sale.price = res.data.price;
this.edit = null;
this.refreshTotal();
this.vnApp.showSuccess(this.$t('Data saved!'));
}).finally(() => this.resetChanges());
}
@ -287,7 +259,6 @@ class Controller extends Section {
sale.discount = this.edit.discount;
this.edit = null;
this.refreshTotal();
}).finally(() => this.resetChanges());
}
@ -401,7 +372,6 @@ class Controller extends Section {
updateQuantity(sale) {
const data = {quantity: sale.quantity};
this.$http.post(`Sales/${sale.id}/updateQuantity`, data).then(() => {
this.refreshTotal();
this.vnApp.showSuccess(this.$t('Data saved!'));
}).catch(e => {
this.$.model.refresh();
@ -444,7 +414,6 @@ class Controller extends Section {
sale.price = newSale.price;
sale.item = newSale.item;
this.refreshTotal();
this.vnApp.showSuccess(this.$t('Data saved!'));
}).finally(() => this.resetChanges());
}
@ -466,7 +435,6 @@ class Controller extends Section {
this.$http.post(query).then(() => {
this.vnApp.showSuccess(this.$t('Data saved!'));
this.$.model.refresh();
this.refreshTotal();
});
}

View File

@ -72,28 +72,6 @@ describe('Ticket', () => {
});
});
describe('sales() setter', () => {
it('should set the sales data an then call the refreshTotal() method', () => {
jest.spyOn(controller, 'refreshTotal').mockReturnThis();
controller.sales = [{id: 1}];
expect(controller.refreshTotal).toHaveBeenCalledWith();
});
});
describe('getSubTotal()', () => {
it('should make an HTTP GET query and then set the subtotal property', () => {
const expectedResponse = {totalWithoutVat: 128};
$httpBackend.expect('GET', 'Tickets/1').respond(200, expectedResponse);
controller.getSubTotal();
$httpBackend.flush();
expect(controller.subtotal).toEqual(expectedResponse.totalWithoutVat);
});
});
describe('getSaleTotal()', () => {
it('should return the sale total amount', () => {
const sale = {
@ -122,21 +100,6 @@ describe('Ticket', () => {
});
});
describe('getVat()', () => {
it('should make an HTTP GET query and return the ticket VAT', () => {
controller.edit = {};
const expectedResponse = {totalWithVat: 1000, totalWithoutVat: 999};
const expectedVAT = expectedResponse.totalWithVat - expectedResponse.totalWithoutVat;
$httpBackend.expect('GET', 'Tickets/1').respond(200, expectedResponse);
controller.getVat();
$httpBackend.flush();
expect(controller.VAT).toEqual(expectedVAT);
});
});
describe('selectedSales()', () => {
it('should return a list of selected sales', () => {
controller.sales[1].checked = true;
@ -276,7 +239,6 @@ describe('Ticket', () => {
describe('removeSelectedSales()', () => {
it('should remove the selected sales from the controller sale property', () => {
jest.spyOn(controller, 'refreshTotal').mockReturnThis();
jest.spyOn(controller, 'resetChanges').mockReturnThis();
const firstSale = controller.sales[0];
@ -288,7 +250,6 @@ describe('Ticket', () => {
expect(controller.sales.length).toEqual(1);
expect(lastSale.id).toEqual(4);
expect(controller.refreshTotal).toHaveBeenCalledWith();
});
});
@ -355,7 +316,6 @@ describe('Ticket', () => {
describe('updatePrice()', () => {
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, 'resetChanges').mockReturnThis();
@ -372,7 +332,6 @@ describe('Ticket', () => {
$httpBackend.flush();
expect(selectedSale.price).toEqual(2);
expect(controller.refreshTotal).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.$.editPricePopover.hide).toHaveBeenCalledWith();
expect(controller.resetChanges).toHaveBeenCalledWith();
@ -451,7 +410,6 @@ describe('Ticket', () => {
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.vnApp, 'showSuccess').mockReturnThis();
jest.spyOn(controller, 'refreshTotal').mockReturnThis();
const expectedDiscount = 10;
const firstSelectedSale = controller.sales[0];
@ -473,7 +431,6 @@ describe('Ticket', () => {
expect(firstSelectedSale.discount).toEqual(expectedDiscount);
expect(secondSelectedSale.discount).toEqual(expectedDiscount);
expect(controller.refreshTotal).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.resetChanges).toHaveBeenCalledWith();
});
@ -622,7 +579,6 @@ describe('Ticket', () => {
describe('updateQuantity()', () => {
it('should make a POST query saving sale quantity', () => {
jest.spyOn(controller, 'refreshTotal').mockReturnThis();
jest.spyOn(controller, 'resetChanges').mockReturnThis();
const selectedSale = controller.sales[0];
@ -634,7 +590,6 @@ describe('Ticket', () => {
controller.updateQuantity(selectedSale);
$httpBackend.flush();
expect(controller.refreshTotal).toHaveBeenCalledWith();
expect(controller.resetChanges).toHaveBeenCalledWith();
});
});
@ -659,7 +614,6 @@ describe('Ticket', () => {
describe('addSale()', () => {
it('should make a POST query adding a new sale', () => {
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
jest.spyOn(controller, 'refreshTotal').mockReturnThis();
jest.spyOn(controller, 'resetChanges').mockReturnThis();
const newSale = {itemFk: 4, quantity: 10};
@ -681,7 +635,6 @@ describe('Ticket', () => {
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.refreshTotal).toHaveBeenCalledWith();
expect(controller.resetChanges).toHaveBeenCalledWith();
});
});
@ -712,7 +665,6 @@ describe('Ticket', () => {
it('should make an HTTP post query ', () => {
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
jest.spyOn(controller.$.model, 'refresh').mockReturnThis();
jest.spyOn(controller, 'refreshTotal').mockReturnThis();
const selectedSale = controller.sales[0];
selectedSale.checked = true;
@ -723,7 +675,6 @@ describe('Ticket', () => {
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.$.model.refresh).toHaveBeenCalledWith();
expect(controller.refreshTotal).toHaveBeenCalledWith();
});
});
});