Merge branch '2181-ticket_sale_fixes' of verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Bernat Exposito 2020-03-13 08:23:36 +00:00 committed by Gitea
commit 1877a2ff1f
4 changed files with 63 additions and 11 deletions

View File

@ -175,5 +175,12 @@
"model": "ItemNiche", "model": "ItemNiche",
"foreignKey": "itemFk" "foreignKey": "itemFk"
} }
},
"scope": {
"where": {
"name": {
"neq": ""
}
}
} }
} }

View File

@ -105,20 +105,22 @@
on-error-src/> on-error-src/>
</vn-td> </vn-td>
<vn-td vn-focus number> <vn-td vn-focus number>
<span class="link" ng-if="sale.itemFk" <span class="link" ng-if="sale.id"
ng-click="$ctrl.showDescriptor($event, sale.itemFk)"> ng-click="$ctrl.showDescriptor($event, sale.itemFk)">
{{sale.itemFk | zeroFill:6}} {{sale.itemFk}}
</span> </span>
<vn-autocomplete <vn-autocomplete
ng-if="!sale.itemFk" ng-if="!sale.id"
vn-focus vn-focus
vn-one vn-one
url="Items" url="Items"
ng-model="sale.itemFk" ng-model="sale.itemFk"
show-field="name" show-field="name"
value-field="id" value-field="id"
search-function="{or: [{id: $search}, {name: {like: '%' + $search + '%'}}]}" search-function="$ctrl.itemSearchFunc($search)"
order="id DESC"> on-change="$ctrl.onChangeQuantity(sale)"
order="id DESC"
tabindex="1">
<tpl-item> <tpl-item>
{{id}} - {{name}} {{id}} - {{name}}
</tpl-item> </tpl-item>
@ -137,7 +139,8 @@
<vn-td ng-if="!sale.id" number> <vn-td ng-if="!sale.id" number>
<vn-input-number <vn-input-number
ng-model="sale.quantity" ng-model="sale.quantity"
on-change="$ctrl.onChangeQuantity(sale)"> on-change="$ctrl.onChangeQuantity(sale)"
tabindex="2">
</vn-input-number> </vn-input-number>
</vn-td> </vn-td>
<vn-td-editable disabled="!sale.id || !$ctrl.isEditable" expand> <vn-td-editable disabled="!sale.id || !$ctrl.isEditable" expand>
@ -150,7 +153,7 @@
</vn-fetched-tags> </vn-fetched-tags>
</text> </text>
<field> <field>
<vn-textfield <vn-textfield class="dense"
vn-id="concept" vn-id="concept"
ng-model="sale.concept" ng-model="sale.concept"
on-change="$ctrl.updateConcept(sale)"> on-change="$ctrl.updateConcept(sale)">
@ -167,7 +170,8 @@
<vn-td number> <vn-td number>
<span ng-class="{'link': !$ctrl.isLocked}" <span ng-class="{'link': !$ctrl.isLocked}"
title="{{!$ctrl.isLocked ? 'Edit discount' : ''}}" title="{{!$ctrl.isLocked ? 'Edit discount' : ''}}"
ng-click="$ctrl.showEditDiscountPopover($event, sale)"> ng-click="$ctrl.showEditDiscountPopover($event, sale)"
ng-if="sale.id">
{{(sale.discount / 100) | percentage}} {{(sale.discount / 100) | percentage}}
</span> </span>
</vn-td> </vn-td>

View File

@ -464,9 +464,11 @@ class Controller {
* Updates the sale quantity for existing instance * Updates the sale quantity for existing instance
*/ */
onChangeQuantity(sale) { onChangeQuantity(sale) {
if (!sale.quantity) return;
if (!sale.id) if (!sale.id)
this.addSale(sale); return this.addSale(sale);
else
this.updateQuantity(sale); this.updateQuantity(sale);
} }
@ -560,6 +562,12 @@ class Controller {
this.$scope.model.refresh(); this.$scope.model.refresh();
}); });
} }
itemSearchFunc($search) {
return /^\d+$/.test($search)
? {id: $search}
: {name: {like: '%' + $search + '%'}};
}
} }
Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate']; Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate'];

View File

@ -207,6 +207,39 @@ describe('Ticket', () => {
}); });
}); });
describe('onChangeQuantity()', () => {
it('should not call addSale() or updateQuantity() methods', () => {
jest.spyOn(controller, 'addSale');
jest.spyOn(controller, 'updateQuantity');
const sale = {itemFk: 4};
controller.onChangeQuantity(sale);
expect(controller.addSale).not.toHaveBeenCalled();
expect(controller.updateQuantity).not.toHaveBeenCalled();
});
it('should call addSale() method', () => {
jest.spyOn(controller, 'addSale');
const sale = {itemFk: 4, quantity: 5};
controller.onChangeQuantity(sale);
expect(controller.addSale).toHaveBeenCalledWith(sale);
});
it('should call updateQuantity() method', () => {
jest.spyOn(controller, 'updateQuantity');
jest.spyOn(controller, 'addSale');
const sale = {id: 1, itemFk: 4, quantity: 5};
controller.onChangeQuantity(sale);
expect(controller.addSale).not.toHaveBeenCalled();
expect(controller.updateQuantity).toHaveBeenCalledWith(sale);
});
});
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.$scope.watcher, 'updateOriginalData'); jest.spyOn(controller.$scope.watcher, 'updateOriginalData');