Merge branch 'test' of https://gitea.verdnatura.es/verdnatura/salix into dev
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Joan Sanchez 2021-05-14 12:56:10 +02:00
commit c0f2590b61
2 changed files with 12 additions and 11 deletions

View File

@ -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>

View File

@ -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 = {