svn commit: r419201 - in /incubator/ofbiz/trunk/applications: manufacturing/script/org/ofbiz/manufacturing/jobshopmgt/ manufacturing/servicedef/ manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ product/servicedef/

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

svn commit: r419201 - in /incubator/ofbiz/trunk/applications: manufacturing/script/org/ofbiz/manufacturing/jobshopmgt/ manufacturing/servicedef/ manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ product/servicedef/

jacopoc
Author: jacopoc
Date: Wed Jul  5 03:17:18 2006
New Revision: 419201

URL: http://svn.apache.org/viewvc?rev=419201&view=rev
Log:
First version of the implementation of de-composition of new marketing packages.
When a return recive for a marketing package is done, a seca is run to decompose the marketing package.

Modified:
    incubator/ofbiz/trunk/applications/manufacturing/script/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.xml
    incubator/ofbiz/trunk/applications/manufacturing/servicedef/services_production_run.xml
    incubator/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java
    incubator/ofbiz/trunk/applications/product/servicedef/secas_shipment.xml

Modified: incubator/ofbiz/trunk/applications/manufacturing/script/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/manufacturing/script/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.xml?rev=419201&r1=419200&r2=419201&view=diff
==============================================================================
--- incubator/ofbiz/trunk/applications/manufacturing/script/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.xml (original)
+++ incubator/ofbiz/trunk/applications/manufacturing/script/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.xml Wed Jul  5 03:17:18 2006
@@ -227,5 +227,65 @@
             </if-compare>
         </if-compare>
     </simple-method>
+
+    <simple-method method-name="issueInventoryItemToWorkEffort" short-description="Issue one InventoryItem to a WorkEffort">
+        <set field="inventoryItem" from-field="parameters.inventoryItem"/>
+        <if-compare value="SERIALIZED_INV_ITEM" operator="equals" field-name="inventoryItem.inventoryItemTypeId">
+            <if-compare value="INV_AVAILABLE" operator="equals" field-name="inventoryItem.statusId">
+                <!-- change status on inventoryItem -->
+                <set field="inventoryItem.statusId" value="INV_DELIVERED"/>
+                <store-value value-name="inventoryItem"/>
+
+                <!-- create ItemIssuance record -->
+                <set field="issuanceCreateMap.workEffortId" from-field="parameters.workEffortId"/>
+                <set field="issuanceCreateMap.inventoryItemId" from-field="inventoryItem.inventoryItemId"/>
+                <calculate field-name="quantity" map-name="issuanceCreateMap"><number value="1"/></calculate>
+                <call-service service-name="assignInventoryToWorkEffort" in-map-name="issuanceCreateMap"/>
+                <field-to-result field-name="issuanceCreateMap.quantity" result-name="quantityIssued"/>
+            </if-compare>
+        </if-compare>
+        <if>
+            <condition>
+                <and>
+                    <if-compare field-name="inventoryItem.inventoryItemTypeId" operator="equals" value="NON_SERIAL_INV_ITEM"/>
+                    <not><if-empty field-name="inventoryItem.quantityOnHandTotal"/></not>
+                    <if-compare field-name="inventoryItem.quantityOnHandTotal" operator="greater" value="0" type="Double"/>
+                </and>
+            </condition>
+            <then>
+                <if-compare-field field-name="parameters.quantity" operator="greater" to-field-name="inventoryItem.quantityOnHandTotal" type="Double">
+                    <set from-field="inventoryItem.quantityOnHandTotal" field="deductAmount"/>
+                <else>
+                    <set from-field="parameters.quantity" field="deductAmount"/>
+                </else>
+                </if-compare-field>
+
+                <!-- create WorkEffortInventoryAssign record -->
+                <set from-field="parameters.workEffortId" field="issuanceCreateMap.workEffortId"/>
+                <set from-field="inventoryItem.inventoryItemId" field="issuanceCreateMap.inventoryItemId"/>
+                <set from-field="deductAmount" field="issuanceCreateMap.quantity"/>
+                <call-service service-name="assignInventoryToWorkEffort" in-map-name="issuanceCreateMap">
+                </call-service>
+
+                <!-- instead of updating InventoryItem, add an InventoryItemDetail -->
+                <set from-field="inventoryItem.inventoryItemId" field="createDetailMap.inventoryItemId"/>
+                <set from-field="parameters.workEffortId" field="createDetailMap.workEffortId"/>
+                <!-- update availableToPromiseDiff AND quantityOnHandDiff since this is an issuance -->
+                <calculate field-name="createDetailMap.availableToPromiseDiff" type="Double">
+                    <calcop field-name="deductAmount" operator="negative"/>
+                </calculate>
+                <calculate field-name="createDetailMap.quantityOnHandDiff" type="Double">
+                    <calcop field-name="deductAmount" operator="negative"/>
+                </calculate>
+                <call-service service-name="createInventoryItemDetail" in-map-name="createDetailMap"/>
+                <field-to-result field-name="deductAmount" result-name="quantityIssued"/>
+            </then>
+            <else>
+                <calculate field-name="quantity" map-name="issuanceCreateMap"><number value="1"/></calculate>
+                <field-to-result field-name="deductAmount" result-name="quantityIssued"/>
+            </else>
+        </if>
+    </simple-method>
+
 </simple-methods>
 

Modified: incubator/ofbiz/trunk/applications/manufacturing/servicedef/services_production_run.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/manufacturing/servicedef/services_production_run.xml?rev=419201&r1=419200&r2=419201&view=diff
==============================================================================
--- incubator/ofbiz/trunk/applications/manufacturing/servicedef/services_production_run.xml (original)
+++ incubator/ofbiz/trunk/applications/manufacturing/servicedef/services_production_run.xml Wed Jul  5 03:17:18 2006
@@ -134,6 +134,17 @@
         <attribute name="workEffortGoodStandard" type="GenericValue" mode="IN" optional="true"/>
         <attribute name="reserveOrderEnumId" type="String" mode="IN" optional="true"/>
     </service>
+    <service name="issueInventoryItemToWorkEffort" engine="simple"
+                location="org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.xml" invoke="issueInventoryItemToWorkEffort" auth="false">
+        <description>
+            Issue one InventoryItem (or part of it) to a WorkEffort.
+            Note that this skips the normal inventory reservation process.
+        </description>
+        <attribute name="workEffortId" type="String" mode="IN" optional="false"/>
+        <attribute name="inventoryItem" type="GenericValue" mode="IN" optional="false"/>
+        <attribute name="quantity" type="Double" mode="IN" optional="true"/>
+        <attribute name="quantityIssued" type="Double" mode="OUT" optional="false"/>
+    </service>
     <service name="productionRunProduce" engine="java"
             location="org.ofbiz.manufacturing.jobshopmgt.ProductionRunServices" invoke="productionRunProduce" auth="true">
         <description>
@@ -155,6 +166,9 @@
         <attribute name="workEffortId" type="String" mode="IN" optional="false"/>
         <attribute name="productId" type="String" mode="IN" optional="false"/>
         <attribute name="quantity" type="Double" mode="IN" optional="false"/>
+        <attribute name="facilityId" type="String" mode="IN" optional="true"/>
+        <attribute name="unitCost" type="Double" mode="IN" optional="true"/>
+        <attribute name="currencyUomId" type="String" mode="IN" optional="true"/>
         <attribute name="createSerializedInventory" type="Boolean" mode="IN" optional="true"/>
     </service>
     <service name="productionRunTaskReturnMaterial" engine="java"
@@ -166,6 +180,24 @@
         <attribute name="productId" type="String" mode="IN" optional="false"/>
         <attribute name="quantity" type="Double" mode="IN" optional="true"/>
         <attribute name="createSerializedInventory" type="Boolean" mode="IN" optional="true"/>
+    </service>
+    <service name="checkDecomposeInventoryItem" engine="java"
+            location="org.ofbiz.manufacturing.jobshopmgt.ProductionRunServices" invoke="decomposeInventoryItem" auth="true">
+        <description>
+            If the inventory item is for a 'marketing package' run the decomposeInventoryItem service.
+            It is intended to be called as seca when a marketing package is received into warehouse (e.g. from a return).
+        </description>
+        <attribute name="inventoryItemId" type="String" mode="IN" optional="false"/>
+        <attribute name="quantityAccepted" type="Double" mode="IN" optional="true"/>
+    </service>
+    <service name="decomposeInventoryItem" engine="java"
+            location="org.ofbiz.manufacturing.jobshopmgt.ProductionRunServices" invoke="decomposeInventoryItem" auth="true">
+        <description>
+            Create a decompose work effort, issue the inventory item (or part of it), and put in warehouse its components.
+            It is intended to be called when a marketing package is received into warehouse (e.g. from a return).
+        </description>
+        <attribute name="inventoryItemId" type="String" mode="IN" optional="false"/>
+        <attribute name="quantity" type="Double" mode="IN" optional="true"/>
     </service>
     <service name="updateProductionRunTask" engine="java"
             location="org.ofbiz.manufacturing.jobshopmgt.ProductionRunServices" invoke="updateProductionRunTask" auth="true">

Modified: incubator/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java?rev=419201&r1=419200&r2=419201&view=diff
==============================================================================
--- incubator/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java (original)
+++ incubator/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java Wed Jul  5 03:17:18 2006
@@ -1385,16 +1385,21 @@
         Double quantity = (Double)context.get("quantity");
         
         // Optional input fields
+        String facilityId = (String)context.get("facilityId");
+        String currencyUomId = (String)context.get("currencyUomId");
+        Double unitCost = (Double)context.get("unitCost");
         Boolean createSerializedInventory = (Boolean)context.get("createSerializedInventory");
         
         // The default is non-serialized inventory item
         if (createSerializedInventory == null) {
             createSerializedInventory = new Boolean(false);
         }
