Author: jacopoc
Date: Mon May 7 13:01:02 2007 New Revision: 535972 URL: http://svn.apache.org/viewvc?view=rev&rev=535972 Log: Implemented first version of 'repair returns': a return for repair is like a normal replacement return, with the exception that an additional product is added to the replacement order. This item is a repair item (defined in ProductAssoc). Modified: ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderReturnServices.xml ofbiz/trunk/applications/order/servicedef/secas.xml ofbiz/trunk/applications/order/servicedef/services_return.xml ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java Modified: ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderReturnServices.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderReturnServices.xml?view=diff&rev=535972&r1=535971&r2=535972 ============================================================================== --- ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderReturnServices.xml (original) +++ ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderReturnServices.xml Mon May 7 13:01:02 2007 @@ -770,4 +770,9 @@ <set field="inMap.returnTypeId" value="RTN_CSREPLACE"/> <call-service service-name="processReplacementReturn" in-map-name="inMap"/> </simple-method> + <simple-method method-name="processRepairReplacementReturn" short-description="Process the replacements in a repair return"> + <set field="inMap.returnId" from-field="parameters.returnId"/> + <set field="inMap.returnTypeId" value="RTN_REPAIR_REPLACE"/> + <call-service service-name="processReplacementReturn" in-map-name="inMap"/> + </simple-method> </simple-methods> Modified: ofbiz/trunk/applications/order/servicedef/secas.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/secas.xml?view=diff&rev=535972&r1=535971&r2=535972 ============================================================================== --- ofbiz/trunk/applications/order/servicedef/secas.xml (original) +++ ofbiz/trunk/applications/order/servicedef/secas.xml Mon May 7 13:01:02 2007 @@ -148,6 +148,7 @@ <condition field-name="statusId" operator="equals" value="RETURN_RECEIVED"/> <condition field-name="currentStatusId" operator="not-equals" value="RETURN_RECEIVED"/> <action service="processWaitReplacementReturn" mode="sync"/> + <action service="processRepairReplacementReturn" mode="sync"/> <action service="processCreditReturn" mode="sync"/> <action service="processRefundReturn" mode="sync"/> </eca> @@ -173,6 +174,7 @@ <eca service="updateReturnStatusFromReceipt" event="global-commit"> <condition field-name="returnHeaderStatus" operator="equals" value="RETURN_RECEIVED"/> <action service="processWaitReplacementReturn" mode="sync" persist="true"/> + <action service="processRepairReplacementReturn" mode="sync"/> <action service="processCreditReturn" mode="sync" persist="true"/> <action service="processRefundReturn" mode="sync" persist="true"/> </eca> Modified: ofbiz/trunk/applications/order/servicedef/services_return.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services_return.xml?view=diff&rev=535972&r1=535971&r2=535972 ============================================================================== --- ofbiz/trunk/applications/order/servicedef/services_return.xml (original) +++ ofbiz/trunk/applications/order/servicedef/services_return.xml Mon May 7 13:01:02 2007 @@ -226,6 +226,11 @@ <description>Process the replacements in a cross-ship return</description> <attribute name="returnId" type="String" mode="IN" optional="false"/> </service> + <service name="processRepairReplacementReturn" engine="simple" auth="true" + location="org/ofbiz/order/order/OrderReturnServices.xml" invoke="processRepairReplacementReturn"> + <description>Process the replacements in a repair return</description> + <attribute name="returnId" type="String" mode="IN" optional="false"/> + </service> <service name="updateReturnStatusFromReceipt" engine="simple" location="org/ofbiz/order/order/OrderReturnServices.xml" invoke="updateReturnStatusFromReceipt"> <description>Update return/item status when items have been received</description> Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java?view=diff&rev=535972&r1=535971&r2=535972 ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java Mon May 7 13:01:02 2007 @@ -49,6 +49,7 @@ import org.ofbiz.entity.condition.EntityExpr; import org.ofbiz.entity.condition.EntityOperator; import org.ofbiz.entity.util.EntityUtil; +import org.ofbiz.product.product.ProductContentWrapper; import org.ofbiz.product.store.ProductStoreWorker; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.GenericServiceException; @@ -1342,6 +1343,8 @@ } // make the shipment prefs + /* + * OrderShipmentPreference is a deprecated entity List shipmentPrefs = new ArrayList(); List orderSp = null; try { @@ -1357,9 +1360,11 @@ } orderMap.put("orderShipmentPreferences", shipmentPrefs); } + */ // make the order items double itemTotal = 0.00; + double additionalItemTotal = 0.00; List orderItems = new ArrayList(); List orderItemShipGroupInfo = new ArrayList(); List orderItemShipGroupIds = new ArrayList(); // this is used to store the ship group ids of the groups already added to the orderItemShipGroupInfo list @@ -1380,8 +1385,8 @@ Double quantity = returnItem.getDouble("returnQuantity"); Double unitPrice = returnItem.getDouble("returnPrice"); if (quantity != null && unitPrice != null) { - itemTotal = (quantity.doubleValue() * unitPrice.doubleValue()); - GenericValue newItem = delegator.makeValue("OrderItem", UtilMisc.toMap("orderItemSeqId", UtilFormatOut.formatPaddedNumber(itemCount, 5))); + itemTotal = itemTotal + (quantity.doubleValue() * unitPrice.doubleValue()); + GenericValue newItem = delegator.makeValue("OrderItem", UtilMisc.toMap("orderItemSeqId", UtilFormatOut.formatPaddedNumber(itemCount++, 5))); newItem.set("orderItemTypeId", orderItem.get("orderItemTypeId")); newItem.set("productId", orderItem.get("productId")); @@ -1402,9 +1407,9 @@ // of the original order is considered and cloned, // anIs there a better way to handle this?d the returned units are assigned to it. // - + GenericValue orderItemShipGroupAssoc = null; try { - GenericValue orderItemShipGroupAssoc = EntityUtil.getFirst(orderItem.getRelated("OrderItemShipGroupAssoc")); + orderItemShipGroupAssoc = EntityUtil.getFirst(orderItem.getRelated("OrderItemShipGroupAssoc")); if (orderItemShipGroupAssoc != null) { if (!orderItemShipGroupIds.contains(orderItemShipGroupAssoc.getString("shipGroupSeqId"))) { GenericValue orderItemShipGroup = orderItemShipGroupAssoc.getRelatedOne("OrderItemShipGroup"); @@ -1424,6 +1429,97 @@ "orderItemSeqId", orderItem.getString("orderItemSeqId"), "shipGroupSeqId", "_NA_", "toOrderItemSeqId", newItem.getString("orderItemSeqId"), "toShipGroupSeqId", "_NA_", "orderItemAssocTypeId", "REPLACEMENT")); orderItemAssocs.add(newOrderItemAssoc); + + // For repair replacement orders, add to the order also the repair items + if ("RTN_REPAIR_REPLACE".equals(returnTypeId)) { + List repairItems = null; + try { + GenericValue product = orderItem.getRelatedOne("Product"); + if (UtilValidate.isNotEmpty(product)) { + repairItems = EntityUtil.filterByDate(product.getRelated("MainProductAssoc", + UtilMisc.toMap("productAssocTypeId", "PRODUCT_REPAIR_SRV"), + UtilMisc.toList("sequenceNum"))); + } + } catch (GenericEntityException e) { + Debug.logError(e, module); + continue; + } + if (UtilValidate.isNotEmpty(repairItems)) { + Iterator repairItemIt = repairItems.iterator(); + while (repairItemIt.hasNext()) { + GenericValue repairItem = (GenericValue)repairItemIt.next(); + GenericValue repairItemProduct = null; + try { + repairItemProduct = repairItem.getRelatedOne("AssocProduct"); + } catch (GenericEntityException e) { + Debug.logError(e, module); + continue; + } + if (UtilValidate.isNotEmpty(repairItemProduct)) { + Double repairUnitQuantity = repairItem.getDouble("quantity"); + if (UtilValidate.isEmpty(repairUnitQuantity)) { + repairUnitQuantity = new Double(1.0); + } + Double repairQuantity = new Double(quantity.doubleValue() * repairUnitQuantity.doubleValue()); + newItem = delegator.makeValue("OrderItem", UtilMisc.toMap("orderItemSeqId", UtilFormatOut.formatPaddedNumber(itemCount++, 5))); + + // price + Map priceContext = FastMap.newInstance(); + priceContext.put("currencyUomId", orderHeader.get("currencyUom")); + if (placingPartyId != null) { + priceContext.put("partyId", placingPartyId); + } + priceContext.put("quantity", repairUnitQuantity); + priceContext.put("product", repairItemProduct); + priceContext.put("webSiteId", orderHeader.get("webSiteId")); + priceContext.put("productStoreId", orderHeader.get("productStoreId")); + // TODO: prodCatalogId, agreementId + priceContext.put("productPricePurposeId", "PURCHASE"); + priceContext.put("checkIncludeVat", "Y"); + Map priceResult = null; + try { + priceResult = dispatcher.runSync("calculateProductPrice", priceContext); + } catch(GenericServiceException gse) { + Debug.logError(gse, module); + continue; + } + if (ServiceUtil.isError(priceResult)) { + Debug.logError(ServiceUtil.getErrorMessage(priceResult), module); + continue; + } + Boolean validPriceFound = (Boolean) priceResult.get("validPriceFound"); + if (Boolean.FALSE.equals(validPriceFound)) { + Debug.logError("Could not find a valid price for the product with ID [" + repairItemProduct.get("productId") + "].", module); + continue; + } + + if (priceResult.get("listPrice") != null) { + newItem.set("unitListPrice", (Double)priceResult.get("listPrice")); + } + + Double repairUnitPrice = null; + if (priceResult.get("basePrice") != null) { + repairUnitPrice = (Double)priceResult.get("basePrice"); + } else { + repairUnitPrice = new Double(0.0); + } + newItem.set("unitPrice", repairUnitPrice); + + newItem.set("productId", repairItemProduct.get("productId")); + // TODO: orderItemTypeId, prodCatalogId, productCategoryId + newItem.set("quantity", repairQuantity); + newItem.set("itemDescription", ProductContentWrapper.getProductContentAsText(repairItemProduct, "PRODUCT_NAME", locale, null)); + newItem.set("statusId", "ITEM_CREATED"); + orderItems.add(newItem); + additionalItemTotal = additionalItemTotal + (repairQuantity.doubleValue() * repairUnitPrice.doubleValue()); + if (UtilValidate.isNotEmpty(orderItemShipGroupAssoc)) { + GenericValue newOrderItemShipGroupAssoc = delegator.makeValue("OrderItemShipGroupAssoc", UtilMisc.toMap("orderItemSeqId", newItem.getString("orderItemSeqId"), "shipGroupSeqId", orderItemShipGroupAssoc.getString("shipGroupSeqId"), "quantity", repairQuantity)); + orderItemShipGroupInfo.add(newOrderItemShipGroupAssoc); + } + } + } + } + } } } } @@ -1447,6 +1543,36 @@ adj.set("createdDate", UtilDateTime.nowTimestamp()); adj.set("createdByUserLogin", userLogin.getString("userLoginId")); orderMap.put("orderAdjustments", UtilMisc.toList(adj)); + + // Payment preference + if (additionalItemTotal > 0) { + GenericValue paymentMethod = null; + try { + paymentMethod = returnHeader.getRelatedOne("PaymentMethod"); + } catch (GenericEntityException e) { + Debug.logError(e, module); + } + if (UtilValidate.isNotEmpty(paymentMethod)) { + String paymentMethodId = paymentMethod.getString("paymentMethodId"); + String paymentMethodTypeId = paymentMethod.getString("paymentMethodTypeId"); + GenericValue opp = delegator.makeValue("OrderPaymentPreference", new HashMap()); + opp.set("paymentMethodTypeId", paymentMethodTypeId); + opp.set("paymentMethodId", paymentMethodId); + // TODO: manualRefNum, manualAuthCode, securityCode, presentFlag, overflowFlag + if (paymentMethodId != null || "FIN_ACCOUNT".equals(paymentMethodTypeId)) { + opp.set("statusId", "PAYMENT_NOT_AUTH"); + } else if (paymentMethodTypeId != null) { + // external payment method types require notification when received + // internal payment method types are assumed to be in-hand + if (paymentMethodTypeId.startsWith("EXT_")) { + opp.set("statusId", "PAYMENT_NOT_RECEIVED"); + } else { + opp.set("statusId", "PAYMENT_RECEIVED"); + } + } + orderMap.put("orderPaymentInfo", UtilMisc.toList(opp)); + } + } // we'll assume new order is under same terms as original. note orderTerms is a required parameter of storeOrder try { |
Free forum by Nabble | Edit this page |