Applied patch that allows to override the default routing when a manual production run is created.

Thanks to Scott Gray for the patch (OFBIZ-190).


git-svn-id: https://svn.apache.org/repos/asf/incubator/ofbiz/trunk@464217 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jacopo Cappellato
2006-10-15 15:53:54 +00:00
parent 171b9372f9
commit abdf709cca
3 changed files with 98 additions and 65 deletions
@@ -22,59 +22,90 @@ under the License.
<simple-method method-name="getProductRouting" short-description="Get the product's routing and routing tasks">
<set from-field="parameters.productId" field="lookupRouting.productId"/>
<set value="ROU_PROD_TEMPLATE" field="lookupRouting.workEffortGoodStdTypeId"/>
<find-by-and entity-name="WorkEffortGoodStandard" list-name="routings" map-name="lookupRouting"/>
<!-- TODO: we should consider the validity against a date passed as (optional) parameter -->
<filter-list-by-date list-name="routings"/>
<!-- TODO: we should consider the quantity to select the best routing -->
<first-from-list list-name="routings" entry-name="routingGS"/>
<!-- If there are no routings associated with our product and it's a variant, then
check to see if it's virtual product has a routing -->
<if-empty field-name="routingGS">
<entity-one entity-name="Product" value-name="product" auto-field-map="false" >
<field-map field-name="productId" env-name="parameters.productId" />
</entity-one>
<if-compare field-name="product.isVariant" operator="equals" value="Y">
<entity-condition entity-name="ProductAssoc" list-name="virtualProductAssocList" filter-by-date="true">
<!-- If applicableDate has been passed use the value with all filter-by-date calls-->
<if-not-empty field-name="applicableDate" map-name="parameters">
<set from-field="parameters.applicableDate" field="filterDate"/>
<else>
<now-timestamp-to-env env-name="filterDate"/>
</else>
</if-not-empty>
<!-- If a workEffortId has been passed, use it to look up the desired routing-->
<if-not-empty field-name="workEffortId" map-name="parameters">
<set from-field="parameters.workEffortId" field="lookupRouting.workEffortId"/>
<find-by-and entity-name="WorkEffortGoodStandard" list-name="routings" map-name="lookupRouting"/>
<filter-list-by-date list-name="routings" valid-date-name="filterDate"/>
<first-from-list list-name="routings" entry-name="routingGS"/>
<!-- If the routing is not associated with our product and it's a variant, then
check to see if it's virtual product has the routing -->
<if-empty field-name="routingGS">
<entity-condition entity-name="ProductAssoc" list-name="virtualProductAssocList">
<condition-list combine="and">
<condition-expr field-name="productIdTo" env-name="parameters.productId" />
<condition-expr field-name="productAssocTypeId" value="PRODUCT_VARIANT" />
</condition-list>
</entity-condition>
<first-from-list list-name="virtualProductAssocList" entry-name="virtualProductAssoc" />
<filter-list-by-date list-name="virtualProductAssocList" valid-date-name="filterDate"/>
<first-from-list list-name="virtualProductAssocList" entry-name="virtualProductAssoc"/>
<if-not-empty field-name="virtualProductAssoc">
<set from-field="virtualProductAssoc.productId" field="lookupRouting.productId"/>
<set value="ROU_PROD_TEMPLATE" field="lookupRouting.workEffortGoodStdTypeId"/>
<find-by-and entity-name="WorkEffortGoodStandard" list-name="routings" map-name="lookupRouting"/>
<!-- TODO: we should consider the validity against a date passed as (optional) parameter -->
<filter-list-by-date list-name="routings"/>
<!-- TODO: we should consider the quantity to select the best routing -->
<!-- Consider the validity against a date passed as (optional) parameter -->
<filter-list-by-date list-name="routings" valid-date-name="filterDate"/>
<first-from-list list-name="routings" entry-name="routingGS"/>
</if-not-empty>
</if-compare>
</if-empty>
<if-not-empty field-name="routingGS">
<clear-field field-name="lookupRouting"/>
<set from-field="routingGS.workEffortId" field="lookupRouting.workEffortId"/>
<find-by-primary-key entity-name="WorkEffort" value-name="routing" map-name="lookupRouting"/>
</if-empty>
<!-- No workEffortId has been passed, so retrieve the first routing found for this product-->
<else>
<!-- The default routing is used when no explicit routing is associated to the product
and the ignoreDefaultRouting is not equals to Y -->
<if>
<condition>
<or>
<if-empty field-name="parameters.ignoreDefaultRouting"/>
<if-compare field-name="parameters.ignoreDefaultRouting" operator="equals" value="N"/>
</or>
</condition>
<then>
<clear-field field-name="lookupRouting"/>
<set value="DEFAULT_ROUTING" field="lookupRouting.workEffortId"/>
<find-by-primary-key entity-name="WorkEffort" value-name="routing" map-name="lookupRouting"/>
</then>
</if>
<find-by-and entity-name="WorkEffortGoodStandard" list-name="routings" map-name="lookupRouting"/>
<!-- Consider the validity against a date passed as (optional) parameter -->
<filter-list-by-date list-name="routings" valid-date-name="filterDate"/>
<!-- TODO: we should consider the quantity to select the best routing -->
<first-from-list list-name="routings" entry-name="routingGS"/>
<!-- If there are no routings associated with our product and it's a variant, then
check to see if it's virtual product has a routing -->
<if-empty field-name="routingGS">
<entity-condition entity-name="ProductAssoc" list-name="virtualProductAssocList">
<condition-list combine="and">
<condition-expr field-name="productIdTo" env-name="parameters.productId" />
<condition-expr field-name="productAssocTypeId" value="PRODUCT_VARIANT" />
</condition-list>
</entity-condition>
<filter-list-by-date list-name="virtualProductAssocList" valid-date-name="filterDate"/>
<first-from-list list-name="virtualProductAssocList" entry-name="virtualProductAssoc"/>
<if-not-empty field-name="virtualProductAssoc">
<set from-field="virtualProductAssoc.productId" field="lookupRouting.productId"/>
<set value="ROU_PROD_TEMPLATE" field="lookupRouting.workEffortGoodStdTypeId"/>
<find-by-and entity-name="WorkEffortGoodStandard" list-name="routings" map-name="lookupRouting"/>
<!-- Consider the validity against a date passed as (optional) parameter -->
<filter-list-by-date list-name="routings" valid-date-name="filterDate"/>
<!-- TODO: we should consider the quantity to select the best routing -->
<first-from-list list-name="routings" entry-name="routingGS"/>
</if-not-empty>
</if-empty>
</else>
</if-not-empty>
<if-not-empty field-name="routingGS">
<clear-field field-name="lookupRouting"/>
<set from-field="routingGS.workEffortId" field="lookupRouting.workEffortId"/>
<find-by-primary-key entity-name="WorkEffort" value-name="routing" map-name="lookupRouting"/>
<else>
<!-- The default routing is used when no explicit routing is associated to the product
and the ignoreDefaultRouting is not equals to Y -->
<if>
<condition>
<or>
<if-empty field-name="parameters.ignoreDefaultRouting"/>
<if-compare field-name="parameters.ignoreDefaultRouting" operator="equals" value="N"/>
</or>
</condition>
<then>
<clear-field field-name="lookupRouting"/>
<set value="DEFAULT_ROUTING" field="lookupRouting.workEffortId"/>
<find-by-primary-key entity-name="WorkEffort" value-name="routing" map-name="lookupRouting"/>
</then>
</if>
</else>
</if-not-empty>
<if-not-empty field-name="routing">
<set from-field="routing.workEffortId" field="lookupTasks.workEffortIdFrom"/>
<string-to-list string="sequenceNum" list-name="tasksOrder"/>
@@ -43,6 +43,8 @@ under the License.
location="org/ofbiz/manufacturing/routing/RoutingServices.xml" invoke="getProductRouting">
<description>Get the product's routing and routing tasks</description>
<attribute mode="IN" name="productId" optional="false" type="String"/>
<attribute mode="IN" name="workEffortId" optional="true" type="String"/>
<attribute mode="IN" name="applicableDate" optional="true" type="java.sql.Timestamp"/>
<attribute mode="IN" name="ignoreDefaultRouting" optional="true" type="String"/><!-- If this is set to Y, the default routing is not returned -->
<attribute mode="OUT" name="routing" type="GenericValue" optional="true"/>
<attribute mode="OUT" name="tasks" type="java.util.List" optional="true"/>
@@ -191,7 +191,30 @@ public class ProductionRunServices {
Debug.logWarning(e.getMessage(), module);
return ServiceUtil.returnError(e.getMessage());
}
// -------------------
// Routing and routing tasks
// -------------------
// Select the product's routing
try {
Map routingInMap = UtilMisc.toMap("productId", productId, "applicableDate", startDate, "userLogin", userLogin);
if (workEffortId != null) {
routingInMap.put("workEffortId", workEffortId);
}
Map routingOutMap = dispatcher.runSync("getProductRouting", routingInMap);
routing = (GenericValue)routingOutMap.get("routing");
routingTaskAssocs = (List)routingOutMap.get("tasks");
} catch(GenericServiceException gse) {
Debug.logWarning(gse.getMessage(), module);
}
// =================================
if (routing == null) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductRoutingNotExist", locale));
}
if (routingTaskAssocs == null || routingTaskAssocs.size()==0) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingRoutingHasNoRoutingTask", locale));
}
// -------------------
// Components
// -------------------
@@ -206,34 +229,11 @@ public class ProductionRunServices {
try {
resultService = dispatcher.runSync("getManufacturingComponents", serviceContext);
components = (List)resultService.get("components"); // a list of objects representing the product's components
if (workEffortId == null) {
workEffortId = (String)resultService.get("workEffortId"); // the product routing id
}
} catch (GenericServiceException e) {
Debug.logError(e, "Problem calling the getManufacturingComponents service", module);
return ServiceUtil.returnError(e.getMessage());
}
// -------------------
// Routing and routing tasks
// -------------------
// Select the product's routing
try {
Map routingInMap = UtilMisc.toMap("productId", productId, "userLogin", userLogin);
Map routingOutMap = dispatcher.runSync("getProductRouting", routingInMap);
routing = (GenericValue)routingOutMap.get("routing");
routingTaskAssocs = (List)routingOutMap.get("tasks");
} catch(GenericServiceException gse) {
Debug.logWarning(gse.getMessage(), module);
}
// =================================
if (routing == null) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductRoutingNotExist", locale));
}
if (routingTaskAssocs == null || routingTaskAssocs.size()==0) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingRoutingHasNoRoutingTask", locale));
}
// ProductionRun header creation,
if (workEffortName == null) {
String prdName = UtilValidate.isNotEmpty(product.getString("productName"))? product.getString("productName"): product.getString("productId");