-        // TODO: if the task is not running, then return an error message.
-
-        // The production run is loaded
-        ProductionRun productionRun = new ProductionRun(productionRunTaskId, delegator, dispatcher);
+        
+        if (facilityId == null) {
+            // The production run is loaded
+            ProductionRun productionRun = new ProductionRun(productionRunTaskId, delegator, dispatcher);
+            facilityId = productionRun.getGenericValue().getString("facilityId");
+        }
 
         if (createSerializedInventory.booleanValue()) {
             try {
@@ -1403,10 +1408,13 @@
                     Map serviceContext = UtilMisc.toMap("productId", productId,
                                                         "inventoryItemTypeId", "SERIALIZED_INV_ITEM",
                                                         "statusId", "INV_AVAILABLE");
-                    serviceContext.put("facilityId", productionRun.getGenericValue().getString("facilityId"));
+                    serviceContext.put("facilityId", facilityId);
                     serviceContext.put("datetimeReceived", UtilDateTime.nowDate());
                     serviceContext.put("comments", "Created by production run task " + productionRunTaskId);
-                    //serviceContext.put("serialNumber", productionRunTaskId);
+                    if (unitCost != null) {
+                        serviceContext.put("unitCost", unitCost);
+                        serviceContext.put("currencyUomId", currencyUomId);
+                    }
                     serviceContext.put("userLogin", userLogin);
                     Map resultService = dispatcher.runSync("createInventoryItem", serviceContext);
                     String inventoryItemId = (String)resultService.get("inventoryItemId");
@@ -1432,9 +1440,13 @@
             try {
                 Map serviceContext = UtilMisc.toMap("productId", productId,
                                                     "inventoryItemTypeId", "NON_SERIAL_INV_ITEM");
-                serviceContext.put("facilityId", productionRun.getGenericValue().getString("facilityId"));
+                serviceContext.put("facilityId", facilityId);
                 serviceContext.put("datetimeReceived", UtilDateTime.nowTimestamp());
                 serviceContext.put("comments", "Created by production run task " + productionRunTaskId);
+                if (unitCost != null) {
+                    serviceContext.put("unitCost", unitCost);
+                    serviceContext.put("currencyUomId", currencyUomId);
+                }
                 serviceContext.put("userLogin", userLogin);
                 Map resultService = dispatcher.runSync("createInventoryItem", serviceContext);
                 String inventoryItemId = (String)resultService.get("inventoryItemId");
@@ -2196,4 +2208,132 @@
         return result;
     }
 
+    public static Map checkDecomposeInventoryItem(DispatchContext ctx, Map context) {
+        Map result = new HashMap();
+        GenericDelegator delegator = ctx.getDelegator();
+        LocalDispatcher dispatcher = ctx.getDispatcher();
+        Timestamp now = UtilDateTime.nowTimestamp();
+        Locale locale = (Locale) context.get("locale");
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
+        String inventoryItemId = (String)context.get("inventoryItemId");
+        Double quantity = (Double)context.get("quantityAccepted");
+        try {
+            GenericValue inventoryItem = delegator.findByPrimaryKey("InventoryItem", UtilMisc.toMap("inventoryItemId", inventoryItemId));
+            if (inventoryItem == null) {
+                return ServiceUtil.returnError("Error: inventory item with id [" + inventoryItemId + "] not found.");
+            }
+            GenericValue product = inventoryItem.getRelatedOne("Product");
+            if (product == null) {
+                return ServiceUtil.returnError("Error: product with id [" + inventoryItem.get("productId") + "] not found.");
+            }
+            if ("MARKETING_PKG_AUTO".equals(product.getString("productTypeId"))) {
+                Map serviceContext = UtilMisc.toMap("inventoryItemId", inventoryItemId,
+                                                    "userLogin", userLogin);
+                if (quantity != null) {
+                    serviceContext.put("quantity", quantity);
+                }
+                dispatcher.runSync("decomposeInventoryItem", serviceContext);
+            }
+        } catch (Exception e) {
+            Debug.logError(e, "Problem calling the checkDecomposeInventoryItem service", module);
+            return ServiceUtil.returnError(e.getMessage());
+        }
+        return ServiceUtil.returnSuccess();
+    }
+
+    public static Map decomposeInventoryItem(DispatchContext ctx, Map context) {
+        Map result = new HashMap();
+        GenericDelegator delegator = ctx.getDelegator();
+        LocalDispatcher dispatcher = ctx.getDispatcher();
+        Timestamp now = UtilDateTime.nowTimestamp();
+        List msgResult = new LinkedList();
+        Locale locale = (Locale) context.get("locale");
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
+        // Mandatory input fields
+        String inventoryItemId = (String)context.get("inventoryItemId");
+        Double quantity = (Double)context.get("quantity");
+
+        try {
+            GenericValue inventoryItem = delegator.findByPrimaryKey("InventoryItem", UtilMisc.toMap("inventoryItemId", inventoryItemId));
+            if (inventoryItem == null) {
+                return ServiceUtil.returnError("Error decomposing inventory item: inventory item with id [" + inventoryItemId + "] not found.");
+            }
+            // the work effort (disassemble order) is created
+            Map serviceContext = UtilMisc.toMap("workEffortTypeId", "PROD_ORDER_HEADER",
+                                 "workEffortPurposeTypeId", "WEPT_PRODUCTION_RUN",
+                                 "currentStatusId", "PRUN_CREATED");
+            serviceContext.put("workEffortName", "Decompose inventory item [" + inventoryItem.getString("inventoryItemId") + "]");
+            serviceContext.put("facilityId", inventoryItem.getString("facilityId"));
+            serviceContext.put("estimatedStartDate", now);
+            serviceContext.put("userLogin", userLogin);
+            Map resultService = dispatcher.runSync("createWorkEffort", serviceContext);
+            String workEffortId = (String)resultService.get("workEffortId");
+            // the inventory (marketing package) is issued
+            serviceContext.clear();
+            serviceContext = UtilMisc.toMap("inventoryItem", inventoryItem,
+                                 "workEffortId", workEffortId,
+                                 "userLogin", userLogin);
+            if (quantity != null) {
+                serviceContext.put("quantity", quantity);
+            }
+            resultService = dispatcher.runSync("issueInventoryItemToWorkEffort", serviceContext);
+            Double issuedQuantity = (Double)resultService.get("issuedQuantity");
+            // TODO: get the package's unit cost
+            serviceContext.clear();
+            serviceContext = UtilMisc.toMap("productId", inventoryItem.getString("productId"),
+                                 "currencyUomId", inventoryItem.getString("currencyUomId"),
+                                 "costComponentTypePrefix", "EST_STD_",
+                                 "userLogin", userLogin);
+            resultService = dispatcher.runSync("getProductCost", serviceContext);
+            Double packageCost = (Double)resultService.get("productCost");
+            if (packageCost == null || packageCost.doubleValue() == 0) {
+                packageCost = new Double(1.0);
+            }
+            Double inventoryItemCost = (Double)inventoryItem.getDouble("unitCost");
+            if (inventoryItemCost == null) {
+                inventoryItemCost = new Double(1.0);
+            }
+            Double costCoefficient = new Double(inventoryItemCost.doubleValue() / packageCost.doubleValue());
+            
+            // the components are retrieved
+            serviceContext.clear();
+            serviceContext = UtilMisc.toMap("productId", inventoryItem.getString("productId"),
+                                 "quantity", issuedQuantity,
+                                 "userLogin", userLogin);
+            resultService = dispatcher.runSync("getManufacturingComponents", serviceContext);
+            List components = (List)resultService.get("componentsMap");
+            if (components == null || components.isEmpty()) {
+                return ServiceUtil.returnError("Error decomposing inventory item: no components found for marketing package [" + inventoryItem.getString("productId") + "].");
+            }
+            Iterator componentsIt = components.iterator();
+            while (componentsIt.hasNext()) {
+                Map component = (Map)componentsIt.next();
+                // get the component's unit cost
+                serviceContext.clear();
+                serviceContext = UtilMisc.toMap("productId", ((GenericValue)component.get("product")).getString("productId"),
+                                     "currencyUomId", inventoryItem.getString("currencyUomId"),
+                                     "costComponentTypePrefix", "EST_STD_",
+                                     "userLogin", userLogin);
+                resultService = dispatcher.runSync("getProductCost", serviceContext);
+                Double componentCost = (Double)resultService.get("productCost");
+                Double componentInventoryItemCost = new Double(costCoefficient.doubleValue() * componentCost.doubleValue());
+                serviceContext.clear();
+                serviceContext = UtilMisc.toMap("productId", ((GenericValue)component.get("product")).getString("productId"),
+                                     "quantity", component.get("quantity"),
+                                     "facilityId", inventoryItem.getString("facilityId"),
+                                     "unitCost", componentInventoryItemCost,
+                                     "userLogin", userLogin);
+                serviceContext.put("workEffortId", workEffortId);
+                resultService = dispatcher.runSync("productionRunTaskProduce", serviceContext);
+            }
+            // the components are put in warehouse
+        } catch (GenericEntityException e) {
+            Debug.logError(e, "Problem calling the createWorkEffort service", module);
+            return ServiceUtil.returnError(e.getMessage());
+        } catch (GenericServiceException e) {
+            Debug.logError(e, "Problem calling the createWorkEffort service", module);
+            return ServiceUtil.returnError(e.getMessage());
+        }
+        return result;
+    }
 }

Modified: incubator/ofbiz/trunk/applications/product/servicedef/secas_shipment.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/product/servicedef/secas_shipment.xml?rev=419201&r1=419200&r2=419201&view=diff
==============================================================================
--- incubator/ofbiz/trunk/applications/product/servicedef/secas_shipment.xml (original)
+++ incubator/ofbiz/trunk/applications/product/servicedef/secas_shipment.xml Wed Jul  5 03:17:18 2006
@@ -91,6 +91,7 @@
 
     <eca service="createShipmentReceipt" event="commit">
         <condition field-name="returnId" operator="is-not-empty"/>
+        <action service="checkDecomposeInventoryItem" mode="sync"/>
         <action service="updateReturnStatusFromReceipt" mode="sync"/>
     </eca>
     <eca service="createShipmentReceipt" event="commit">