svn commit: r722588 - in /ofbiz/trunk/applications: ecommerce/data/DemoProduct.xml order/servicedef/secas.xml order/servicedef/services.xml order/src/org/ofbiz/order/order/OrderServices.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r722588 - in /ofbiz/trunk/applications: ecommerce/data/DemoProduct.xml order/servicedef/secas.xml order/servicedef/services.xml order/src/org/ofbiz/order/order/OrderServices.java

jleroux@apache.org
Author: jleroux
Date: Tue Dec  2 11:33:25 2008
New Revision: 722588

URL: http://svn.apache.org/viewvc?rev=722588&view=rev
Log:
A patch from Krzysztof Podejma "Cannot complete order that contains products of type "SERVICE"" (https://issues.apache.org/jira/browse/OFBIZ-943) - OFBIZ-943
+ some demo data


Modified:
    ofbiz/trunk/applications/ecommerce/data/DemoProduct.xml
    ofbiz/trunk/applications/order/servicedef/secas.xml
    ofbiz/trunk/applications/order/servicedef/services.xml
    ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java

Modified: ofbiz/trunk/applications/ecommerce/data/DemoProduct.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/ecommerce/data/DemoProduct.xml?rev=722588&r1=722587&r2=722588&view=diff
==============================================================================
--- ofbiz/trunk/applications/ecommerce/data/DemoProduct.xml (original)
+++ ofbiz/trunk/applications/ecommerce/data/DemoProduct.xml Tue Dec  2 11:33:25 2008
@@ -279,6 +279,14 @@
     <ProductAssoc productId="GZ-BASKET-PICK" productIdTo="GZ-1000" productAssocTypeId="PRODUCT_COMPONENT" quantity="1" fromDate="2007-01-01 12:00:00.0"/>
     <ProductAssoc productId="GZ-BASKET-PICK" productIdTo="GZ-1001" productAssocTypeId="PRODUCT_COMPONENT" quantity="2" fromDate="2007-01-01 12:00:00.0"/>
     <ProductAssoc productId="GZ-BASKET-PICK" productIdTo="GZ-1004" productAssocTypeId="PRODUCT_COMPONENT" quantity="3" fromDate="2007-01-01 12:00:00.0"/>
+
+    <!-- test for service product type-->
+    <ProductCategory productCategoryId="SERV-001" productCategoryTypeId="CATALOG_CATEGORY"/>
+    <ProductCategoryRollup fromDate="2008-12-02 12:00:00.0" parentProductCategoryId="CATALOG1" productCategoryId="SERV-001"/>
+    <Product productId="SV-1000" productTypeId="SERVICE" primaryProductCategoryId="SERV-001" productName="Service product" internalName="Service type product" description="Service type product for demonstration use" taxable="Y" chargeShipping="N" autoCreateKeywords="Y" isVirtual="N" isVariant="N" createdDate="2008-12-02 12:00:00.0" createdByUserLogin="admin" lastModifiedDate="2008-12-02 12:00:00.0" lastModifiedByUserLogin="admin"/>
+    <ProductPrice productId="SV-1000" productPricePurposeId="PURCHASE" productPriceTypeId="DEFAULT_PRICE" currencyUomId="USD" productStoreGroupId="_NA_" fromDate="2008-12-02 12:00:00.0" price="1000" createdDate="2008-12-02 12:00:00.0" createdByUserLogin="admin"/>
+    <ProductCategoryMember productCategoryId="SERV-001" productId="SV-1000" fromDate="2008-12-02 12:00:00.0"/>
+    <ProductCategoryMember productCategoryId="CATALOG1_SEARCH" productId="SV-1000" fromDate="2008-12-02 12:00:00.0"/>
     
     <ProductFeatureCategory productFeatureCategoryId="8000" description="License Features"/>
     <ProductFeatureCategoryAppl productFeatureCategoryId="8000" productCategoryId="CATALOG1_SEARCH" fromDate="2001-05-13 12:00:00.0"/>

Modified: ofbiz/trunk/applications/order/servicedef/secas.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/secas.xml?rev=722588&r1=722587&r2=722588&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/secas.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/secas.xml Tue Dec  2 11:33:25 2008
@@ -52,7 +52,10 @@
         <condition field-name="statusId" operator="equals" value="ITEM_APPROVED"/>
         <action service="checkDigitalItemFulfillment" mode="sync"/>
     </eca>
-
+    <eca service="changeOrderItemStatus" event="commit">
+        <condition field-name="statusId" operator="equals" value="ITEM_APPROVED"/>
+        <action service="invoiceServiceItems" mode="sync"/>
+    </eca>
     <!-- order status changes -->
     <eca service="changeOrderStatus" event="commit" run-on-error="false">
         <condition field-name="statusId" operator="equals" value="ORDER_CANCELLED"/>
@@ -297,4 +300,4 @@
         <condition field-name="workEffortId" operator="is-empty" />
         <action service="createWorkEffort" mode="sync"/>
     </eca>
-</service-eca>
\ No newline at end of file
+</service-eca>

Modified: ofbiz/trunk/applications/order/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services.xml?rev=722588&r1=722587&r2=722588&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/services.xml Tue Dec  2 11:33:25 2008
@@ -440,7 +440,11 @@
        <auto-attributes entity-name="ProductContent" include="pk" mode="IN" optional="false"/>
        <attribute name="orderItem" type="GenericValue" mode="IN" optional="false"/>
    </service>
-
+    <service name="invoiceServiceItems" engine="java"
+            location="org.ofbiz.order.order.OrderServices" invoke="invoiceServiceItems" auth="true">
+        <description>Check an order for service items and invoice the items</description>
+        <attribute name="orderId" type="String" mode="IN"/>
+    </service>
     <!-- Order View Services -->
     <service name="getOrderedSummaryInformation" engine="simple"
             location="org/ofbiz/order/order/OrderServices.xml" invoke="getOrderedSummaryInformation">

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java?rev=722588&r1=722587&r2=722588&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java Tue Dec  2 11:33:25 2008
@@ -3125,6 +3125,134 @@
         }
         return ServiceUtil.returnSuccess();
     }
+    /** Service to invoice service items from order*/
+    public static Map invoiceServiceItems(DispatchContext dctx, Map context){
+        GenericDelegator delegator = dctx.getDelegator();
+        LocalDispatcher dispatcher = dctx.getDispatcher();
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
+        String orderId = (String) context.get("orderId");
+        Locale locale = (Locale) context.get("locale");
+
+        // need the order header
+        GenericValue orderHeader = null;
+        try {
+            orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));
+        } catch (GenericEntityException e) {
+            Debug.logError(e, "ERROR: Unable to get OrderHeader for orderId : " + orderId, module);
+            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorUnableToGetOrderHeaderForOrderId", UtilMisc.toMap("orderId",orderId), locale));
+        }
+
+        // get all the items for the order
+        List orderItems = null;
+        if (orderHeader != null) {
+            try {
+                orderItems = orderHeader.getRelated("OrderItem");
+            } catch (GenericEntityException e) {
+                Debug.logError(e, "ERROR: Unable to get OrderItem list for orderId : " + orderId, module);
+                return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorUnableToGetOrderItemListForOrderId", UtilMisc.toMap("orderId",orderId), locale));
+            }
+        }
+
+        // find any service items
+        List serviceItems = new ArrayList();
+        Map serviceProducts = new HashMap();
+        if (orderItems != null && orderItems.size() > 0) {
+            Iterator i = orderItems.iterator();
+            while (i.hasNext()) {
+                GenericValue item = (GenericValue) i.next();
+                GenericValue product = null;
+                try {
+                    product = item.getRelatedOne("Product");
+                } catch (GenericEntityException e) {
+                    Debug.logError(e, "ERROR: Unable to get Product from OrderItem", module);
+                }
+                if (product != null) {
+                    GenericValue productType = null;
+                    try {
+                        productType = product.getRelatedOne("ProductType");
+                    } catch (GenericEntityException e) {
+                        Debug.logError(e, "ERROR: Unable to get ProductType from Product", module);
+                    }
+
+                    if (productType != null) {
+                        String productTypeId = productType.getString("productTypeId");
+
+                        // check for service goods
+                        if (productTypeId != null && "SERVICE".equalsIgnoreCase(productTypeId)) {
+                            // we only invoice APPROVED items
+                            if ("ITEM_APPROVED".equals(item.getString("statusId"))) {
+                                serviceItems.add(item);
+                                serviceProducts.put(item,product);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        // now process the service items
+        if (serviceItems.size() > 0) {
+
+
+            // single list with all invoice items
+            List itemsToInvoice = FastList.newInstance();
+            itemsToInvoice.addAll(serviceItems);
+
+            // do something tricky here: run as a different user that can actually create an invoice, post transaction, etc
+            Map invoiceResult = null;
+            try {
+                GenericValue permUserLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system"));
+                Map invoiceContext = UtilMisc.toMap("orderId", orderId, "billItems", itemsToInvoice, "userLogin", permUserLogin);
+                invoiceResult = dispatcher.runSync("createInvoiceForOrder", invoiceContext);
+            } catch (GenericEntityException e) {
+                Debug.logError(e, "ERROR: Unable to invoice service items", module);
+                return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderProblemWithInvoiceCreationServiceItems", locale));
+            } catch (GenericServiceException e) {
+                Debug.logError(e, "ERROR: Unable to invoice service items", module);
+                return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderProblemWithInvoiceCreationServiceItems", locale));
+            }
+            if (ModelService.RESPOND_ERROR.equals(invoiceResult.get(ModelService.RESPONSE_MESSAGE))) {
+                return ServiceUtil.returnError((String) invoiceResult.get(ModelService.ERROR_MESSAGE));
+            }
+
+            // update the status of service goods to COMPLETED;
+            Iterator dii = itemsToInvoice.iterator();
+            while (dii.hasNext()) {
+                GenericValue productType = null;
+                GenericValue item = (GenericValue) dii.next();
+                GenericValue product = (GenericValue) serviceProducts.get(item);
+                boolean markComplete = false;
+                if(product != null){
+                    try {
+                        productType = product.getRelatedOne("ProductType");
+                    } catch (GenericEntityException e) {
+                        Debug.logError(e, "ERROR: Unable to get ProductType from Product", module);
+                    }                    
+                    if (item != null && productType != null) {
+                        String productTypeId = productType.getString("productTypeId");
+                        if (productTypeId != null && "SERVICE".equalsIgnoreCase(productTypeId)) {
+                            markComplete = true;
+                        }
+                    }
+                }
+
+                if (markComplete) {
+                    Map statusCtx = new HashMap();
+                    statusCtx.put("orderId", item.getString("orderId"));
+                    statusCtx.put("orderItemSeqId", item.getString("orderItemSeqId"));
+                    statusCtx.put("statusId", "ITEM_COMPLETED");
+                    statusCtx.put("userLogin", userLogin);
+                    try {
+                        dispatcher.runSyncIgnore("changeOrderItemStatus", statusCtx);
+                    } catch (GenericServiceException e) {
+                        Debug.logError(e, "ERROR: Problem setting the status to COMPLETED : " + item, module);
+                    }
+                }
+            }
+        }
+
+        return ServiceUtil.returnSuccess();
+    }
 
     public static Map addItemToApprovedOrder(DispatchContext dctx, Map context) {
         LocalDispatcher dispatcher = dctx.getDispatcher();