Skip to content

Keep the merchandise return API inside the panel's rules - #1062

Merged
KrzysztofPajak merged 3 commits into
developfrom
fix/merchandise-return-api-received
Nov 18, 2026
Merged

KrzysztofPajak merged 3 commits into
developfrom
fix/merchandise-return-api-received

Conversation

@KrzysztofPajak

Copy link
Copy Markdown
Member

Resolves: none
Type: bugfix

Issue

Two gaps in the merchandise return API added in #1059, found in its review against the S6 plan:

  1. POST /api/merchandisereturn/{key}/status with Received was accepted for any return the flow allows, while the panel refuses it when a product tracking stock has no posted return receipt (the goods reach the stock and their inspection only through a receipt). Through the API a return could be marked received with nothing booked, and a receipt posted later no longer marks it. NextStatuses also always offered Received.
  2. PUT /api/merchandisereturn/{key} overwrote every editable field with what was sent, so a body with only staffNotes cleared the customer's comment, the external id and the pickup address. It also wrote the pickup date and address where the store does not allow them.

Solution

  • The panel's rule moves to IMerchandiseReturnWorkflowService.CanMarkReceived (a posted receipt, or no product in the return tracks stock) and is shared by the panels and the API; the vendor panel keeps its exception (no inventory documents there). ChangeStatus itself is unchanged.
  • The API status endpoint refuses Received with 409 and Orders.MerchandiseReturns.StatusChangeNotAllowed when the rule says no; NextStatuses offers Received only when it is allowed, and never in the list (as the panel's list does not).
  • PUT changes only the fields that were sent (an empty string still clears a text); the pickup date and address change only when MerchandiseReturns_AllowToSpecifyPickupDate / ...PickupAddress are on, as in the panel.

Breaking changes

none (the API from #1059 is unreleased)

Testing

  1. dotnet test src/Tests/Grand.Business.Checkout.Tests - 857 passed (new CanMarkReceived tests).
  2. dotnet test src/Tests/Grand.Web.Admin.Tests - 2030 passed (panel Received tests now go through the shared rule).
  3. dotnet test src/Tests/Grand.Module.Api.Tests - 81 passed (Received refused/allowed/unknown return; PUT keeps unsent fields and respects the pickup settings).
  4. Manual (not run): on an accepted return of a stock-tracked product without a receipt, POST .../status {"status":15} returns 409 and GET .../{key} does not list 15 in nextStatuses; PUT .../{key} {"staffNotes":"x"} keeps customerComments.

- Marking a return Received by hand is allowed only when a return receipt was
  posted or no receipt can take its goods in. The rule moves from the admin
  view model to IMerchandiseReturnWorkflowService.CanMarkReceived, shared by
  the panels and the API; the vendor panel keeps its exception. The API status
  endpoint refuses Received otherwise, and NextStatuses offers it only then
  (never in the list, as in the panel's list).
- PUT on a return changes only the fields sent, so updating the staff notes
  keeps the customer's comment, external id and pickup address; the pickup
  date and address change only where the store setting allows them.
Copilot AI balanced review requested due to automatic review settings November 17, 2026 20:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

support added 2 commits November 18, 2026 07:44
The rule that only a return receipt marks a stock-tracked return received
now runs in StatusChangeError, on the return as stored under the order's
lock, so every caller gets it, not only the API handler and the panel. The
vendor panel, which has no inventory documents, passes withoutReturnReceipts
through a new ChangeStatus overload. CanMarkReceived also checks the products
of a ManageStockByBundleProducts bundle, as a receipt books those.
- PUT refuses a pickup date or address the return's store does not allow
  with 400 PickupNotAllowed, read from that store's settings; a value sent
  back as stored is not a change, so a read-modify-write still works
- an address with no field filled in clears the pickup address
- the list offers Received in nextStatuses as the return read by id does
- CanMarkReceived takes the order the panel loaded already
- the panel tests stub the rule's answer instead of copying it
- the edit page renders a return whose order or order item was deleted
@KrzysztofPajak
KrzysztofPajak merged commit 5e42e0f into develop Nov 18, 2026
9 checks passed
@KrzysztofPajak
KrzysztofPajak deleted the fix/merchandise-return-api-received branch November 18, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants