diff --git a/front/core/components/confirm/confirm.html b/front/core/components/confirm/confirm.html index 3debb1cfe..5baf3d450 100644 --- a/front/core/components/confirm/confirm.html +++ b/front/core/components/confirm/confirm.html @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/modules/order/front/prices-popover/index.js b/modules/order/front/prices-popover/index.js index 7e2fb1900..aa5570f59 100644 --- a/modules/order/front/prices-popover/index.js +++ b/modules/order/front/prices-popover/index.js @@ -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 = { diff --git a/modules/order/front/prices-popover/index.spec.js b/modules/order/front/prices-popover/index.spec.js index a68a328a2..653682e52 100644 --- a/modules/order/front/prices-popover/index.spec.js +++ b/modules/order/front/prices-popover/index.spec.js @@ -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); }); });