London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

Create return order programmatically

Vote:
 

Hi

Is it possible to create and add a return order to a PurchaseOrder programmatically?

I was thinking about Doing it manually, something like:

var returnOrderForm = purchaseOrder.OrderForms.first().Clone() as OrderForm;
returnOrderForm.ReturnType = "Refund";
returnOrderForm.RMANumber = "MyRMANum";
purchaseOrder.ReturnOrderForms.Add(returnOrderForm);
purchaseOrder.AcceptChanges();

But is this a bad idea?

We run EPiServer 7.5

Henrik Rasmussen

#133414
Sep 03, 2015 15:53
Vote:
 

Hi,

It depends on what you want, but we usually do this:

			 OrderForm returnForm = purchaseOrder.ReturnOrderForms.AddNew();
 returnForm.Name = OrderForm.ReturnName;
 returnForm.OrigOrderFormId = purchaseOrder.OrderForms[0].OrderFormId;
 returnForm.ReturnType = ReturnType.Refund;
 returnForm.Status = ReturnFormStatus.AwaitingStockReturn.ToString();
 returnForm.RMANumber = returnForm.ReturnFormNumberMethod(returnForm);
 returnForm.CreatorId = PrincipalInfo.CurrentPrincipal.GetContactId().ToString();
 
 return returnForm;
So you can ensure some information is more correct this way.
Regards,
/Q


#133443
Edited, Sep 04, 2015 13:38
Vote:
 

I tried what your suggested but also added a LineItem to the return order. Futrhermore, I called the AcceptChanges() on the returnOrder to acctually save the order in the database. This created a return order, but it seemed corrupted as i tried to edit it from the Commerce Manager it produced an exception. This error revealed that there is a ReturnExchangeManager available in the SDK which implements the procedure Mr Mai suggested which is more comfortable to me.

This is how I used the ReturnExchangeManager:

private void createRefundForm(PurchaseOrder Order, int index, int returnQuantity, String returnReason)
{
    OrderForm returnForm = ReturnExchangeManager.AddNewReturnFormToPurchaseOrder(Order);
    ReturnExchangeManager.AddNewReturnLineItemToReturnForm(
        returnForm, Order.OrderForms[0].LineItems[index], returnQuantity, returnReason);
    returnForm.AcceptChanges();
}

Where Order is the order to return and the index is the index of the lineitems to return

Henrik

#133712
Sep 09, 2015 9:44
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.