changeset:   5587:9b2ceb8e700c
tag:         tip
user:        Guillermo Alvarez de Eulate <guillermo.alvarez@openbravo.com>
date:        Mon Jan 18 17:20:27 2016 +0100
summary:     Fixed issue 31800: Calculate Receipt is not executed when paid receipts are loaded. It will be just executed when layaways are loaded.

diff -r 22d168dadc71 -r 9b2ceb8e700c src/org/openbravo/retail/posterminal/PaidReceiptLinesProperties.java
--- a/src/org/openbravo/retail/posterminal/PaidReceiptLinesProperties.java	Fri Jan 15 10:47:16 2016 +0100
+++ b/src/org/openbravo/retail/posterminal/PaidReceiptLinesProperties.java	Mon Jan 18 17:20:27 2016 +0100
@@ -37,8 +37,10 @@
         add(new HQLProperty("ordLine.orderedQuantity", "quantity"));
         add(new HQLProperty("ordLine.baseGrossUnitPrice", "unitPrice"));
         add(new HQLProperty("ordLine.lineGrossAmount", "linegrossamount"));
+        add(new HQLProperty("ordLine.lineNetAmount", "linenetamount"));
         add(new HQLProperty("ordLine.id", "lineId"));
-        add(new HQLProperty("ordLine.standardPrice", "baseNetUnitPrice"));
+        add(new HQLProperty("ordLine.baseGrossUnitPrice", "nondiscountedprice"));
+        add(new HQLProperty("ordLine.unitPrice", "baseNetUnitPrice"));
         add(new HQLProperty("ordLine.salesOrder.currency.pricePrecision", "pricePrecision"));
         add(new HQLProperty("ordLine.warehouse.id", "warehouse"));
         add(new HQLProperty("ordLine.warehouse.name", "warehousename"));
diff -r 22d168dadc71 -r 9b2ceb8e700c src/org/openbravo/retail/posterminal/PaidReceipts.java
--- a/src/org/openbravo/retail/posterminal/PaidReceipts.java	Fri Jan 15 10:47:16 2016 +0100
+++ b/src/org/openbravo/retail/posterminal/PaidReceipts.java	Mon Jan 18 17:20:27 2016 +0100
@@ -134,7 +134,7 @@
           OBDal.getInstance().getSession().createQuery(hqlPaidReceiptsShipLines);
           Query paidReceiptsShipLinesQuery = OBDal.getInstance().getSession()
               .createQuery(hqlPaidReceiptsShipLines);
-          paidReceiptsShipLinesQuery.setString(0, (String) objpaidReceiptsLines[6]);
+          paidReceiptsShipLinesQuery.setString(0, (String) objpaidReceiptsLines[7]);
 
           // cycle through the lines of the selected order
           JSONArray shipmentlines = new JSONArray();
@@ -155,7 +155,7 @@
           OBCriteria<OrderLineOffer> qPromotions = OBDal.getInstance().createCriteria(
               OrderLineOffer.class);
           qPromotions.add(Restrictions.eq(OrderLineOffer.PROPERTY_SALESORDERLINE + ".id",
-              (String) objpaidReceiptsLines[6]));
+              (String) objpaidReceiptsLines[7]));
           qPromotions.addOrder(Order.asc(OrderLineOffer.PROPERTY_LINENO));
           JSONArray promotions = new JSONArray();
           boolean hasPromotions = false;
@@ -189,7 +189,7 @@
             lineAmount = (BigDecimal) objpaidReceiptsLines[5];
           }
           paidReceiptLine.put("linegrossamount", lineAmount);
-
+          paidReceiptLine.put("nondiscountednet", lineAmount);
           paidReceiptLine.put("promotions", promotions);
 
           listpaidReceiptsLines.put(paidReceiptLine);
diff -r 22d168dadc71 -r 9b2ceb8e700c web/org.openbravo.retail.posterminal/js/components/modalpaidreceipts.js
--- a/web/org.openbravo.retail.posterminal/js/components/modalpaidreceipts.js	Fri Jan 15 10:47:16 2016 +0100
+++ b/web/org.openbravo.retail.posterminal/js/components/modalpaidreceipts.js	Mon Jan 18 17:20:27 2016 +0100
@@ -487,7 +487,9 @@
   },
   changePaidReceipt: function (inSender, inEvent) {
     this.model.get('orderList').addPaidReceipt(inEvent.newPaidReceipt);
-    this.model.attributes.order.calculateReceipt();
+    if (inEvent.newPaidReceipt.get('isLayaway')) {
+      this.model.attributes.order.calculateReceipt();
+    }
     return true;
   },
   executeOnShow: function () {
diff -r 22d168dadc71 -r 9b2ceb8e700c web/org.openbravo.retail.posterminal/js/data/dataordertaxes.js
--- a/web/org.openbravo.retail.posterminal/js/data/dataordertaxes.js	Fri Jan 15 10:47:16 2016 +0100
+++ b/web/org.openbravo.retail.posterminal/js/data/dataordertaxes.js	Mon Jan 18 17:20:27 2016 +0100
@@ -616,7 +616,7 @@
 
       line.set({
         'pricenet': line.get('price'),
-        'net': OB.DEC.mul(line.get('price'), line.get('qty')),
+        'net': OB.DEC.mul(line.get('nondiscountedprice') || line.get('price'), line.get('qty')),
         'linerate': OB.DEC.One,
         'tax': null,
         'taxAmount': OB.DEC.Zero,
diff -r 22d168dadc71 -r 9b2ceb8e700c web/org.openbravo.retail.posterminal/js/model/order.js
--- a/web/org.openbravo.retail.posterminal/js/model/order.js	Fri Jan 15 10:47:16 2016 +0100
+++ b/web/org.openbravo.retail.posterminal/js/model/order.js	Mon Jan 18 17:20:27 2016 +0100
@@ -129,7 +129,7 @@
         this.set('gross', null, {
           silent: true
         });
-        this.set('net', OB.DEC.mul(this.get('qty'), this.get('price')));
+        this.set('net', OB.DEC.mul(this.get('qty'), this.get('nondiscountedprice') || this.get('price')));
       }
     },
 
@@ -697,9 +697,17 @@
       });
       // If line is null or undefined, we calculate the Promotions of the receipt
       if (OB.UTIL.isNullOrUndefined(line)) {
-        OB.Model.Discounts.applyPromotions(this);
+        if (this.get('promotionsAlreadyCalculated')) {
+          this.trigger('applyPromotionsFinished');
+        } else {
+          OB.Model.Discounts.applyPromotions(this);
+        }
       } else {
-        OB.Model.Discounts.applyPromotions(this, line);
+        if (this.get('promotionsAlreadyCalculated')) {
+          this.trigger('applyPromotionsFinished');
+        } else {
+          OB.Model.Discounts.applyPromotions(this, line);
+        }
       }
     },
 
