Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API endpoint for customer returns #3579

Merged

Conversation

seand7565
Copy link
Contributor

@seand7565 seand7565 commented Apr 8, 2020

THIS PR SPONSORED BY Super Good Software

Description

Adds an API endpoint that allows you to manage customer returns. Also adds a test suite for this new API endpoint, adds associated jbuilder files, adds customer_return.number to ransackable attributes, and creates a connection between order and customer_return for easier referencing.

Just like return_items, when you create the customer_return you'll also need to add attributes for the return_items associated with the return.

Quick note: The way I'm referencing customer returns from the order is a bit convoluted, because there's no order_id on customer_returns. I think there should be, as it would simplify this a bit (and it makes sense that customer returns would be connected to the order like return authorizations are) - but it felt like it was outside of the scope of this PR.

Ref #3566

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have updated Guides and README accordingly to this change (if needed)
  • I have added tests to cover this change (if needed)
  • I have attached screenshots to this PR for visual changes (if needed)

@seand7565 seand7565 force-pushed the add_api_endpoint_for_customer_returns branch from 629af7a to c0c9b9c Compare April 8, 2020 11:46
Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great @seand7565, thanks! And also thanks @jarednorman!

I think we need to squash these two commits and add some API documentation as well. Feel free to ask if you need help with that.

@seand7565 seand7565 force-pushed the add_api_endpoint_for_customer_returns branch from c0c9b9c to 349b45f Compare April 12, 2020 11:57
@seand7565
Copy link
Contributor Author

@kennyadsl Squashed & documented! I added to the stoplight documentation, let me know how it looks. Thanks!

Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Sean!

@kennyadsl kennyadsl assigned kennyadsl and unassigned kennyadsl Apr 17, 2020
@kennyadsl kennyadsl added changelog:solidus_api Changes to the solidus_api gem Code Review Needed type:enhancement Proposed or newly added feature labels Apr 17, 2020
@ccarruitero
Copy link
Contributor

ccarruitero commented Apr 18, 2020

Thanks @seand7565 for the PR.

In admin workflow, in order to create a CustomerReturn, you need to create a ReturnAuthorization first.
https://guides.solidus.io/developers/returns/overview.html
https://guides.solidus.io/developers/returns/customer-returns.html

Until I understand, that is because you have to accept or not the return, and setup the ReturnReason and ReimbursementType for the ReturnItem

And after generate the CustomerReturn, you associate the ReturnItems that you will receive.

So, I think we should receive a return_authorization_id and list of ReturnItems parameters for create a CustomerReturn. Then, we should validate that the ReturnAuthorization is accepted for generate the new CustomerReturn and associate the given return items with the generated CustomerReturn.

Also, we should need to generate a Reimbursement for the items that the customer return

@seand7565
Copy link
Contributor Author

seand7565 commented Apr 19, 2020

Hey @ccarruitero, thanks for the review!

On requiring RMAs - I tried to model the API the same way the backend works. Currently, an RMA is NOT required for creating a Customer Return. You can create a customer return with no RMA, and it will create the customer return successfully. However, it will generate an “acceptance error” of {:rma_required=>"Return item requires an RMA”} - this does not prevent you from saving the Customer Return, nor will it prevent you from “receiving” it - it will toss the Customer Return into the “Rejected” column though, and will not create a reimbursement.

image

While I don’t like the way this is handled (there are a lot of Return Item statuses that don’t make sense with RMAs like “given to customer” or “lost in transit” - you wouldn’t be expecting a return in those situations but might still want a reimbursement), changing the functionality of how this works is another issue - one that I might tackle very shortly, but outside of the scope of this PR.

Reimbursements AFAIK are handled by return_item state changes - setting the reception status of the customer return should trigger the reimbursement handler.

I’ll take a look at your comments on the code a bit later - thanks for the input!

@kennyadsl
Copy link
Member

Thanks @seand7565 and @ccarruitero for the review!

The "RMA required" part is a bit tricky. By default, you need to have a RMA to create valid Return Items and Customer Returns.

This depends on a specific validator set here that can be changed depending on the needs.

For now, I'll keep it as in admin even if it's not ideal.

@seand7565 seand7565 force-pushed the add_api_endpoint_for_customer_returns branch from 349b45f to e1dad17 Compare May 16, 2020 18:16
api/config/routes.rb Outdated Show resolved Hide resolved
core/app/models/spree/order.rb Show resolved Hide resolved
@seand7565 seand7565 force-pushed the add_api_endpoint_for_customer_returns branch from e1dad17 to 5f1d4c1 Compare May 30, 2020 15:50
@seand7565 seand7565 force-pushed the add_api_endpoint_for_customer_returns branch from 5f1d4c1 to 90c4571 Compare May 30, 2020 15:59
@aldesantis aldesantis merged commit 20e622d into solidusio:master Jun 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_api Changes to the solidus_api gem type:enhancement Proposed or newly added feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants