Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 2896-route_tickets_refactor
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
commit
97e9dc57bc
|
@ -3,5 +3,5 @@
|
||||||
</tpl-body>
|
</tpl-body>
|
||||||
<tpl-buttons>
|
<tpl-buttons>
|
||||||
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}">
|
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}">
|
||||||
<button response="accept" translate>Accept</button>
|
<button response="accept" vn-focus translate>Accept</button>
|
||||||
</tpl-buttons>
|
</tpl-buttons>
|
|
@ -19,8 +19,9 @@ class Controller extends Popover {
|
||||||
}
|
}
|
||||||
|
|
||||||
show(parent, item) {
|
show(parent, item) {
|
||||||
this.item = JSON.parse(JSON.stringify(item));
|
|
||||||
this.id = item.id;
|
this.id = item.id;
|
||||||
|
this.item = JSON.parse(JSON.stringify(item));
|
||||||
|
this.maxQuantity = this.item.available;
|
||||||
this.prices = this.item.prices;
|
this.prices = this.item.prices;
|
||||||
|
|
||||||
super.show(parent);
|
super.show(parent);
|
||||||
|
@ -43,7 +44,6 @@ class Controller extends Popover {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.totalQuantity = total;
|
this.totalQuantity = total;
|
||||||
this.maxQuantity = this.item.available - total;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addQuantity(price) {
|
addQuantity(price) {
|
||||||
|
@ -55,15 +55,16 @@ class Controller extends Popover {
|
||||||
|
|
||||||
getGroupings() {
|
getGroupings() {
|
||||||
const filledRows = [];
|
const filledRows = [];
|
||||||
for (let price of this.prices) {
|
for (let priceOption of this.prices) {
|
||||||
if (price.quantity && price.quantity > 0) {
|
if (priceOption.quantity && priceOption.quantity > 0) {
|
||||||
const priceMatch = filledRows.find(row => {
|
const priceMatch = filledRows.find(row => {
|
||||||
return row.warehouseFk == price.warehouseFk;
|
return row.warehouseFk == priceOption.warehouseFk
|
||||||
|
&& row.price == priceOption.price;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!priceMatch)
|
if (!priceMatch)
|
||||||
filledRows.push(Object.assign({}, price));
|
filledRows.push(Object.assign({}, priceOption));
|
||||||
else priceMatch.quantity += price.quantity;
|
else priceMatch.quantity += priceOption.quantity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,14 +75,14 @@ class Controller extends Popover {
|
||||||
const filledRows = this.getGroupings();
|
const filledRows = this.getGroupings();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const hasValidGropings = filledRows.some(row =>
|
const hasInvalidGropings = filledRows.some(row =>
|
||||||
row.quantity % row.grouping == 0
|
row.quantity % row.grouping != 0
|
||||||
);
|
);
|
||||||
|
|
||||||
if (filledRows.length <= 0)
|
if (filledRows.length <= 0)
|
||||||
throw new Error('First you must add some quantity');
|
throw new Error('First you must add some quantity');
|
||||||
|
|
||||||
if (!hasValidGropings)
|
if (hasInvalidGropings)
|
||||||
throw new Error(`The amounts doesn't match with the grouping`);
|
throw new Error(`The amounts doesn't match with the grouping`);
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
|
|
|
@ -23,6 +23,7 @@ describe('Order', () => {
|
||||||
{warehouseFk: 1, grouping: 100, quantity: 100}
|
{warehouseFk: 1, grouping: 100, quantity: 100}
|
||||||
];
|
];
|
||||||
controller.item = {available: 1000};
|
controller.item = {available: 1000};
|
||||||
|
controller.maxQuantity = 1000;
|
||||||
controller.order = {id: orderId};
|
controller.order = {id: orderId};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -41,11 +42,10 @@ describe('Order', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getTotalQuantity()', () => {
|
describe('getTotalQuantity()', () => {
|
||||||
it('should set the totalQuantity and maxQuantity properties', () => {
|
it('should set the totalQuantity property', () => {
|
||||||
controller.getTotalQuantity();
|
controller.getTotalQuantity();
|
||||||
|
|
||||||
expect(controller.totalQuantity).toEqual(100);
|
expect(controller.totalQuantity).toEqual(100);
|
||||||
expect(controller.maxQuantity).toEqual(900);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue