details: https://code.openbravo.com/erp/devel/pi/rev/3ae7799bc934 changeset: 27189:3ae7799bc934 user: Atul Gaware <atul.gaware <at> openbravo.com> date: Sat Jul 11 10:35:43 2015 +0530 summary: Fixes Issue 30292:Wrong Document Type calculation when there are types configured in the legal entity and the store (generic child organization)
Instead of OBCriteria, OBQuery is implemented in order to sort record by organization parent level using ad_isorgincluded function prior to default flag and id. details: https://code.openbravo.com/erp/devel/pi/rev/ebfc013a13c0 changeset: 27190:ebfc013a13c0 user: Víctor Martínez Romanos <victor.martinez <at> openbravo.com> date: Mon Jul 13 13:15:38 2015 +0200 summary: Related to issue 30292: code review improvements 1. Ordered by dt.default desc to get first the records with default = Y 2. Ordered by dt.id desc as it was in the original code. Note that this order is different from the one used at AD_GET_DOCTYPE. However I have kept this order to to get the same records as in the past (otherwise it could be considered as a functional regression) 3. Limit query to just 1 record to improve performance diffstat: modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/utility/FIN_Utility.java | 37 +++++---- 1 files changed, 22 insertions(+), 15 deletions(-) diffs (55 lines): diff -r 62725e97926d -r ebfc013a13c0 modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/utility/FIN_Utility.java --- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/utility/FIN_Utility.java Fri Jul 10 13:19:36 2015 +0200 +++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/utility/FIN_Utility.java Mon Jul 13 13:15:38 2015 +0200 @@ -283,10 +283,6 @@ DocumentType outDocType = null; Client client = null; - OBCriteria<DocumentType> obcDoc = OBDal.getInstance().createCriteria(DocumentType.class); - obcDoc.setFilterOnReadableClients(false); - obcDoc.setFilterOnReadableOrganization(false); - if ("0".equals(org.getId())) { client = OBContext.getOBContext().getCurrentClient(); if ("0".equals(client.getId())) { @@ -295,18 +291,29 @@ } else { client = org.getClient(); } - obcDoc.add(Restrictions.eq(DocumentType.PROPERTY_CLIENT, client)); - obcDoc - .add(Restrictions.in("organization.id", - OBContext.getOBContext().getOrganizationStructureProvider(org.getClient().getId()) - .getParentTree(org.getId(), true))); - obcDoc.add(Restrictions.eq(DocumentType.PROPERTY_DOCUMENTCATEGORY, docCategory)); - obcDoc.addOrderBy(DocumentType.PROPERTY_DEFAULT, false); - obcDoc.addOrderBy(DocumentType.PROPERTY_ID, false); - List<DocumentType> docTypeList = obcDoc.list(); - if (docTypeList != null && docTypeList.size() > 0) { - outDocType = docTypeList.get(0); + OBContext.setAdminMode(false); + try { + StringBuilder whereOrderByClause = new StringBuilder(); + whereOrderByClause.append(" as dt where dt.organization.id in ("); + whereOrderByClause.append(Utility.getInStrSet(new OrganizationStructureProvider() + .getParentTree(org.getId(), true))); + whereOrderByClause.append(") and dt.client.id = '" + client.getId() + + "' and dt.documentCategory = '" + docCategory + "' order by ad_isorgincluded('" + + org.getId() + "', dt.organization.id, '" + client.getId() + + "') , dt.default desc, dt.id desc"); + OBQuery<DocumentType> dt = OBDal.getInstance().createQuery(DocumentType.class, + whereOrderByClause.toString()); + dt.setFilterOnReadableClients(false); + dt.setFilterOnReadableOrganization(false); + dt.setMaxResult(1); + + List<DocumentType> dtList = dt.list(); + if (dtList != null && !dtList.isEmpty()) { + outDocType = dtList.get(0); + } + } finally { + OBContext.restorePreviousMode(); } return outDocType; } ------------------------------------------------------------------------------ Don't Limit Your Business. Reach for the Cloud. GigeNET's Cloud Solutions provide you with the tools and support that you need to offload your IT needs and focus on growing your business. Configured For All Businesses. Start Your Cloud Today. https://www.gigenetcloud.com/ _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits