# HG changeset patch
# User Silambarasan Sekar <silambarasan@qualiantech.com>
# Date 1470822171 -19800
#      Wed Aug 10 15:12:51 2016 +0530
# Branch laeuropea
# Node ID deaf1c73c49967248a161031260b9f134be4e04c
# Parent  1f0e746f8bd0d5cbf889b8d3367fcde84b25397f
[hotfix] Fixes issue 33678: Two issues related to Check Approval
- Approval fails if User has two roles(one inactive and one active) and one same preference for each role
- Approval Fails if User has same preference assigned multiple times

diff -r 1f0e746f8bd0 -r deaf1c73c499 src/org/openbravo/retail/posterminal/utility/CheckApproval.java
--- a/src/org/openbravo/retail/posterminal/utility/CheckApproval.java	Wed Aug 10 15:02:22 2016 +0530
+++ b/src/org/openbravo/retail/posterminal/utility/CheckApproval.java	Wed Aug 10 15:12:51 2016 +0530
@@ -70,7 +70,8 @@
             + "   and (userContact = :user" //
             + "        or exists (from ADUserRoles r"
             + "                  where r.role = p.visibleAtRole"
-            + "                    and r.userContact = :user))"
+            + "                    and r.userContact.id = :user"
+            + "                    and r.active=true))"
             + "   and (p.visibleAtOrganization.id = :org " //
             + " or p.visibleAtOrganization.id in (:orgList) "
             + "   or p.visibleAtOrganization is null) ";
@@ -99,7 +100,7 @@
             }
           }
           jsonData.put("userId", qUserList.get(0).getId());
-          jsonData.put("canApprove", c == approvalType.length());
+          jsonData.put("canApprove", c >= approvalType.length());
           jsonData.put("preference", jsonPreference);
           result.put("data", jsonData);
         }
