Skip to content

Fix shipment state when all units cancelled#6314

Merged
tvdeyen merged 2 commits intomainfrom
fix-shipment-cancellation
Sep 5, 2025
Merged

Fix shipment state when all units cancelled#6314
tvdeyen merged 2 commits intomainfrom
fix-shipment-cancellation

Conversation

@adammathys
Copy link
Member

@adammathys adammathys commented Jul 31, 2025

Summary

Includes two key changes:

  1. Removes logic in OrderCancellations to update shipment state. I tracked this logic back to a cherry-pick from some Bonobos code about a decade ago (c98d247), so the original reasoning for it is unfortunately lost to time. Our commit includes some reasoning around the removal, but essentially I don't think there's any scenario right now where this code makes sense. If we're triggering it because there's a mix of shipped and cancelled items, the shipment should already be "shipped" due to the shipped inventory units. If we're triggering it because all of the items are cancelled, we don't want to mark the shipment as "shipped" anyway.

  2. Updates Shipment#determine_state to mark shipments as cancelled if all inventory units are cancelled. As mentioned above, marking a shipment as shipped if all of the units are cancelled doesn't make a lot of sense. Since cancelling a unit will result in an order recalculation, we can rely on this method to update the shipment state appropriately.

Alternative for: #5220 & #4446

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

The following are not always needed:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

adammathys and others added 2 commits July 31, 2025 11:42
We don't need to be modifying the shipment state in our
OrderCancellations object. There are only two current situations where
this code will run:

1. All inventory units are shipped and one or more are cancelled.
    -> In this situation, the shipment will already be in a "shipped"
    state and there's no reason to change the `shipped_at` column.

2. All inventory units are cancelled.
    -> We don't really want to mark shipments as "shipped" in this
    situation anyway. So it's better to not do anything here.

Co-authored-by: Alistair Norman <alistair@super.gd>
Co-authored-by: Noah Silvera <noah@super.gd>
If we cancel all inventory units in a shipment, we should mark it as
cancelled itself because there's nothing to ship.

Co-authored-by: Alistair Norman <alistair@super.gd>
Co-authored-by: Noah Silvera <noah@super.gd>
@adammathys adammathys self-assigned this Jul 31, 2025
@adammathys adammathys requested a review from a team as a code owner July 31, 2025 19:07
@github-actions github-actions bot added the changelog:solidus_core Changes to the solidus_core gem label Jul 31, 2025
@codecov
Copy link

codecov bot commented Jul 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@424f284). Learn more about missing BASE report.
⚠️ Report is 45 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6314   +/-   ##
=======================================
  Coverage        ?   89.31%           
=======================================
  Files           ?      959           
  Lines           ?    20110           
  Branches        ?        0           
=======================================
  Hits            ?    17961           
  Misses          ?     2149           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

I would love to see a spec that covers that we are calling determine_state on the shipment when the order is cancelled, or even more high-level, that we are setting the state to cancelled when all the items are cancelled. Maybe there's already one?

By the way this is not blocking, approving, thanks!

Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

I agree with Alberto. If there is a spec verifying the behavior, then fine. Otherwise we should add a spec that ensures what is stated in the first commit message.

@tvdeyen tvdeyen added this to the 4.6 milestone Aug 5, 2025
@jarednorman
Copy link
Member

@adammathys You gonna add a spec here?

@tvdeyen tvdeyen merged commit a176b61 into main Sep 5, 2025
39 checks passed
@tvdeyen tvdeyen deleted the fix-shipment-cancellation branch September 5, 2025 15:55
@adammathys adammathys mentioned this pull request Sep 6, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog:solidus_core Changes to the solidus_core gem

Projects

Development

Successfully merging this pull request may close these issues.

4 participants