# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1456229304 -19800
# Node ID a32913c758a0872f994b8759f3ab360209365135
# Parent  06df429840390b817fb4201581018dc888a1cda5
Fixes issue 31828 : Order Loader Changing Standard Precision to Price Precision for Order, Invoice, Tax & Payment

diff -r 06df42984039 -r a32913c758a0 src/org/openbravo/retail/posterminal/OrderLoader.java
--- a/src/org/openbravo/retail/posterminal/OrderLoader.java	Fri Nov 27 14:37:00 2015 +0530
+++ b/src/org/openbravo/retail/posterminal/OrderLoader.java	Tue Feb 23 17:38:24 2016 +0530
@@ -797,7 +797,7 @@
 
   protected void createInvoiceLines(Invoice invoice, Order order, JSONObject jsonorder,
       JSONArray orderlines, ArrayList<OrderLine> lineReferences) throws JSONException {
-    int stdPrecision = order.getCurrency().getStandardPrecision().intValue();
+    int stdPrecision = order.getCurrency().getPricePrecision().intValue();
 
     boolean multipleShipmentsLines = false;
     int lineNo = 0;
@@ -862,7 +862,7 @@
       invoice.setId(jsonorder.getString("id"));
       invoice.setNewOBObject(true);
     }
-    int stdPrecision = order.getCurrency().getStandardPrecision().intValue();
+    int stdPrecision = order.getCurrency().getPricePrecision().intValue();
 
     String description;
     if (jsonorder.has("Invoice.description")) {
@@ -963,7 +963,7 @@
   }
 
   protected void updateTaxes(Invoice invoice) throws JSONException {
-    int stdPrecision = invoice.getCurrency().getStandardPrecision().intValue();
+    int stdPrecision = invoice.getCurrency().getPricePrecision().intValue();
     for (InvoiceTax taxInv : invoice.getInvoiceTaxList()) {
       BigDecimal taxAmt = BigDecimal.ZERO;
       BigDecimal taxableAmt = BigDecimal.ZERO;
@@ -991,7 +991,7 @@
   }
 
   public static BigDecimal convertCurrencyInvoice(Invoice invoice) {
-    int stdPrecision = invoice.getCurrency().getStandardPrecision().intValue();
+    int stdPrecision = invoice.getCurrency().getPricePrecision().intValue();
     List<Object> parameters = new ArrayList<Object>();
     List<Class<?>> types = new ArrayList<Class<?>>();
     parameters.add(invoice.getGrandTotalAmount().setScale(stdPrecision, RoundingMode.HALF_UP));
@@ -1237,7 +1237,7 @@
       ArrayList<OrderLine> lineReferences) throws JSONException {
     Entity orderLineEntity = ModelProvider.getInstance().getEntity(OrderLine.class);
     Entity promotionLineEntity = ModelProvider.getInstance().getEntity(OrderLineOffer.class);
-    int stdPrecision = order.getCurrency().getStandardPrecision().intValue();
+    int stdPrecision = order.getCurrency().getPricePrecision().intValue();
 
     for (int i = 0; i < orderlines.length(); i++) {
 
@@ -1407,7 +1407,7 @@
       order.setId(jsonorder.getString("id"));
       order.setNewOBObject(true);
     }
-    int stdPrecision = order.getCurrency().getStandardPrecision().intValue();
+    int stdPrecision = order.getCurrency().getPricePrecision().intValue();
     BusinessPartner bp = order.getBusinessPartner();
     order.setTransactionDocument((DocumentType) OBDal.getInstance().getProxy("DocumentType",
         jsonorder.getString("documentType")));
@@ -1626,11 +1626,11 @@
       // Create a unique payment schedule for all payments
       BigDecimal amt = BigDecimal.valueOf(jsonorder.getDouble("payment"));
       FIN_PaymentSchedule paymentSchedule = OBProvider.getInstance().get(FIN_PaymentSchedule.class);
-      int stdPrecision = order.getCurrency().getStandardPrecision().intValue();
+      int stdPrecision = order.getCurrency().getPricePrecision().intValue();
       if ((!newLayaway && (notpaidLayaway || creditpaidLayaway || fullypaidLayaway))
           || partialpaidLayaway) {
         paymentSchedule = order.getFINPaymentScheduleList().get(0);
-        stdPrecision = order.getCurrency().getStandardPrecision().intValue();
+        stdPrecision = order.getCurrency().getPricePrecision().intValue();
       } else {
         paymentSchedule = OBProvider.getInstance().get(FIN_PaymentSchedule.class);
         paymentSchedule.setId(order.getId());
@@ -1639,7 +1639,7 @@
         paymentSchedule.setOrder(order);
         paymentSchedule.setFinPaymentmethod(order.getBusinessPartner().getPaymentMethod());
         // paymentSchedule.setPaidAmount(new BigDecimal(0));
-        stdPrecision = order.getCurrency().getStandardPrecision().intValue();
+        stdPrecision = order.getCurrency().getPricePrecision().intValue();
         paymentSchedule.setAmount(BigDecimal.valueOf(jsonorder.getDouble("gross")).setScale(
             stdPrecision, RoundingMode.HALF_UP));
         // Sept 2012 -> gross because outstanding is not allowed in Openbravo Web POS
@@ -1842,7 +1842,7 @@
       boolean totalIsNegative = jsonorder.getDouble("gross") < 0;
       boolean checkPaidOnCreditChecked = (jsonorder.has("paidOnCredit") && jsonorder
           .getBoolean("paidOnCredit"));
-      int stdPrecision = order.getCurrency().getStandardPrecision().intValue();
+      int stdPrecision = order.getCurrency().getPricePrecision().intValue();
       BigDecimal amount = BigDecimal.valueOf(payment.getDouble("origAmount")).setScale(
           stdPrecision, RoundingMode.HALF_UP);
       BigDecimal origAmount = amount;
diff -r 06df42984039 -r a32913c758a0 web/org.openbravo.retail.posterminal/js/closecash/view/closecash.js
--- a/web/org.openbravo.retail.posterminal/js/closecash/view/closecash.js	Fri Nov 27 14:37:00 2015 +0530
+++ b/web/org.openbravo.retail.posterminal/js/closecash/view/closecash.js	Tue Feb 23 17:38:24 2016 +0530
@@ -268,8 +268,8 @@
     }, this);
 
     this.model.on('change:totalCounted', function () {
-      this.$.cashupMultiColumn.$.leftPanel.$.listPaymentMethods.$.difference.printAmount(OB.DEC.sub(this.model.get('totalCounted'), this.model.get('totalExpected')));
       this.model.set("totalDifference", OB.DEC.sub(this.model.get('totalCounted'), OB.Utilities.Number.roundJSNumber(this.model.get('totalExpected'), 2)));
+      this.$.cashupMultiColumn.$.leftPanel.$.listPaymentMethods.$.difference.printAmount(this.model.get("totalDifference"));
       this.waterfall('onAnyCounted');
       this.refreshButtons();
     }, this);
