Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ Map updateReturnHeader() {
adjustment: BigDecimal.ZERO]
BigDecimal availableReturnTotal = serviceResult.availableReturnTotal
BigDecimal returnTotal = serviceResult.returnTotal
BigDecimal orderTotal = serviceResult.returnTotal
BigDecimal orderTotal = serviceResult.orderTotal
logInfo("Available amount for return on order # ${returnItem.orderId} is " +
"[${availableReturnTotal}] (orderTotal = [${orderTotal}] - returnTotal = [${returnTotal}]")
"[${availableReturnTotal}] (orderTotal = [${orderTotal}] - returnTotal = [${returnTotal}])")

if (availableReturnTotal < -0.01) {
return informError('OrderReturnPriceCannotExceedTheOrderTotal')
Expand Down Expand Up @@ -520,22 +520,21 @@ Map quickReturnFromOrder() {
.where(orderId: orderHeader.orderId, orderItemSeqId: '_NA_')
.queryList()
for (GenericValue orderAdjustment : orderAdjustments) {
Map returnAdjCtx = [:]
returnAdjCtx.returnId = returnId
Map returnAdjCtx = [returnId: returnId, orderAdjustmentId: orderAdjustment.orderAdjustmentId]
// filter out orderAdjustment that have been returned
if (from('ReturnAdjustment').where(orderAdjustmentId: orderAdjustment.orderAdjustmentId).queryCount() == 0) {
logInfo('Create new return adjustment: ' + returnAdjCtx)
run service: 'createReturnAdjustment', with: returnAdjCtx
}
}
// very important: if countNewReturnItemx is not set,
// very important: if countNewReturnItems is not set,
// getOrderAvailableReturnedTotal would not count the return items we just created
Map orderAvailableCtx = [orderId: orderHeader.orderId, countNewReturnItemx: true]
Map orderAvailableCtx = [orderId: orderHeader.orderId, countNewReturnItems: true]
Map serviceResultART = run service: 'getOrderAvailableReturnedTotal', with: orderAvailableCtx
BigDecimal availableReturnTotal = serviceResult.availableReturnTotal
BigDecimal availableReturnTotal = serviceResultART.availableReturnTotal
BigDecimal returnTotal = serviceResultART.returnTotal
BigDecimal orderTotal = serviceResultART.orderTotal
logInfo("OrderTotal [${orderTotal}] - ReturnTotal [${returnTotal}] = available Return Total [${}]")
logInfo("OrderTotal [${orderTotal}] - ReturnTotal [${returnTotal}] = available Return Total [${availableReturnTotal}]")

// create a manual balance adjustment based on the difference between order total and return total
if (availableReturnTotal != (BigDecimal.ZERO)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,45 @@ class OrderReturnTests extends OFBizTestCase {
}
// Return related test services
void testQuickReturnOrder() {
String orderId = 'TEST_RTN12432'
Map serviceCtx = [
orderId: 'TEST_DEMO10090',
orderId: orderId,
returnHeaderTypeId: 'CUSTOMER_RETURN',
userLogin: userLogin
]
Map serviceResult = dispatcher.runSync('quickReturnOrder', serviceCtx)
assert ServiceUtil.isSuccess(serviceResult)
assert serviceResult.returnId != null

List returnItems = from('ReturnItem').where(returnId: serviceResult.returnId).queryList()
assert returnItems.size() == 1
assert returnItems[0].returnQuantity == 2.0G
assert returnItems[0].returnPrice == 10.00G

List returnAdjustments = from('ReturnAdjustment').where(returnId: serviceResult.returnId).queryList()
assert returnAdjustments*.orderAdjustmentId.toSet() == [
'TEST_RTN12432_ITEM', 'TEST_RTN12432_PROMO', 'TEST_RTN12432_SHIP', 'TEST_RTN12432_TAX'
].toSet()
assert !returnAdjustments.any { it.returnAdjustmentTypeId == 'RET_MAN_ADJ' }

BigDecimal returnTotal = returnItems.sum(BigDecimal.ZERO) {
it.returnQuantity * it.returnPrice
} + returnAdjustments.sum(BigDecimal.ZERO) { it.amount }
assert returnTotal == 17.00G

Map invoiceResult = dispatcher.runSync('createInvoiceFromReturn', [
returnId: serviceResult.returnId,
billItems: returnItems,
userLogin: userLogin
])
assert ServiceUtil.isSuccess(invoiceResult)
assert invoiceResult.invoiceId != null

List invoiceItems = from('InvoiceItem').where(invoiceId: invoiceResult.invoiceId).queryList()
BigDecimal invoiceTotal = invoiceItems.sum(BigDecimal.ZERO) {
(it.quantity ?: BigDecimal.ONE) * it.amount
}
assert invoiceTotal == returnTotal
}
void testProcessCreditReturn() {
Map serviceCtx = [
Expand Down
3 changes: 2 additions & 1 deletion applications/order/template/return/ReturnItems.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ under the License.
<#local rowCount = rowCount + 1>
<#local rowCountForAdjRemove = rowCountForAdjRemove + 1>
</#if>
<#local returnTotal = returnTotal + returnAdjustment.amount?default(0)>
</tr>
</#macro>

Expand Down Expand Up @@ -262,6 +261,7 @@ under the License.
<#assign returnItemAdjustments = item.getRelated("ReturnAdjustment", null, null, false)>
<#if (returnItemAdjustments?has_content)>
<#list returnItemAdjustments as returnItemAdjustment>
<#assign returnTotal = returnTotal + returnItemAdjustment.amount?default(0)>
<@displayReturnAdjustment returnAdjustment=returnItemAdjustment adjEditable=false/> <#-- adjustments of return items should never be editable -->
</#list>
</#if>
Expand All @@ -278,6 +278,7 @@ under the License.
<#if (returnAdjustments?has_content)>
<#list returnAdjustments as returnAdjustment>
<#assign adjEditable = !readOnly> <#-- they are editable if the rest of the return items are -->
<#assign returnTotal = returnTotal + returnAdjustment.amount?default(0)>
<@displayReturnAdjustment returnAdjustment=returnAdjustment adjEditable=adjEditable/>
</#list>
</#if>
Expand Down
11 changes: 11 additions & 0 deletions applications/order/testdef/data/OrderTestData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ under the License.
<OrderRole orderId="TEST_DEMO10090" partyId="TestDemoCustomer" roleTypeId="PLACING_CUSTOMER"/>
<OrderRole orderId="TEST_DEMO10090" partyId="TestDemoCustomer" roleTypeId="SHIP_TO_CUSTOMER"/>
<OrderContactMech orderId="TEST_DEMO10090" contactMechPurposeTypeId="ORDER_EMAIL" contactMechId="TestContactMech"/>

<!-- Regression data for OFBIZ-12432: quick returns must preserve item and order adjustments. -->
<ProductStore productStoreId="TEST_RTN_STORE" storeName="Return Test Store" payToPartyId="Company"/>
<OrderHeader orderId="TEST_RTN12432" orderTypeId="SALES_ORDER" orderDate="2021-12-03 12:00:00.0" entryDate="2021-12-03 12:00:00.0" statusId="ORDER_COMPLETED" currencyUom="USD" productStoreId="TEST_RTN_STORE" remainingSubTotal="15.00" grandTotal="17.00"/>
<OrderItem orderId="TEST_RTN12432" orderItemSeqId="00001" orderItemTypeId="PRODUCT_ORDER_ITEM" productId="GZ-2644" isPromo="N" quantity="2.0" selectedAmount="0.0" unitPrice="10.00" unitListPrice="10.00" isModifiedPrice="N" itemDescription="OFBIZ-12432 return item" statusId="ITEM_COMPLETED"/>
<OrderRole orderId="TEST_RTN12432" partyId="TestDemoCustomer" roleTypeId="BILL_TO_CUSTOMER"/>
<OrderAdjustment orderAdjustmentId="TEST_RTN12432_ITEM" orderAdjustmentTypeId="PROMOTION_ADJUSTMENT" orderId="TEST_RTN12432" orderItemSeqId="00001" shipGroupSeqId="_NA_" description="Item promotion" amount="-5.00"/>
<OrderAdjustment orderAdjustmentId="TEST_RTN12432_PROMO" orderAdjustmentTypeId="PROMOTION_ADJUSTMENT" orderId="TEST_RTN12432" orderItemSeqId="_NA_" shipGroupSeqId="_NA_" description="Order promotion" amount="-2.00"/>
<OrderAdjustment orderAdjustmentId="TEST_RTN12432_SHIP" orderAdjustmentTypeId="SHIPPING_CHARGES" orderId="TEST_RTN12432" orderItemSeqId="_NA_" shipGroupSeqId="_NA_" description="Shipping" amount="3.00"/>
<OrderAdjustment orderAdjustmentId="TEST_RTN12432_TAX" orderAdjustmentTypeId="SALES_TAX" orderId="TEST_RTN12432" orderItemSeqId="_NA_" shipGroupSeqId="_NA_" description="Sales tax" amount="1.00"/>

<WorkEffort workEffortId="9000" workEffortTypeId="PROJECT" currentStatusId="_NA_" lastStatusUpdate="2007-12-14 15:07:52.901" scopeEnumId="WES_PRIVATE" workEffortName="Demo Project1 Cust1" revisionNumber="1"/>
<Requirement requirementId="1000" requirementTypeId="CUSTOMER_REQUIREMENT"/>
<ReturnHeader returnId="1009" statusId="RETURN_RECEIVED" returnHeaderTypeId="CUSTOMER_RETURN"/>
Expand Down
Loading