This commit is contained in:
parent
e6f7ef41b0
commit
a70b29f9bf
|
@ -3,5 +3,5 @@
|
|||
</tpl-body>
|
||||
<tpl-buttons>
|
||||
<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>
|
|
@ -19,8 +19,9 @@ class Controller extends Popover {
|
|||
}
|
||||
|
||||
show(parent, item) {
|
||||
this.item = JSON.parse(JSON.stringify(item));
|
||||
this.id = item.id;
|
||||
this.item = JSON.parse(JSON.stringify(item));
|
||||
this.maxQuantity = this.item.available;
|
||||
this.prices = this.item.prices;
|
||||
|
||||
super.show(parent);
|
||||
|
@ -43,7 +44,6 @@ class Controller extends Popover {
|
|||
}
|
||||
|
||||
this.totalQuantity = total;
|
||||
this.maxQuantity = this.item.available - total;
|
||||
}
|
||||
|
||||
addQuantity(price) {
|
||||
|
@ -55,15 +55,16 @@ class Controller extends Popover {
|
|||
|
||||
getGroupings() {
|
||||
const filledRows = [];
|
||||
for (let price of this.prices) {
|
||||
if (price.quantity && price.quantity > 0) {
|
||||
for (let priceOption of this.prices) {
|
||||
if (priceOption.quantity && priceOption.quantity > 0) {
|
||||
const priceMatch = filledRows.find(row => {
|
||||
return row.warehouseFk == price.warehouseFk;
|
||||
return row.warehouseFk == priceOption.warehouseFk
|
||||
&& row.price == priceOption.price;
|
||||
});
|
||||
|
||||
if (!priceMatch)
|
||||
filledRows.push(Object.assign({}, price));
|
||||
else priceMatch.quantity += price.quantity;
|
||||
filledRows.push(Object.assign({}, priceOption));
|
||||
else priceMatch.quantity += priceOption.quantity;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,14 +75,14 @@ class Controller extends Popover {
|
|||
const filledRows = this.getGroupings();
|
||||
|
||||
try {
|
||||
const hasValidGropings = filledRows.some(row =>
|
||||
row.quantity % row.grouping == 0
|
||||
const hasInvalidGropings = filledRows.some(row =>
|
||||
row.quantity % row.grouping != 0
|
||||
);
|
||||
|
||||
if (filledRows.length <= 0)
|
||||
throw new Error('First you must add some quantity');
|
||||
|
||||
if (!hasValidGropings)
|
||||
if (hasInvalidGropings)
|
||||
throw new Error(`The amounts doesn't match with the grouping`);
|
||||
|
||||
const params = {
|
||||
|
|
Loading…
Reference in New Issue