details: https://code.openbravo.com/erp/devel/pi/rev/4f00f31f65e1 changeset: 26282:4f00f31f65e1 user: Reinaldo Guerra <reinaldo.guerra <at> peoplewalking.com> date: Wed Mar 25 12:25:21 2015 -0500 summary: Fixed bug 28907, fixed bug 27848, fixed bug 29003
The following changes was made in Stock Reservation pick and edit: When filters are executed, a Reservation entity is created from the json parameter "@MaterialMgmtReservation.id@". This works fine when the pop-up is called from Stock Reservation window, but from Sales Order, this parameter does not exists, and the filter process fails. Now is included a code line that puts a "@MaterialMgmtReservation.id@" into the json parameters before the filters are applied. Array critera filtering was bad created when getting grid's data, so was changed, to allow filter's multiple selection. An hibernate exception is launched when typing wrong filters and the expression "in ()" is included in the query to be executed. So this expression was replaced by one which returns a false value: "1 = 2". Were included also, changes to allow filtering quantity's column. Other changes were included to avoid exceptions comparing to null values. details: https://code.openbravo.com/erp/devel/pi/rev/621618711608 changeset: 26283:621618711608 user: Reinaldo Guerra <reinaldo.guerra <at> peoplewalking.com> date: Thu Mar 26 12:49:23 2015 -0500 summary: Related to issue 28907: Empty filter when there is no attribute set value. When records are created in Stock Reservation pick and edit, the 0 value retrieved from default attribute set instance, defined in reservation's tables, is now set to null, when creating filter criteria. Now if there is no attribute set defined for reservation's products, the attribute set value filter is empty. details: https://code.openbravo.com/erp/devel/pi/rev/12e2fb2008f2 changeset: 26284:12e2fb2008f2 user: Alvaro Ferraz <alvaro.ferraz <at> openbravo.com> date: Thu Mar 26 13:56:32 2015 +0100 summary: Related to 29003: Avoid exception Avoid exceptions in getOrderLineSetValueFilterData and getAttributeSetValueFilterData methods details: https://code.openbravo.com/erp/devel/pi/rev/bb85cbd52ff0 changeset: 26285:bb85cbd52ff0 user: Alvaro Ferraz <alvaro.ferraz <at> openbravo.com> date: Thu Mar 26 14:17:07 2015 +0100 summary: Related to 29003: Avoid exception when filtering by number Avoid exceptions when retrieving the value of the filter in number-type columns and the value is not a number diffstat: src/org/openbravo/common/datasource/StockReservationPickAndEditDataSource.java | 616 +++++++-- 1 files changed, 471 insertions(+), 145 deletions(-) diffs (truncated from 892 to 300 lines): diff -r 60a8ed1b0650 -r bb85cbd52ff0 src/org/openbravo/common/datasource/StockReservationPickAndEditDataSource.java --- a/src/org/openbravo/common/datasource/StockReservationPickAndEditDataSource.java Fri Mar 27 01:11:08 2015 +0000 +++ b/src/org/openbravo/common/datasource/StockReservationPickAndEditDataSource.java Thu Mar 26 14:17:07 2015 +0100 @@ -142,7 +142,10 @@ JSONArray criterias = (JSONArray) JsonUtils.buildCriteria(parameters).get("criteria"); for (int i = 0; i < criterias.length(); i++) { final JSONObject criteria = criterias.getJSONObject(i); - filterCriteria.put(criteria.getString("fieldName"), criteria.getString("value")); + if (criteria.has("fieldName")) { + filterCriteria.put(criteria.getString("fieldName"), + criteria.has("value") ? criteria.getString("value") : criteria.toString()); + } } } catch (JSONException e) { log4j.error("Error while building the criteria", e); @@ -170,12 +173,14 @@ ids.add((String) record.get("purchaseOrderLine")); } OBCriteria<OrderLine> obc = OBDal.getInstance().createCriteria(OrderLine.class); - obc.add(Restrictions.in(OrderLine.PROPERTY_ID, ids)); - obc.setFilterOnReadableClients(false); - obc.setFilterOnReadableOrganization(false); - obc.setFilterOnActive(false); - obc.addOrderBy(OrderLine.PROPERTY_SALESORDER, false); - obc.addOrderBy(OrderLine.PROPERTY_LINENO, true); + if (ids.size() > 0) { + obc.add(Restrictions.in(OrderLine.PROPERTY_ID, ids)); + obc.setFilterOnReadableClients(false); + obc.setFilterOnReadableOrganization(false); + obc.setFilterOnActive(false); + obc.addOrderBy(OrderLine.PROPERTY_SALESORDER, false); + obc.addOrderBy(OrderLine.PROPERTY_LINENO, true); + } return obc.list(); } @@ -187,7 +192,8 @@ JSONArray criterias = (JSONArray) JsonUtils.buildCriteria(parameters).get("criteria"); for (int i = 0; i < criterias.length(); i++) { final JSONObject criteria = criterias.getJSONObject(i); - filterCriteria.put(criteria.getString("fieldName"), criteria.getString("value")); + filterCriteria.put(criteria.getString("fieldName"), + criteria.has("value") ? criteria.getString("value") : criteria.toString()); } } catch (JSONException e) { log4j.error("Error while building the criteria", e); @@ -222,11 +228,13 @@ ids.add((String) record.get("warehouse")); } OBCriteria<Warehouse> obc = OBDal.getInstance().createCriteria(Warehouse.class); - obc.add(Restrictions.in(Warehouse.PROPERTY_ID, ids)); - obc.setFilterOnReadableClients(false); - obc.setFilterOnReadableOrganization(false); - obc.setFilterOnActive(false); - obc.addOrderBy(Warehouse.PROPERTY_NAME, true); + if (ids.size() > 0) { + obc.add(Restrictions.in(Warehouse.PROPERTY_ID, ids)); + obc.setFilterOnReadableClients(false); + obc.setFilterOnReadableOrganization(false); + obc.setFilterOnActive(false); + obc.addOrderBy(Warehouse.PROPERTY_NAME, true); + } return obc.list(); } @@ -274,7 +282,12 @@ } } else if (myJSONObject.get("fieldName").equals("warehouse") && myJSONObject.get("operator").equals("equals") && myJSONObject.has("value")) { - myCriterion = Restrictions.eq(Warehouse.PROPERTY_ID, myJSONObject.get("value")); + if (myCriterion == null) { + myCriterion = Restrictions.eq(Warehouse.PROPERTY_ID, myJSONObject.get("value")); + } else { + myCriterion = Restrictions.or(myCriterion, + Restrictions.eq(Warehouse.PROPERTY_ID, myJSONObject.get("value"))); + } } } if (myCriterion != null) { @@ -317,7 +330,8 @@ JSONArray criterias = (JSONArray) JsonUtils.buildCriteria(parameters).get("criteria"); for (int i = 0; i < criterias.length(); i++) { final JSONObject criteria = criterias.getJSONObject(i); - filterCriteria.put(criteria.getString("fieldName"), criteria.getString("value")); + filterCriteria.put(criteria.getString("fieldName"), + criteria.has("value") ? criteria.getString("value") : criteria.toString()); } } catch (JSONException e) { log4j.error("Error while building the criteria", e); @@ -351,14 +365,16 @@ ids.add((String) record.get("storageBin")); } OBCriteria<Locator> obc = OBDal.getInstance().createCriteria(Locator.class); - obc.add(Restrictions.in(Locator.PROPERTY_ID, ids)); - obc.setFilterOnReadableClients(false); - obc.setFilterOnReadableOrganization(false); - obc.setFilterOnActive(false); - obc.addOrderBy(Locator.PROPERTY_WAREHOUSE, true); - obc.addOrderBy(Locator.PROPERTY_ROWX, true); - obc.addOrderBy(Locator.PROPERTY_STACKY, true); - obc.addOrderBy(Locator.PROPERTY_LEVELZ, true); + if (ids.size() > 0) { + obc.add(Restrictions.in(Locator.PROPERTY_ID, ids)); + obc.setFilterOnReadableClients(false); + obc.setFilterOnReadableOrganization(false); + obc.setFilterOnActive(false); + obc.addOrderBy(Locator.PROPERTY_WAREHOUSE, true); + obc.addOrderBy(Locator.PROPERTY_ROWX, true); + obc.addOrderBy(Locator.PROPERTY_STACKY, true); + obc.addOrderBy(Locator.PROPERTY_LEVELZ, true); + } return obc.list(); } @@ -402,7 +418,12 @@ } } else if (myJSONObject.get("fieldName").equals("storageBin") && operator.equals("equals") && myJSONObject.has("value")) { - myCriterion = Restrictions.eq(Locator.PROPERTY_ID, myJSONObject.get("value")); + if (myCriterion == null) { + myCriterion = Restrictions.eq(Locator.PROPERTY_ID, myJSONObject.get("value")); + } else { + myCriterion = Restrictions.or(myCriterion, + Restrictions.eq(Locator.PROPERTY_ID, myJSONObject.get("value"))); + } } } if (myCriterion != null) { @@ -430,7 +451,10 @@ JSONArray criterias = (JSONArray) JsonUtils.buildCriteria(parameters).get("criteria"); for (int i = 0; i < criterias.length(); i++) { final JSONObject criteria = criterias.getJSONObject(i); - filterCriteria.put(criteria.getString("fieldName"), criteria.getString("value")); + if (criteria.has("fieldName")) { + filterCriteria.put(criteria.getString("fieldName"), + criteria.has("value") ? criteria.getString("value") : criteria.toString()); + } } } catch (JSONException e) { log4j.error("Error while building the criteria", e); @@ -460,11 +484,13 @@ } OBCriteria<AttributeSetInstance> obc = OBDal.getInstance().createCriteria( AttributeSetInstance.class); - obc.add(Restrictions.in(AttributeSetInstance.PROPERTY_ID, ids)); - obc.setFilterOnReadableClients(false); - obc.setFilterOnReadableOrganization(false); - obc.setFilterOnActive(false); - obc.addOrderBy(AttributeSetInstance.PROPERTY_DESCRIPTION, true); + if (ids.size() > 0) { + obc.add(Restrictions.in(AttributeSetInstance.PROPERTY_ID, ids)); + obc.setFilterOnReadableClients(false); + obc.setFilterOnReadableOrganization(false); + obc.setFilterOnActive(false); + obc.addOrderBy(AttributeSetInstance.PROPERTY_DESCRIPTION, true); + } return obc.list(); } @@ -492,8 +518,8 @@ if (filterCriteria.containsKey(mySon.getJSONObject(j).getString("fieldName"))) { JSONArray values = new JSONArray(filterCriteria.get(mySon.getJSONObject(j).getString( "fieldName"))); - filterCriteria.put(mySon.getJSONObject(j).getString("fieldName"), values.put(mySon) - .toString()); + filterCriteria.put(mySon.getJSONObject(j).getString("fieldName"), + values.put(mySon.getJSONObject(j)).toString()); } else { filterCriteria.put(mySon.getJSONObject(j).getString("fieldName"), new JSONArray() .put(mySon.getJSONObject(j)).toString()); @@ -532,6 +558,11 @@ String strReservation = parameters.get("@MaterialMgmtReservation.id@"); ol = parameters.get("@OrderLine.id@"); Reservation reservation = null; + if (ol != null && !"".equals(ol)) { + reservation = ReservationUtils.getReservationFromOrder(OBDal.getInstance().get( + OrderLine.class, ol)); + parameters.put("@MaterialMgmtReservation.id@", reservation.getId()); + } // Filters List<Warehouse> warehousesFiltered = null; if (filterCriteria.get("warehouse$_identifier") != null @@ -585,6 +616,10 @@ if (filterCriteria.get("allocated") != null) { allocatedCriteria = filterCriteria.get("allocated"); } + String quantityCriteria = ""; + if (filterCriteria.get("quantity") != null) { + quantityCriteria = filterCriteria.get("quantity"); + } if (ol != null && !"".equals(ol)) { reservation = ReservationUtils.getReservationFromOrder(OBDal.getInstance().get( @@ -602,21 +637,26 @@ Set<String> organizations = new OrganizationStructureProvider().getChildTree(strOrganization, true); try { - result.addAll(getSelectedLines(reservation)); + if (reservation != null && !reservation.getRESStatus().equals("DR")) { + result.addAll(getSelectedLines(reservation, organizations, warehousesFiltered, + locatorsFiltered, attributesFiltered, availableQtyFilterCriteria, + reservedinothersFilterCriteria, releasedFilterCriteria, allocatedCriteria, + quantityCriteria, selectedIds)); + } if (orderLinesFiltered == null || orderLinesFiltered.size() == 0) { - result - .addAll(getStorageDetail(reservation, organizations, warehousesFiltered, - locatorsFiltered, attributesFiltered, availableQtyFilterCriteria, - reservedinothersFilterCriteria, releasedFilterCriteria, allocatedCriteria, - selectedIds)); + result.addAll(getStorageDetail(reservation, organizations, warehousesFiltered, + locatorsFiltered, attributesFiltered, availableQtyFilterCriteria, + reservedinothersFilterCriteria, releasedFilterCriteria, allocatedCriteria, + quantityCriteria, selectedIds)); } + if (locatorsFiltered == null || locatorsFiltered.size() == 0) { - result - .addAll(getPurchaseOrderLines(reservation, organizations, warehousesFiltered, - attributesFiltered, orderLinesFiltered, availableQtyFilterCriteria, - reservedinothersFilterCriteria, releasedFilterCriteria, allocatedCriteria, - selectedIds)); + result.addAll(getPurchaseOrderLines(reservation, organizations, warehousesFiltered, + attributesFiltered, orderLinesFiltered, availableQtyFilterCriteria, + reservedinothersFilterCriteria, releasedFilterCriteria, allocatedCriteria, + quantityCriteria, selectedIds)); } + } finally { OBContext.restorePreviousMode(); } @@ -730,8 +770,13 @@ } } else if (myJSONObject.get("fieldName").equals("attributeSetValue") && operator.equals("equals") && myJSONObject.has("value")) { - myCriterion = Restrictions.eq(AttributeSetInstance.PROPERTY_ID, - myJSONObject.get("value")); + if (myCriterion == null) { + myCriterion = Restrictions.eq(AttributeSetInstance.PROPERTY_ID, + myJSONObject.get("value")); + } else { + myCriterion = Restrictions.or(myCriterion, + Restrictions.eq(AttributeSetInstance.PROPERTY_ID, myJSONObject.get("value"))); + } } } if (myCriterion != null) { @@ -812,68 +857,201 @@ return new StringTokenizer(orderLineIdentifier).nextToken(); } - private List<Map<String, Object>> getSelectedLines(Reservation reservation) { + private List<Map<String, Object>> getSelectedLines(Reservation reservation, + Set<String> organizations, List<Warehouse> warehousesFiltered, + List<Locator> locatorsFiltered, List<AttributeSetInstance> attributeSetInstancesFiltered, + String availableQtyFilterCriteria, String reservedinothersFilterCriteria, + String releasedFilterCriteria, String allocatedCriteria, String quantityCriteria, + ArrayList<String> selectedIds) { List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); final StringBuilder hqlString = new StringBuilder(); hqlString.append("select rs from MaterialMgmtReservationStock rs "); hqlString.append("join rs.reservation as r"); hqlString.append(" where rs.reservation = :reservation "); + + if (reservation.getAttributeSetValue() != null) { + hqlString.append("and rs.attributeSetValue = :attributeSetValue "); + } + if (attributeSetInstancesFiltered != null) { + if (attributeSetInstancesFiltered.isEmpty()) { + hqlString.append("and 1 = 2 "); + } else { + hqlString.append("and rs.attributeSetValue in :attributeSetInstancesFiltered "); + } + } + if (reservation.getStorageBin() != null) { + hqlString.append("and rs.storageBin = :storageBin "); + } + if (locatorsFiltered != null) { + if (locatorsFiltered.isEmpty()) { + hqlString.append("and 1 = 2 "); + } else { + hqlString.append("and rs.storageBin in :locatorsFiltered "); + } + } + if (reservation.getWarehouse() != null) { + hqlString.append("and rs.storageBin.warehouse = :warehouse "); + } + if (warehousesFiltered != null) { + if (warehousesFiltered.isEmpty()) { + hqlString.append("and 1 = 2 "); + } else { + hqlString.append("and rs.storageBin.warehouse in :warehousesFiltered "); + } + } + + hqlString.append("and rs.storageBin.warehouse in :warehouses "); hqlString.append(" order by rs.salesOrderLine DESC, r.warehouse, rs.storageBin"); + final Session session = OBDal.getInstance().getSession(); Query query = session.createQuery(hqlString.toString()); ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits