# HG changeset patch
# User Silambarasan Sekar <silambarasan@qualiantech.com>
# Date 1473066040 -19800
#      Mon Sep 05 14:30:40 2016 +0530
# Node ID 5e829b87b5f0e848d127de42515a45a6738d1b93
# Parent  027dc930d1761e778089716c0cae4b9f5c9d3cee
Fixes issue 33890: Thorw Error when processing Orders without payments

diff -r 027dc930d176 -r 5e829b87b5f0 src/org/openbravo/retail/posterminal/OrderLoader.java
--- a/src/org/openbravo/retail/posterminal/OrderLoader.java	Wed Sep 07 10:43:15 2016 -0600
+++ b/src/org/openbravo/retail/posterminal/OrderLoader.java	Mon Sep 05 14:30:40 2016 +0530
@@ -1782,8 +1782,15 @@
     } else {
       JSONArray payments = jsonorder.getJSONArray("payments");
 
+      // Check if order has valid payments
+      BigDecimal amt = BigDecimal.valueOf(jsonorder.getDouble("payment"));
+      if ((jsonorder.getLong("orderType") == 0 || jsonorder.getLong("orderType") == 1)
+          && payments.length() == 0 && !wasPaidOnCredit && !jsonorder.getBoolean("isLayaway")
+          && amt.compareTo(BigDecimal.ZERO) > 0) {
+        throw new OBException("Error in OrderLoader, Payments not found");
+      }
+
       // 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 pricePrecision = order.getCurrency().getObposPosprecision() == null ? order.getCurrency()
           .getPricePrecision().intValue() : order.getCurrency().getObposPosprecision().intValue();
