Author: jacopoc
Date: Sat Nov 21 08:15:16 2015 New Revision: 1715485 URL: http://svn.apache.org/viewvc?rev=1715485&view=rev Log: Implemented ability to refund non-physical goods (e.g. services). Thanks to Akash Jain for the contribution: OFBIZ-6728, OFBIZ-6729, OFBIZ-6730 Modified: ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java ofbiz/trunk/applications/order/data/OrderTypeData.xml ofbiz/trunk/applications/order/servicedef/secas.xml ofbiz/trunk/applications/product/script/org/ofbiz/shipment/shipment/ShipmentServices.xml ofbiz/trunk/applications/product/servicedef/services_shipment.xml Modified: ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml?rev=1715485&r1=1715484&r2=1715485&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml (original) +++ ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml Sat Nov 21 08:15:16 2015 @@ -602,6 +602,7 @@ under the License. <InvoiceItemTypeMap invoiceTypeId="CUST_RTN_INVOICE" invoiceItemMapKey="RET_WARRANTY_ADJ" invoiceItemTypeId="CRT_WARRANTY_ADJ"/> <InvoiceItemTypeMap invoiceTypeId="CUST_RTN_INVOICE" invoiceItemMapKey="RET_MAN_ADJ" invoiceItemTypeId="CRT_MAN_ADJ"/> <InvoiceItemTypeMap invoiceTypeId="CUST_RTN_INVOICE" invoiceItemMapKey="RET_MKTG_PKG_ADJ" invoiceItemTypeId="CRT_MKTG_PKG_ADJ"/> + <InvoiceItemTypeMap invoiceTypeId="CUST_RTN_INVOICE" invoiceItemMapKey="RET_SPROD_ITEM" invoiceItemTypeId="CRT_SPROD_ITEM"/> <InvoiceItemTypeMap invoiceTypeId="PURC_RTN_INVOICE" invoiceItemMapKey="RET_FPROD_ITEM" invoiceItemTypeId="SRT_FPROD_ITEM"/> <InvoiceItemTypeMap invoiceTypeId="PURC_RTN_INVOICE" invoiceItemMapKey="RET_DPROD_ITEM" invoiceItemTypeId="SRT_DPROD_ITEM"/> Modified: ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml?rev=1715485&r1=1715484&r2=1715485&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml (original) +++ ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml Sat Nov 21 08:15:16 2015 @@ -184,7 +184,7 @@ under the License. billItems = List of ShipmentReceipts (for sales return) or ItemIssuance (for purchase return) to use for creating the invoice </description> <attribute name="returnId" type="String" mode="IN" optional="false"/> - <attribute name="billItems" type="List" mode="IN" optional="false"/> + <attribute name="billItems" type="List" mode="IN" optional="true"/> <attribute name="invoiceId" type="String" mode="OUT" optional="true"/> </service> <service name="createCommissionInvoices" engine="java" Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java?rev=1715485&r1=1715484&r2=1715485&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java (original) +++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java Sat Nov 21 08:15:16 2015 @@ -1905,6 +1905,39 @@ public class InvoiceServices { invoiceTypeId = "PURC_RTN_INVOICE"; description = "Return Invoice for Vendor Return #" + returnId; } + + List<GenericValue> returnItems = returnHeader.getRelated("ReturnItem", null, null, false); + if (!returnItems.isEmpty()) { + for (GenericValue returnItem : returnItems) { + if ("RETURN_COMPLETED".equals(returnItem.getString("statusId"))) { + GenericValue product = returnItem.getRelatedOne("Product", false); + if (!ProductWorker.isPhysical(product)) { + boolean isNonPhysicalItemToReturn = false; + List<GenericValue> returnItemBillings = returnItem.getRelated("ReturnItemBilling", null, null, false); + + if (!returnItemBillings.isEmpty()) { + GenericValue invoice = EntityUtil.getFirst(returnItemBillings).getRelatedOne("Invoice", false); + if ("INVOICE_CANCELLED".equals(invoice.getString("statusId"))) { + isNonPhysicalItemToReturn = true; + } + } else { + isNonPhysicalItemToReturn = true; + } + + if (isNonPhysicalItemToReturn) { + if (UtilValidate.isEmpty(billItems)) { + billItems = new ArrayList(); + } + + billItems.add(returnItem); + } + } + } + } + } + + Map<String, Object> results = ServiceUtil.returnSuccess(); + if (UtilValidate.isNotEmpty(billItems)) { // set the invoice data Map<String, Object> input = UtilMisc.<String, Object>toMap("invoiceTypeId", invoiceTypeId, "statusId", "INVOICE_IN_PROCESS"); input.put("partyId", returnHeader.get("toPartyId")); @@ -1933,15 +1966,20 @@ public class InvoiceServices { for (GenericValue item : billItems) { boolean shipmentReceiptFound = false; boolean itemIssuanceFound = false; + GenericValue returnItem = null; + BigDecimal quantity = BigDecimal.ZERO; + if ("ShipmentReceipt".equals(item.getEntityName())) { shipmentReceiptFound = true; } else if ("ItemIssuance".equals(item.getEntityName())) { itemIssuanceFound = true; + } else if ("ReturnItem".equals(item.getEntityName())) { + quantity = item.getBigDecimal("returnQuantity"); + returnItem = item; } else { Debug.logError("Unexpected entity " + item + " of type " + item.getEntityName(), module); } // we need the related return item and product - GenericValue returnItem = null; if (shipmentReceiptFound) { returnItem = item.getRelatedOne("ReturnItem", true); } else if (itemIssuanceFound) { @@ -1962,7 +2000,6 @@ public class InvoiceServices { "AccountingNoKnownInvoiceItemTypeReturnItemType", UtilMisc.toMap("returnItemTypeId", returnItem.getString("returnItemTypeId")), locale)); } - BigDecimal quantity = BigDecimal.ZERO; if (shipmentReceiptFound) { quantity = item.getBigDecimal("quantityAccepted"); } else if (itemIssuanceFound) { @@ -2137,8 +2174,8 @@ public class InvoiceServices { } // return the invoiceId - Map<String, Object> results = ServiceUtil.returnSuccess(); results.put("invoiceId", invoiceId); + } return results; } catch (GenericServiceException e) { Debug.logError(e, errorMsg + e.getMessage(), module); Modified: ofbiz/trunk/applications/order/data/OrderTypeData.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/data/OrderTypeData.xml?rev=1715485&r1=1715484&r2=1715485&view=diff ============================================================================== --- ofbiz/trunk/applications/order/data/OrderTypeData.xml (original) +++ ofbiz/trunk/applications/order/data/OrderTypeData.xml Sat Nov 21 08:15:16 2015 @@ -329,6 +329,7 @@ under the License. <ReturnItemTypeMap returnHeaderTypeId="CUSTOMER_RETURN" returnItemMapKey="RENTAL_ORDER_ITEM" returnItemTypeId="RET_FPROD_ITEM" /> <ReturnItemTypeMap returnHeaderTypeId="CUSTOMER_RETURN" returnItemMapKey="ASSET_USAGE_OUT_IN" returnItemTypeId="RET_FPROD_ITEM" /> <ReturnItemTypeMap returnHeaderTypeId="CUSTOMER_RETURN" returnItemMapKey="SERVICE_PRODUCT" returnItemTypeId="RET_SPROD_ITEM"/> + <ReturnItemTypeMap returnHeaderTypeId="CUSTOMER_RETURN" returnItemMapKey="SERVICE" returnItemTypeId="RET_SPROD_ITEM"/> <ReturnItemTypeMap returnHeaderTypeId="CUSTOMER_RETURN" returnItemMapKey="RAW_MATERIAL" returnItemTypeId="RET_MPROD_ITEM"/> <ReturnItemTypeMap returnHeaderTypeId="VENDOR_RETURN" returnItemMapKey="FINISHED_GOOD" returnItemTypeId="RET_FPROD_ITEM"/> <ReturnItemTypeMap returnHeaderTypeId="VENDOR_RETURN" returnItemMapKey="MARKETING_PKG_AUTO" returnItemTypeId="RET_FPROD_ITEM"/> Modified: ofbiz/trunk/applications/order/servicedef/secas.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/secas.xml?rev=1715485&r1=1715484&r2=1715485&view=diff ============================================================================== --- ofbiz/trunk/applications/order/servicedef/secas.xml (original) +++ ofbiz/trunk/applications/order/servicedef/secas.xml Sat Nov 21 08:15:16 2015 @@ -251,6 +251,7 @@ under the License. <action service="sendReturnCompleteNotification" mode="async" persist="true"/> <action service="processSubscriptionReturn" mode="sync"/> <action service="createReturnStatus" mode="sync"/> + <action service="createInvoiceFromReturn" mode="sync"/> </eca> <eca service="updateReturnHeader" event="commit"> <condition field-name="statusId" operator="equals" value="RETURN_CANCELLED"/> Modified: ofbiz/trunk/applications/product/script/org/ofbiz/shipment/shipment/ShipmentServices.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/script/org/ofbiz/shipment/shipment/ShipmentServices.xml?rev=1715485&r1=1715484&r2=1715485&view=diff ============================================================================== --- ofbiz/trunk/applications/product/script/org/ofbiz/shipment/shipment/ShipmentServices.xml (original) +++ ofbiz/trunk/applications/product/script/org/ofbiz/shipment/shipment/ShipmentServices.xml Sat Nov 21 08:15:16 2015 @@ -333,6 +333,25 @@ under the License. </simple-method> <simple-method method-name="createShipmentAndItemsForReturn" short-description="Create Shipment and ShipmentItems based on ReturnHeader and ReturnItems"> + <entity-condition entity-name="ReturnItem" list="returnItems"> + <condition-expr field-name="returnId" operator="equals" from-field="parameters.returnId"/> + </entity-condition> + + <!-- The return shipment is created if the return contains one or more physical products --> + <set field="isPhysicalProductAvailable" value="false" type="Boolean"/> + <iterate entry="returnItem" list="returnItems"> + <get-related-one value-field="returnItem" relation-name="Product" to-value-field="product"/> + <if-not-empty field="product"> + <call-class-method class-name="org.ofbiz.product.product.ProductWorker" method-name="isPhysical" ret-field="isPhysicalProduct"> + <field field="product" type="GenericValue"/> + </call-class-method> + <if-compare field="isPhysicalProduct" operator="equals" value="true" type="Boolean"> + <set field="isPhysicalProductAvailable" value="true" type="Boolean"/> + </if-compare> + </if-not-empty> + </iterate> + + <if-compare field="isPhysicalProductAvailable" operator="equals" value="true" type="Boolean"> <set-service-fields service-name="createShipmentForReturn" map="parameters" to-map="shipmentCtx"/> <call-service service-name="createShipmentForReturn" in-map-name="shipmentCtx"> <result-to-field result-name="shipmentId"/> @@ -340,10 +359,18 @@ under the License. <check-errors/> <log level="info" message="Created new shipment ${shipmentId}"/> - <entity-condition entity-name="ReturnItem" list="returnItems"> - <condition-expr field-name="returnId" operator="equals" from-field="parameters.returnId"/> - </entity-condition> <iterate entry="returnItem" list="returnItems"> + + <!-- Shipment items are created only for physical products --> + <set field="isPhysicalProduct" value="false" type="Boolean"/> + <get-related-one value-field="returnItem" relation-name="Product" to-value-field="product"/> + <if-not-empty field="product"> + <call-class-method class-name="org.ofbiz.product.product.ProductWorker" method-name="isPhysical" ret-field="isPhysicalProduct"> + <field field="product" type="GenericValue"/> + </call-class-method> + </if-not-empty> + + <if-compare field="isPhysicalProduct" operator="equals" value="true" type="Boolean"> <clear-field field="shipItemCtx"/> <set from-field="shipmentId" field="shipItemCtx.shipmentId"/> <set from-field="returnItem.productId" field="shipItemCtx.productId"/> @@ -359,9 +386,11 @@ under the License. <set from-field="returnItem.returnItemSeqId" field="shipItemCtx.returnItemSeqId"/> <set from-field="returnItem.returnQuantity" field="shipItemCtx.quantity"/> <call-service service-name="createReturnItemShipment" in-map-name="shipItemCtx"/> + </if-compare> </iterate> <field-to-result field="shipmentId"/> + </if-compare> </simple-method> <simple-method method-name="createShipmentAndItemsForVendorReturn" short-description="Create Shipment and ShipmentItems based on primaryReturnId for Vendor return"> Modified: ofbiz/trunk/applications/product/servicedef/services_shipment.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/servicedef/services_shipment.xml?rev=1715485&r1=1715484&r2=1715485&view=diff ============================================================================== --- ofbiz/trunk/applications/product/servicedef/services_shipment.xml (original) +++ ofbiz/trunk/applications/product/servicedef/services_shipment.xml Sat Nov 21 08:15:16 2015 @@ -112,7 +112,7 @@ under the License. <description>Create a Return Shipment and ShipmentItems with information from ReturnHeader and ReturnItems</description> <permission-service service-name="facilityGenericPermission" main-action="CREATE"/> <auto-attributes include="pk" mode="IN" optional="false"/> - <attribute name="shipmentId" type="String" mode="OUT" optional="false"/> + <attribute name="shipmentId" type="String" mode="OUT" optional="true"/> </service> <service name="createShipmentAndItemsForVendorReturn" default-entity-name="Shipment" engine="simple" |
Free forum by Nabble | Edit this page |