diff --git a/web/org.openbravo.retail.discounts.coupons.otf/js/model/DiscountRule.js b/web/org.openbravo.retail.discounts.coupons.otf/js/model/DiscountRule.js
index cb9514d..da00ff6 100644
--- a/web/org.openbravo.retail.discounts.coupons.otf/js/model/DiscountRule.js
+++ b/web/org.openbravo.retail.discounts.coupons.otf/js/model/DiscountRule.js
@@ -43,33 +43,40 @@
                 _.each(receipt.get('coupons'), function(coupon) {
                   totaldiscount += coupon.otfAmount;
                 });
-                _.each(preprocess.linesToCompute, function(l, index, list) {
-                  var discount;
-                  // distributing  discount in all lines based on total of each one
-                  // if PIT, in gross
-                  // if no PIT, in net
-                  if (index < list.length - 1) {
-                    discount = OB.DEC.toNumber(
-                      OB.DEC.toBigDecimal(l.total).multiply(
-                        OB.DEC.toBigDecimal(totaldiscount).divide(
-                          OB.DEC.toBigDecimal(
-                            preprocess.totalNet || preprocess.total
-                          ),
-                          20,
-                          OB.DEC.getRoundingMode()
+                preprocess.linesToCompute
+                  .sort((line1, line2) => {
+                    return line1.total - line2.total;
+                  })
+                  .forEach(function(l, index, list) {
+                    var discount;
+                    // distributing  discount in all lines based on total of each one
+                    // if PIT, in gross
+                    // if no PIT, in net
+                    if (index < list.length - 1) {
+                      discount = OB.DEC.toNumber(
+                        OB.DEC.toBigDecimal(l.total).multiply(
+                          OB.DEC.toBigDecimal(totaldiscount).divide(
+                            OB.DEC.toBigDecimal(
+                              preprocess.totalNet || preprocess.total
+                            ),
+                            20,
+                            OB.DEC.getRoundingMode()
+                          )
                         )
-                      )
-                    );
-                  } else {
-                    discount = OB.DEC.sub(totaldiscount, accumdiscount);
-                  }
-                  accumdiscount = OB.DEC.add(accumdiscount, discount);
-                  receipt.addPromotion(l.line, discountRule, {
-                    amt: discount,
-                    forceReplace: true,
-                    executedAtTheEndPromo: true
+                      );
+                    } else {
+                      discount = Math.min(
+                        l.total,
+                        OB.DEC.sub(totaldiscount, accumdiscount)
+                      );
+                    }
+                    accumdiscount = OB.DEC.add(accumdiscount, discount);
+                    receipt.addPromotion(l.line, discountRule, {
+                      amt: discount,
+                      forceReplace: true,
+                      executedAtTheEndPromo: true
+                    });
                   });
-                });
               } else {
                 // Restore original promotions
                 for (i = 0; i < receipt.get('lines').length; i++) {
