Author: lektran
Date: Sat Aug 29 08:52:07 2009 New Revision: 809104 URL: http://svn.apache.org/viewvc?rev=809104&view=rev Log: A few improvements mostly the LookupBulkAddSupplierProducts.groovy script which takes a very long time to load even with relatively modest result sizes Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/cart/LookupBulkAddProducts.groovy ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/cart/LookupBulkAddSupplierProducts.groovy ofbiz/trunk/applications/order/widget/ordermgr/OrderEntryCartScreens.xml ofbiz/trunk/applications/order/widget/ordermgr/OrderEntryForms.xml Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/cart/LookupBulkAddProducts.groovy URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/cart/LookupBulkAddProducts.groovy?rev=809104&r1=809103&r2=809104&view=diff ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/cart/LookupBulkAddProducts.groovy (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/cart/LookupBulkAddProducts.groovy Sat Aug 29 08:52:07 2009 @@ -30,16 +30,17 @@ orConditionList = []; mainConditionList = []; -//make sure the look up is case insensitive -conditionList.add(EntityCondition.makeCondition(EntityFunction.UPPER(EntityFieldValue.makeFieldValue("productId")), - EntityOperator.LIKE, productId.toUpperCase() + "%")); +if (productId) { + //make sure the look up is case insensitive + conditionList.add(EntityCondition.makeCondition(EntityFunction.UPPER(EntityFieldValue.makeFieldValue("productId")), + EntityOperator.LIKE, productId.toUpperCase() + "%")); +} // do not include configurable products conditionList.add(EntityCondition.makeCondition("productTypeId", EntityOperator.NOT_EQUAL, "AGGREGATED")); -// no virtual products: note that isVirtual could be null, which in some databases is different than isVirtual != "Y". +// no virtual products: note that isVirtual could be null, // we consider those products to be non-virtual and hence addable to the order in bulk -orConditionList.add(EntityCondition.makeCondition("isVirtual", EntityOperator.NOT_EQUAL, "Y")); orConditionList.add(EntityCondition.makeCondition("isVirtual", EntityOperator.EQUALS, "N")); orConditionList.add(EntityCondition.makeCondition("isVirtual", EntityOperator.EQUALS, null)); Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/cart/LookupBulkAddSupplierProducts.groovy URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/cart/LookupBulkAddSupplierProducts.groovy?rev=809104&r1=809103&r2=809104&view=diff ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/cart/LookupBulkAddSupplierProducts.groovy (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/cart/LookupBulkAddSupplierProducts.groovy Sat Aug 29 08:52:07 2009 @@ -19,17 +19,34 @@ import org.ofbiz.entity.condition.*; import org.ofbiz.entity.util.EntityUtil; -import org.ofbiz.base.util.UtilMisc; -import org.ofbiz.base.util.UtilDateTime; +import org.ofbiz.base.util.*; import org.ofbiz.order.shoppingcart.ShoppingCart; import org.ofbiz.order.shoppingcart.ShoppingCartEvents; import org.ofbiz.order.order.OrderReadHelper; -productId = request.getParameter("productId") ?: ""; +// This script can take quite a while to run with a decent amount of data +// so we'll take a best effort approach to limit the size of the results +maxRows = null; +// TODO: Find a way to get the pagination parameters for a given form +if (!parameters.containsKey("VIEW_INDEX_1")) { + // There's only one set of pagination parameters so it must be for us + if (parameters.VIEW_SIZE_0) { + if (parameters.VIEW_INDEX_0) { + viewSize = Integer.valueOf(parameters.VIEW_SIZE_0); + viewIndex = Integer.valueOf(parameters.VIEW_INDEX_0); + maxRows = viewSize * (viewIndex + 1); + } + } +} +if (!maxRows) { + maxRows = 50; +} + +productId = parameters.productId; supplier = null; supplierPartyId = null; -orderId = request.getParameter("orderId"); +orderId = parameters.orderId; if (orderId) { orderItemShipGroup = EntityUtil.getFirst(delegator.findList("OrderItemShipGroup", null, null, ["orderId" , "orderId"], null, false)); orderHeader = delegator.findOne("OrderHeader", [orderId : orderId], false); @@ -44,9 +61,11 @@ conditionList = []; -// make sure the look up is case insensitive -conditionList.add(EntityCondition.makeCondition(EntityFunction.UPPER(EntityFieldValue.makeFieldValue("productId")), - EntityOperator.LIKE, productId.toUpperCase() + "%")); +if (productId) { + // make sure the look up is case insensitive + conditionList.add(EntityCondition.makeCondition(EntityFunction.UPPER(EntityFieldValue.makeFieldValue("productId")), + EntityOperator.LIKE, productId.toUpperCase() + "%")); +} if (!supplier) { supplierPartyId = shoppingCart.getOrderPartyId(); } else { @@ -55,62 +74,67 @@ conditionList.add(EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, supplierPartyId)); conditionList.add(EntityCondition.makeCondition("currencyUomId", EntityOperator.EQUALS, shoppingCart.getCurrency())); +conditionList.add(EntityCondition.makeConditionDate("availableFromDate", "availableThruDate")); conditions = EntityCondition.makeCondition(conditionList, EntityOperator.AND); selectedFields = ["productId", "supplierProductId", "supplierProductName", "lastPrice", "minimumOrderQuantity", "orderQtyIncrements"] as Set; -selectedFields.add("availableFromDate"); -selectedFields.add("availableThruDate"); supplierProducts = delegator.findList("SupplierProduct", conditions, selectedFields, ["productId"], null, false); -supplierProducts = EntityUtil.filterByDate(supplierProducts, nowTimestamp, "availableFromDate", "availableThruDate", true); newProductList = []; - -supplierProducts.each { supplierProduct -> - quantityOnOrder = 0.0; +skippedResults = 0; +for (supplierProduct in supplierProducts) { productId = supplierProduct.productId; - // find approved purchase orders - condition = EntityCondition.makeCondition(EntityCondition.makeCondition("orderTypeId", "PURCHASE_ORDER"), EntityOperator.AND, - EntityCondition.makeCondition("statusId", "ORDER_APPROVED")); - - orderHeaders = delegator.findList("OrderHeader", condition, null, ["orderId DESC"], null, false); - orderHeaders.each { orderHeader -> - orderReadHelper = new OrderReadHelper(orderHeader); - orderItems = orderReadHelper.getOrderItems(); - orderItems.each { orderItem -> - if (productId.equals(orderItem.productId) && "ITEM_APPROVED".equals(orderItem.statusId)) { - if (!orderItem.cancelQuantity) { - cancelQuantity = 0.0; - } - shippedQuantity = orderReadHelper.getItemShippedQuantity(orderItem); - quantityOnOrder += orderItem.quantity - cancelQuantity - shippedQuantity; - } - } - } - String facilityId = request.getParameter("facilityId"); + + String facilityId = parameters.facilityId; if (facilityId) { - productFacilityList = delegator.findByAnd("ProductFacility", ["productId": productId, "facilityId" : facilityId]); + productFacilityList = delegator.findByAndCache("ProductFacility", ["productId": productId, "facilityId" : facilityId]); } else { - productFacilityList = delegator.findByAnd("ProductFacility", ["productId": productId]); + productFacilityList = delegator.findByAndCache("ProductFacility", ["productId": productId]); } - productFacilityList.each { productFacility -> - result = dispatcher.runSync("getInventoryAvailableByFacility", ["productId" : productId, "facilityId" : productFacility.facilityId]); - qohAtp = result.quantityOnHandTotal.toString() + "/" + result.availableToPromiseTotal.toString(); - productInfoMap = [:]; - - product = delegator.findOne("Product", ["productId" : productId], false); - productInfoMap.internalName = product.internalName; - - productInfoMap.productId = productId; - productInfoMap.qohAtp = qohAtp; - productInfoMap.quantityOnOrder = quantityOnOrder; - - productInfoMap.supplierProductId = supplierProduct.supplierProductId; - productInfoMap.lastPrice = supplierProduct.lastPrice; - productInfoMap.orderQtyIncrements = supplierProduct.orderQtyIncrements; - - productInfoMap.minimumStock = productFacility.minimumStock; - - newProductList.add(productInfoMap); + if (newProductList.size() >= maxRows) { + // We've got enough results to display, keep going to get the result size but skip the heavy stuff + skippedResults += productFacilityList.size(); + } else { + quantityOnOrder = 0.0; + // find approved purchase orders + condition = EntityCondition.makeCondition(EntityCondition.makeCondition("orderTypeId", "PURCHASE_ORDER"), EntityOperator.AND, + EntityCondition.makeCondition("statusId", "ORDER_APPROVED")); + + orderHeaders = delegator.findList("OrderHeader", condition, null, ["orderId DESC"], null, false); + orderHeaders.each { orderHeader -> + orderReadHelper = new OrderReadHelper(orderHeader); + orderItems = orderReadHelper.getOrderItems(); + orderItems.each { orderItem -> + if (productId.equals(orderItem.productId) && "ITEM_APPROVED".equals(orderItem.statusId)) { + if (!orderItem.cancelQuantity) { + cancelQuantity = 0.0; + } + shippedQuantity = orderReadHelper.getItemShippedQuantity(orderItem); + quantityOnOrder += orderItem.quantity - cancelQuantity - shippedQuantity; + } + } + } + product = delegator.findOne("Product", ["productId" : productId], true); + productFacilityList.each { productFacility -> + result = dispatcher.runSync("getInventoryAvailableByFacility", ["productId" : productId, "facilityId" : productFacility.facilityId]); + qohAtp = result.quantityOnHandTotal.toPlainString() + "/" + result.availableToPromiseTotal.toPlainString(); + productInfoMap = [:]; + + productInfoMap.internalName = product.internalName; + + productInfoMap.productId = productId; + productInfoMap.qohAtp = qohAtp; + productInfoMap.quantityOnOrder = quantityOnOrder; + + productInfoMap.supplierProductId = supplierProduct.supplierProductId; + productInfoMap.lastPrice = supplierProduct.lastPrice; + productInfoMap.orderQtyIncrements = supplierProduct.orderQtyIncrements; + + productInfoMap.minimumStock = productFacility.minimumStock; + + newProductList.add(productInfoMap); + } } } +context.productListSize = newProductList.size() + skippedResults; context.productList = newProductList; \ No newline at end of file Modified: ofbiz/trunk/applications/order/widget/ordermgr/OrderEntryCartScreens.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/widget/ordermgr/OrderEntryCartScreens.xml?rev=809104&r1=809103&r2=809104&view=diff ============================================================================== --- ofbiz/trunk/applications/order/widget/ordermgr/OrderEntryCartScreens.xml (original) +++ ofbiz/trunk/applications/order/widget/ordermgr/OrderEntryCartScreens.xml Sat Aug 29 08:52:07 2009 @@ -187,8 +187,6 @@ <actions> <set field="titleProperty" value="PageTitleLookupBulkAddSupplierProduct"/> <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/cart/LookupBulkAddSupplierProducts.groovy"/> - <set field="viewIndex" from-field="parameters.VIEW_INDEX" type="Integer" default-value="0"/> - <set field="viewSize" from-field="parameters.VIEW_SIZE" type="Integer" default-value="10"/> </actions> <widgets> <decorator-screen name="CommonOrderCatalogDecorator" location="component://order/widget/ordermgr/OrderEntryCommonScreens.xml"> Modified: ofbiz/trunk/applications/order/widget/ordermgr/OrderEntryForms.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/widget/ordermgr/OrderEntryForms.xml?rev=809104&r1=809103&r2=809104&view=diff ============================================================================== --- ofbiz/trunk/applications/order/widget/ordermgr/OrderEntryForms.xml (original) +++ ofbiz/trunk/applications/order/widget/ordermgr/OrderEntryForms.xml Sat Aug 29 08:52:07 2009 @@ -174,7 +174,8 @@ </field> </form> <form name="LookupBulkAddSupplierProducts" type="multi" use-row-submit="true" list-name="productList" title="" target="BulkAddProducts" - odd-row-style="alternate-row" default-table-style="basic-table hover-bar" paginate-target="LookupBulkAddSupplierProducts"> + odd-row-style="alternate-row" default-table-style="basic-table hover-bar" paginate-target="LookupBulkAddSupplierProducts" + override-list-size="${productListSize}"> <field name="productId" widget-style="buttontext"> <hyperlink description="${productId}" target="/catalog/control/EditProductInventoryItems" target-type="inter-app"> <parameter param-name="productId"/> |
Free forum by Nabble | Edit this page |