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

This commit is contained in:
Carlos Jimenez Ruiz 2021-05-14 19:22:15 +02:00
commit 97e9dc57bc
3 changed files with 14 additions and 13 deletions

View File

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

View File

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

View File

@ -23,6 +23,7 @@ describe('Order', () => {
{warehouseFk: 1, grouping: 100, quantity: 100}
];
controller.item = {available: 1000};
controller.maxQuantity = 1000;
controller.order = {id: orderId};
}));
@ -41,11 +42,10 @@ describe('Order', () => {
});
describe('getTotalQuantity()', () => {
it('should set the totalQuantity and maxQuantity properties', () => {
it('should set the totalQuantity property', () => {
controller.getTotalQuantity();
expect(controller.totalQuantity).toEqual(100);
expect(controller.maxQuantity).toEqual(900);
});
});