Author: sichen Date: Fri Sep 29 12:37:41 2006 New Revision: 451399 URL: http://svn.apache.org/viewvc?view=rev&rev=451399 Log: Fix issues with open order item report and 'Required for SO' value in orderview. Introduced a new view-entity to report quantities ordered, issued and open gropued by order item. Renamed the view entity grouped by product to be consistent. Simplified the report bsh and InventoryWorker methods. These fixes are dependent on a the <complex-alias> COALESCE issue OFBIZ-336.
Modified: incubator/ofbiz/trunk/applications/order/entitydef/entitygroup.xml incubator/ofbiz/trunk/applications/order/entitydef/entitymodel_view.xml incubator/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/reports/OpenOrderItemsReport.bsh incubator/ofbiz/trunk/applications/order/widget/ordermgr/ReportForms.xml incubator/ofbiz/trunk/applications/order/widget/ordermgr/ReportScreens.xml incubator/ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java Modified: incubator/ofbiz/trunk/applications/order/entitydef/entitygroup.xml URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/entitydef/entitygroup.xml?view=diff&rev=451399&r1=451398&r2=451399 ============================================================================== --- incubator/ofbiz/trunk/applications/order/entitydef/entitygroup.xml (original) +++ incubator/ofbiz/trunk/applications/order/entitydef/entitygroup.xml Fri Sep 29 12:37:41 2006 @@ -62,7 +62,8 @@ <entity-group group="org.ofbiz" entity="OrderItemShipGrpInvRes" /> <entity-group group="org.ofbiz" entity="OrderItemShipGrpInvResAndItem" /> <entity-group group="org.ofbiz" entity="OrderItemShipGrpInvResAndItemLocation" /> - <entity-group group="org.ofbiz" entity="OrderItemIssuanceGroupByProduct" /> + <entity-group group="org.ofbiz" entity="OrderItemQuantityReportGroupByItem" /> + <entity-group group="org.ofbiz" entity="OrderItemQuantityReportGroupByProduct" /> <entity-group group="org.ofbiz" entity="OrderItemPriceInfo" /> <entity-group group="org.ofbiz" entity="OrderItemRole" /> <entity-group group="org.ofbiz" entity="OrderItemShipGroup" /> Modified: incubator/ofbiz/trunk/applications/order/entitydef/entitymodel_view.xml URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/entitydef/entitymodel_view.xml?view=diff&rev=451399&r1=451398&r2=451399 ============================================================================== --- incubator/ofbiz/trunk/applications/order/entitydef/entitymodel_view.xml (original) +++ incubator/ofbiz/trunk/applications/order/entitydef/entitymodel_view.xml Fri Sep 29 12:37:41 2006 @@ -734,10 +734,50 @@ <key-map field-name="inventoryItemId"/> </relation> </view-entity> - <view-entity entity-name="OrderItemIssuanceGroupByProduct" + <view-entity entity-name="OrderItemQuantityReportGroupByItem" package-name="org.ofbiz.order.order" never-cache="true" - title="Reports quantity issued per product across OrderItems"> + title="Reports quantity ordered, issued and open by item for OrderItems."> + <member-entity entity-alias="OH" entity-name="OrderHeader"/> + <member-entity entity-alias="OI" entity-name="OrderItem"/> + <member-entity entity-alias="II" entity-name="ItemIssuance"/> + <alias entity-alias="OH" name="productStoreId" group-by="false"/> + <alias entity-alias="OH" name="orderId" group-by="true"/> + <alias entity-alias="OH" name="orderTypeId" group-by="false"/> + <alias entity-alias="OH" name="orderStatusId" field="statusId" group-by="false"/> + <alias entity-alias="OH" name="orderDate" group-by="true"/> + <alias entity-alias="OI" name="orderItemSeqId" group-by="true"/> + <alias entity-alias="OI" name="orderItemStatusId" field="statusId" group-by="false"/> + <alias entity-alias="OI" name="productId" group-by="true"/> + <alias entity-alias="OI" name="itemDescription" group-by="true"/> + <alias entity-alias="OI" name="shipBeforeDate" group-by="true"/> + <alias entity-alias="OI" name="shipAfterDate" group-by="true"/> + <alias entity-alias="OI" name="quantityOrdered" function="sum"> + <complex-alias operator="-"> + <complex-alias-field entity-alias="OI" field="quantity" default-value="0"/> + <complex-alias-field entity-alias="OI" field="cancelQuantity" default-value="0"/> + </complex-alias> + </alias> + <alias entity-alias="II" name="quantityIssued" field="quantity" function="sum"/> + <alias entity-alias="OI" name="quantityOpen" function="sum"> + <complex-alias operator="-"> + <complex-alias-field entity-alias="OI" field="quantity" default-value="0"/> + <complex-alias-field entity-alias="OI" field="cancelQuantity" default-value="0"/> + <complex-alias-field entity-alias="II" field="quantity" default-value="0"/> + </complex-alias> + </alias> + <view-link entity-alias="OI" rel-entity-alias="OH"> + <key-map field-name="orderId"/> + </view-link> + <view-link entity-alias="OI" rel-entity-alias="II" rel-optional="true"> + <key-map field-name="orderId"/> + <key-map field-name="orderItemSeqId"/> + </view-link> + </view-entity> + <view-entity entity-name="OrderItemQuantityReportGroupByProduct" + package-name="org.ofbiz.order.order" + never-cache="true" + title="Reports quantity ordered, issued and open by product for OrderItems."> <member-entity entity-alias="OH" entity-name="OrderHeader"/> <member-entity entity-alias="OI" entity-name="OrderItem"/> <member-entity entity-alias="II" entity-name="ItemIssuance"/> @@ -745,11 +785,24 @@ <alias entity-alias="OH" name="orderStatusId" field="statusId" group-by="false"/> <alias entity-alias="OI" name="orderItemStatusId" field="statusId" group-by="false"/> <alias entity-alias="OI" name="productId" group-by="true"/> - <alias entity-alias="II" name="quantity" function="sum"/> + <alias entity-alias="OI" name="quantityOrdered" function="sum"> + <complex-alias operator="-"> + <complex-alias-field entity-alias="OI" field="quantity" default-value="0"/> + <complex-alias-field entity-alias="OI" field="cancelQuantity" default-value="0"/> + </complex-alias> + </alias> + <alias entity-alias="II" name="quantityIssued" field="quantity" function="sum"/> + <alias entity-alias="OI" name="quantityOpen" function="sum"> + <complex-alias operator="-"> + <complex-alias-field entity-alias="OI" field="quantity" default-value="0"/> + <complex-alias-field entity-alias="OI" field="cancelQuantity" default-value="0"/> + <complex-alias-field entity-alias="II" field="quantity" default-value="0"/> + </complex-alias> + </alias> <view-link entity-alias="OI" rel-entity-alias="OH"> <key-map field-name="orderId"/> </view-link> - <view-link entity-alias="OI" rel-entity-alias="II"> + <view-link entity-alias="OI" rel-entity-alias="II" rel-optional="true"> <key-map field-name="orderId"/> <key-map field-name="orderItemSeqId"/> </view-link> Modified: incubator/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/reports/OpenOrderItemsReport.bsh URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/reports/OpenOrderItemsReport.bsh?view=diff&rev=451399&r1=451398&r2=451399 ============================================================================== --- incubator/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/reports/OpenOrderItemsReport.bsh (original) +++ incubator/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/reports/OpenOrderItemsReport.bsh Fri Sep 29 12:37:41 2006 @@ -16,10 +16,8 @@ */ /* - * Script to build the open order item report. - * Uses OrderHeaderAndItem, then computes the quantities - * to display. - * + * Script to build the open order item report using + * the OrderItemQuantityReportGroupByItem view. * @author Leon Torres ([EMAIL PROTECTED]) */ @@ -28,6 +26,7 @@ import org.ofbiz.base.util.UtilMisc; import org.ofbiz.entity.condition.*; +import org.ofbiz.entity.util.*; productStoreId = parameters.get("productStoreId"); orderTypeId = parameters.get("orderTypeId"); @@ -57,43 +56,18 @@ } // item conditions -conditions.add(new EntityExpr("itemStatusId", EntityOperator.NOT_EQUAL, "ITEM_COMPLETED")); -conditions.add(new EntityExpr("itemStatusId", EntityOperator.NOT_EQUAL, "ITEM_CANCELLED")); -conditions.add(new EntityExpr("itemStatusId", EntityOperator.NOT_EQUAL, "ITEM_REJECTED")); +conditions.add(new EntityExpr("orderItemStatusId", EntityOperator.NOT_EQUAL, "ITEM_COMPLETED")); +conditions.add(new EntityExpr("orderItemStatusId", EntityOperator.NOT_EQUAL, "ITEM_CANCELLED")); +conditions.add(new EntityExpr("orderItemStatusId", EntityOperator.NOT_EQUAL, "ITEM_REJECTED")); -// get the orderHeaderAndItems +// get the results as an entity list iterator allConditions = new EntityConditionList( conditions, EntityOperator.AND ); -orderHeaderAndItems = delegator.findByCondition("OrderHeaderAndItems", allConditions, null, UtilMisc.toList("orderDate DESC")); +fieldsToSelect = UtilMisc.toList("orderId","orderDate","productId","quantityOrdered","quantityIssued","quantityOpen"); +fieldsToSelect.add("shipBeforeDate"); +fieldsToSelect.add("shipAfterDate"); +fieldsToSelect.add("itemDescription"); +findOptions = new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, true); +listIt = delegator.findListIteratorByCondition("OrderItemQuantityReportGroupByItem", allConditions, null, fieldsToSelect, UtilMisc.toList("orderDate DESC"), findOptions); +context.put("listIt", listIt); -// make a Map for each orderHeaderAndItem that includes the quantities for the report -reportData = FastList.newInstance(); -for (iter = orderHeaderAndItems.iterator(); iter.hasNext(); ) { - orderItem = iter.next(); - - // add all fields - data = FastMap.newInstance(); - data.putAll( orderItem.getAllFields() ); - - // compute quantity - quantity = orderItem.getDouble("quantity"); - cancelQuantity = orderItem.getDouble("cancelQuantity"); - quantityNet = 0; - if (quantity != null) quantityNet += quantity.doubleValue(); - if (cancelQuantity != null) quantityNet -= cancelQuantity.doubleValue(); - data.put("quantityNet", new Double(quantityNet)); - - // compute issued - issuances = delegator.findByAnd("ItemIssuance", UtilMisc.toMap("orderId", orderItem.get("orderId"), "orderItemSeqId", orderItem.get("orderItemSeqId")), UtilMisc.toList("quantity")); - double quantityIssued = 0; - for (subiter = issuances.iterator(); subiter.hasNext(); ) { - quantityIssued += subiter.next().getDouble("quantity").doubleValue(); - } - data.put("quantityIssued", new Double(quantityIssued)); - // compute open - data.put("quantityOpen", new Double(quantityNet - quantityIssued)); - - reportData.add(data); -} - -context.put("orderItems", reportData); Modified: incubator/ofbiz/trunk/applications/order/widget/ordermgr/ReportForms.xml URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/widget/ordermgr/ReportForms.xml?view=diff&rev=451399&r1=451398&r2=451399 ============================================================================== --- incubator/ofbiz/trunk/applications/order/widget/ordermgr/ReportForms.xml (original) +++ incubator/ofbiz/trunk/applications/order/widget/ordermgr/ReportForms.xml Fri Sep 29 12:37:41 2006 @@ -128,14 +128,16 @@ </form> <!-- list open order items --> - <form name="OpenOrderItemsList" type="list" list-name="orderItems" + <form name="OpenOrderItemsList" type="list" list-name="listIt" + paginate-target="OpenOrderItemsReport" default-title-style="tableheadtext" default-widget-style="tabletext" default-tooltip-style="tabletext"> <field name="orderDate" title="${uiLabelMap.OrderDate}"><display/></field> <field name="orderId" title="${uiLabelMap.OrderOrderId}" widget-style="buttontext"> <hyperlink target="orderview?orderId=${orderId}" description="${orderId}"/> </field> <field name="productId" title="${uiLabelMap.ProductProduct}"><display/></field> - <field name="quantityNet" title="${uiLabelMap.ProductQuantity}"><display/></field> + <field name="itemDescription" title="${uiLabelMap.CommonDescription}"><display/></field> + <field name="quantityOrdered" title="${uiLabelMap.ProductQuantity}"><display/></field> <field name="quantityIssued" title="${uiLabelMap.OrderQtyShipped}"><display/></field> <field name="quantityOpen" title="${uiLabelMap.ProductOpenQuantity}"><display/></field> <field name="shipAfterDate" title="${uiLabelMap.OrderShipAfterDate}"><display/></field> Modified: incubator/ofbiz/trunk/applications/order/widget/ordermgr/ReportScreens.xml URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/widget/ordermgr/ReportScreens.xml?view=diff&rev=451399&r1=451398&r2=451399 ============================================================================== --- incubator/ofbiz/trunk/applications/order/widget/ordermgr/ReportScreens.xml (original) +++ incubator/ofbiz/trunk/applications/order/widget/ordermgr/ReportScreens.xml Fri Sep 29 12:37:41 2006 @@ -185,6 +185,8 @@ <actions> <set field="titleProperty" value="OrderReportOpenOrderItems"/> <set field="headerItem" value="reports"/> + <set field="viewSize" value="${parameters.VIEW_SIZE}" default-value="20" type="Integer"/> + <set field="viewIndex" value="${parameters.VIEW_INDEX}" default-value="0" type="Integer"/> <script location="component://order/webapp/ordermgr/WEB-INF/actions/reports/OpenOrderItemsReport.bsh"/> </actions> <widgets> Modified: incubator/ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java?view=diff&rev=451399&r1=451398&r2=451399 ============================================================================== --- incubator/ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java (original) +++ incubator/ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java Fri Sep 29 12:37:41 2006 @@ -95,8 +95,7 @@ /** * Gets the quanitty of each product in the order that is outstanding across all orders of the given input type. - * First it gets the ordered quantities outstanding, then subtracts the issued quantities outstanding. - * This method relies on the sum view entities OrderReportGroupByProduct and OrderItemIssuanceGroupByProduct. + * Uses the OrderItemQuantityReportGroupByProduct view entity. * * @param productIds Collection of disticnt productIds in an order. Use OrderReadHelper.getOrderProductIds() * @param orderTypeId Either "SALES_ORDER" or "PURCHASE_ORDER" @@ -104,9 +103,7 @@ * @return Map of productIds to quantities outstanding. */ public static Map getOutstandingProductQuantities(Collection productIds, String orderTypeId, GenericDelegator delegator) { - - // both queries use the same condition - List fieldsToSelect = UtilMisc.toList("productId", "quantity"); + List fieldsToSelect = UtilMisc.toList("productId", "quantityOpen"); List condList = UtilMisc.toList( new EntityExpr("orderTypeId", EntityOperator.EQUALS, orderTypeId), new EntityExpr("orderStatusId", EntityOperator.NOT_EQUAL, "ORDER_COMPLETED"), @@ -123,31 +120,10 @@ Map results = FastMap.newInstance(); try { - // find the ordered products outstading and build a map of productId to quantity - List orderedProducts = delegator.findByCondition("OrderReportGroupByProduct", conditions, fieldsToSelect, null); - Map orderedProductsMap = FastMap.newInstance(); + List orderedProducts = delegator.findByCondition("OrderItemQuantityReportGroupByProduct", conditions, fieldsToSelect, null); for (Iterator iter = orderedProducts.iterator(); iter.hasNext(); ) { GenericValue value = (GenericValue) iter.next(); - orderedProductsMap.put(value.getString("productId"), value.getDouble("quantity")); - } - - // find the issued quantities outstanding and build a map of productId to quantity - List issuedProducts = delegator.findByCondition("OrderItemIssuanceGroupByProduct", conditions, fieldsToSelect, null); - Map issuedProductsMap = FastMap.newInstance(); - for (Iterator iter = issuedProducts.iterator(); iter.hasNext(); ) { - GenericValue value = (GenericValue) iter.next(); - issuedProductsMap.put(value.getString("productId"), value.getDouble("quantity")); - } - - // now go through the ordered map and subtract corresponding issued quantities - for (Iterator iter = orderedProductsMap.keySet().iterator(); iter.hasNext(); ) { - String productId = (String) iter.next(); - Double quantityOrdered = (Double) orderedProductsMap.get(productId); - Double quantityIssued = (Double) issuedProductsMap.get(productId); - double quantity = 0; - if (quantityOrdered != null) quantity += quantityOrdered.doubleValue(); - if (quantityIssued != null) quantity -= quantityIssued.doubleValue(); - results.put(productId, new Double(quantity)); + results.put(value.getString("productId"), value.getDouble("quantityOpen")); } } catch (GenericEntityException e) { Debug.logError(e, module);