SRO is stuck in "Init" when using ERP Connect for returns

I’m trying to perform a return through the ERP Connect API (not using the demo application), but the SRO state is still “Init” even after payment and delivery is “Returned”.

My steps, via ERP Connect v2:

  1. Create RMA from return slip
  2. Set RMA to packageReceived
  3. Set RMA to processing
  4. Set RMA to completed, which automatically creates the SRO
  5. Get SRO from RMA
  6. Confirm return for SRO
  7. Refund SRO

What am I doing wrong? I want to complete the RMA right away and then refund, basically all in one step.

Litium version: 7.6.2

You need to approve it first before complete the RMA.

  1. Create RMA from return slip
  2. Set RMA to packageReceived
  3. Set RMA to processing
  4. Approve RMA
  5. Set RMA to completed, which automatically creates the SRO
  6. Get SRO from RMA
  7. Confirm return for SRO
  8. Refund SRO

{{host}}/litium/api/connect/erp/rmas/{{rmaSystemId}}/approve

SRO can only move from Init to Return confirmed when the linked RMA has state = Completed and ApprovalCode = ApprovalCode.Approved

Some sample code:

SetState(systemId, Sales.RmaState.Completed);
var rma = _rmaService.Get(systemId)?.MakeWritableClone();
rma.ApprovalCode = Sales.ApprovalCode.Approved;
rma.ApprovedBy = SecurityToken.CurrentSecurityToken.UserID;
_rmaService.Update(rma);

The RMA now has state = Completed and ApprovalCode = Approved, using the erp connect endpoint “rmas/{systemId}/notify/approve”. However, the SRO is still in “Init” state?

When inspecting the RMA for the SRO, the “Approved by” and “Received by” are also filled in correctly.

Do I have to set ApprovalCode on each order row as well? I saw that the SRO rows have “None” as Approval code.
I’m trying to do everything with ERP connect, but maybe that’s not possible? I’d rather not write any Litium code if possible.

You’ll need to call the ConfirmReturn after RMA has been approved and completed. This is the API to set SRO state from Init to ConfirmReturn :

{{host}}/litium/api/connect/erp/salesReturnOrders/{{sroId}}/confirmReturn

And this is the condition for SRO to change from Init to ReturnConfirmed:

stateMachine.AddStateTransition(new State<OrderCarrier>((short)OrderState.Init, OrderState.Init.ToString()), returnConfirmed,
                (orderCarrier, startState, endState, token) =>
                {
                    //Conditions for SRO from init to ReturnConfirmed.
                    //Precodition:
                    //+RMA in Completed state and it should be Approved
                    //+Order is of type SalesReturnOrder                    
                    if (orderCarrier.Type != OrderType.SalesReturnOrder || orderCarrier.RmaSystemId is null || orderCarrier.RmaSystemId == Guid.Empty)
                    {
                        return false;
                    }
                    var rma = _rmaService.Get(orderCarrier.RmaSystemId.Value);
                    //RmaState.Completed denote that the Rma process is completed, the ApprovateCode.Approved denote that it actually is approved.
                    return rma?.State == RmaState.Completed && rma?.ApprovalCode == ApprovalCode.Approved;
                },
                false);
1 Like

Alright. So basically I did everything correct after your first answer, but I called “confirmReturned” instead of just “confirmReturn”, without checking if it was successful or not :slight_smile:

Thanks!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.