Refactor #1527 claim/detail, ticket/sale updateDiscount y updatePrice
gitea/salix/dev This commit looks good Details

This commit is contained in:
Bernat 2019-06-17 12:13:05 +02:00
parent c435eb456f
commit 53f6db7a4a
7 changed files with 54 additions and 15 deletions

View File

@ -146,9 +146,7 @@
</vn-input-number>
<div class="simulator">
<p class="simulatorTitle" translate>New price</p>
<p>{{($ctrl.saleClaimed.quantity * $ctrl.saleClaimed.sale.price) -
(($ctrl.newDiscount * ($ctrl.saleClaimed.quantity * $ctrl.saleClaimed.sale.price))/100)
| currency: 'EUR':2}}
<p>{{$ctrl.newPrice | currency: 'EUR':2}}
</p>
</div>
</div>

View File

@ -37,6 +37,15 @@ class Controller {
return this._salesClaimed;
}
get newDiscount() {
return this._newDiscount;
}
set newDiscount(value) {
this._newDiscount = value;
this.updateNewPrice();
}
openAddSalesDialog() {
this.getClaimableFromTicket();
this.$.addSales.show();
@ -140,6 +149,11 @@ class Controller {
}
}
updateNewPrice() {
this.newPrice = (this.saleClaimed.quantity * this.saleClaimed.sale.price) -
((this.newDiscount * (this.saleClaimed.quantity * this.saleClaimed.sale.price)) / 100);
}
clearDiscount() {
this.newDiscount = null;
}

View File

@ -93,12 +93,16 @@ describe('claim', () => {
});
});
describe('updateDiscount()', () => {
fdescribe('updateDiscount()', () => {
it('should perform a query if the new discount differs from the claim discount', () => {
controller.saleClaimed = {sale: {
discount: 5,
id: 7,
ticketFk: 1,
price: 2,
quantity: 10}};
controller.newDiscount = 10;
controller.saleClaimed = {sale: {discount: 5}};
controller.saleClaimed = {sale: {id: 7}};
controller.saleClaimed = {sale: {ticketFk: 1}};
spyOn(controller.vnApp, 'showSuccess');
spyOn(controller, 'clearDiscount');

View File

@ -13,8 +13,6 @@
</vn-input-number>
<div class="simulator">
<p class="simulatorTitle" translate>New price</p>
<p>{{($ctrl.edit[0].quantity * $ctrl.edit[0].price)
- (($ctrl.newDiscount * ($ctrl.edit[0].quantity * $ctrl.edit[0].price))/100)
| currency: 'EUR':2}}</p>
<p>{{$ctrl.newPrice | currency: 'EUR':2}}</p>
</div>
</div>

View File

@ -28,6 +28,20 @@ class Controller {
return this._bulk;
}
get newDiscount() {
return this._newDiscount;
}
set newDiscount(value) {
this._newDiscount = value;
this.updateNewPrice();
}
updateNewPrice() {
if (this.newDiscount && this.edit[0])
this.newPrice = (this.edit[0].quantity * this.edit[0].price) - ((this.newDiscount * (this.edit[0].quantity * this.edit[0].price)) / 100);
}
setNewDiscount() {
if (!this.newDiscount && this.edit[0])
this.newDiscount = this.edit[0].discount;

View File

@ -186,9 +186,7 @@
</vn-input-number>
<div class="simulator">
<p class="simulatorTitle" translate>New price</p>
<p>{{($ctrl.sale.quantity * $ctrl.editedPrice)
- (($ctrl.sale.discount * ($ctrl.sale.quantity * $ctrl.editedPrice))/100)
| currency: 'EUR':2}}</p>
<p>{{$ctrl.newPrice | currency: 'EUR':2}}</p>
</div>
</div>
</div>

View File

@ -21,16 +21,25 @@ class Controller {
this.imagesPath = '//verdnatura.es/vn-image-data/catalog';
}
get sales() {
return this._sales;
}
set sales(value) {
this._sales = value;
this.refreshTotal();
}
get sales() {
return this._sales;
get editedPrice() {
return this._editedPrice;
}
set editedPrice(value) {
this._editedPrice = value;
this.updateNewPrice();
}
refreshTotal() {
this.loadSubTotal();
this.loadVAT();
@ -270,6 +279,10 @@ class Controller {
this.$scope.editPricePopover.hide();
}
updateNewPrice() {
this.newPrice = this.sale.quantity * this.editedPrice - ((this.sale.discount * (this.sale.quantity * this.editedPrice)) / 100);
}
showEditPopover(event, sale) {
this.sale = sale;
this.edit = [{