Merge branch '2181-ticket_sale_fixes' of verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
1877a2ff1f
|
@ -175,5 +175,12 @@
|
|||
"model": "ItemNiche",
|
||||
"foreignKey": "itemFk"
|
||||
}
|
||||
},
|
||||
"scope": {
|
||||
"where": {
|
||||
"name": {
|
||||
"neq": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -105,20 +105,22 @@
|
|||
on-error-src/>
|
||||
</vn-td>
|
||||
<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)">
|
||||
{{sale.itemFk | zeroFill:6}}
|
||||
{{sale.itemFk}}
|
||||
</span>
|
||||
<vn-autocomplete
|
||||
ng-if="!sale.itemFk"
|
||||
ng-if="!sale.id"
|
||||
vn-focus
|
||||
vn-one
|
||||
url="Items"
|
||||
ng-model="sale.itemFk"
|
||||
show-field="name"
|
||||
value-field="id"
|
||||
search-function="{or: [{id: $search}, {name: {like: '%' + $search + '%'}}]}"
|
||||
order="id DESC">
|
||||
search-function="$ctrl.itemSearchFunc($search)"
|
||||
on-change="$ctrl.onChangeQuantity(sale)"
|
||||
order="id DESC"
|
||||
tabindex="1">
|
||||
<tpl-item>
|
||||
{{id}} - {{name}}
|
||||
</tpl-item>
|
||||
|
@ -137,7 +139,8 @@
|
|||
<vn-td ng-if="!sale.id" number>
|
||||
<vn-input-number
|
||||
ng-model="sale.quantity"
|
||||
on-change="$ctrl.onChangeQuantity(sale)">
|
||||
on-change="$ctrl.onChangeQuantity(sale)"
|
||||
tabindex="2">
|
||||
</vn-input-number>
|
||||
</vn-td>
|
||||
<vn-td-editable disabled="!sale.id || !$ctrl.isEditable" expand>
|
||||
|
@ -150,7 +153,7 @@
|
|||
</vn-fetched-tags>
|
||||
</text>
|
||||
<field>
|
||||
<vn-textfield
|
||||
<vn-textfield class="dense"
|
||||
vn-id="concept"
|
||||
ng-model="sale.concept"
|
||||
on-change="$ctrl.updateConcept(sale)">
|
||||
|
@ -167,7 +170,8 @@
|
|||
<vn-td number>
|
||||
<span ng-class="{'link': !$ctrl.isLocked}"
|
||||
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}}
|
||||
</span>
|
||||
</vn-td>
|
||||
|
|
|
@ -464,9 +464,11 @@ class Controller {
|
|||
* Updates the sale quantity for existing instance
|
||||
*/
|
||||
onChangeQuantity(sale) {
|
||||
if (!sale.quantity) return;
|
||||
|
||||
if (!sale.id)
|
||||
this.addSale(sale);
|
||||
else
|
||||
return this.addSale(sale);
|
||||
|
||||
this.updateQuantity(sale);
|
||||
}
|
||||
|
||||
|
@ -560,6 +562,12 @@ class Controller {
|
|||
this.$scope.model.refresh();
|
||||
});
|
||||
}
|
||||
|
||||
itemSearchFunc($search) {
|
||||
return /^\d+$/.test($search)
|
||||
? {id: $search}
|
||||
: {name: {like: '%' + $search + '%'}};
|
||||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate'];
|
||||
|
|
|
@ -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()', () => {
|
||||
it('should make a POST query saving sale quantity', () => {
|
||||
jest.spyOn(controller.$scope.watcher, 'updateOriginalData');
|
||||
|
|
Loading…
Reference in New Issue