@@ -1782,6 +1790,19 @@
         //remove promotions
         line.unset('promotions');
 
+        //issues 24994 & 24993
+        //if the order is created from quotation just after save the quotation
+        //(without load the quotation from quotations window). The order has the fields added
+        //by adjust prices. We need to work without these values
+        //price not including taxes
+        line.unset('nondiscountedprice');
+        line.unset('nondiscountednet');
+        //price including taxes
+        line.unset('netFull');
+        line.unset('grossListPrice');
+        line.unset('grossUnitPrice');
+        line.unset('lineGrossAmount');
+
         var successCallbackPrices, criteria = {
           'id': line.get('product').get('id')
         };
@@ -1810,6 +1831,7 @@
     },
 
     createOrderFromQuotation: function (updatePrices) {
+      var me = this;
       this.get('lines').each(function (line) {
         line.set('id', OB.UTIL.get_UUID());
         //issue 25055 -> If we don't do the following prices and taxes are calculated
@@ -1818,21 +1840,10 @@
         //It only happens if the order is created from quotation just after save the quotation
         //(without load the quotation from quotations window)
         if (!this.get('priceIncludesTax')) {
-          line.set('net', line.get('nondiscountednet'));
+          if (line.get('nondiscountednet')) {
+            line.set('net', line.get('nondiscountednet'));
+          }
         }
-
-        //issues 24994 & 24993
-        //if the order is created from quotation just after save the quotation
-        //(without load the quotation from quotations window). The order has the fields added
-        //by adjust prices. We need to work without these values
-        //price not including taxes
-        line.unset('nondiscountedprice');
-        line.unset('nondiscountednet');
-        //price including taxes
-        line.unset('netFull');
-        line.unset('grossListPrice');
-        line.unset('grossUnitPrice');
-        line.unset('lineGrossAmount');
       }, this);
 
       this.set('id', null);
@@ -1859,14 +1870,21 @@
       this.set('documentNo', nextDocumentno.documentNo);
       this.set('posTerminal', OB.MobileApp.model.get('terminal').id);
       this.set('session', OB.MobileApp.model.get('session'));
-      this.save();
-      if (updatePrices) {
-        this.updatePrices(function (order) {
-          OB.UTIL.showSuccess(OB.I18N.getLabel('OBPOS_QuotationCreatedOrder'));
-        });
-      } else {
-        OB.UTIL.showSuccess(OB.I18N.getLabel('OBPOS_QuotationCreatedOrder'));
-      }
+      this.save(function () {
+        if (updatePrices) {
+          me.updatePrices(function (order) {
+            order.calculateReceipt(function () {
+              OB.UTIL.showSuccess(OB.I18N.getLabel('OBPOS_QuotationCreatedOrder'));
+            });
+          });
+        } else {
+          me.set('promotionsAlreadyCalculated', true);
+          me.calculateReceipt(function () {
+            me.unset('promotionsAlreadyCalculated');
+            OB.UTIL.showSuccess(OB.I18N.getLabel('OBPOS_QuotationCreatedOrder'));
+          });
+        }
+      });
     },
 
     reactivateQuotation: function () {
@@ -1874,7 +1892,9 @@
       this.get('lines').each(function (line) {
         line.set('id', OB.UTIL.get_UUID());
         if (!this.get('priceIncludesTax')) {
-          line.set('net', line.get('nondiscountednet'));
+          if (line.get('nondiscountednet')) {
+            line.set('net', line.get('nondiscountednet'));
+          }
         }
         line.unset('nondiscountedprice');
         line.unset('nondiscountednet');
@@ -2758,6 +2778,12 @@
                   }
                 });
 
+                if (order.get('priceIncludesTax')) {
+                  newline.set('gross', OB.DEC.number(iter.linegrossamount));
+                } else {
+                  newline.set('net', OB.DEC.number(iter.linenetamount));
+                }
+
                 // copy verbatim not owned properties -> modular properties.
                 _.each(iter, function (value, key) {
                   if (!newline.ownProperties[key]) {

