-
-
Notifications
You must be signed in to change notification settings - Fork 730
Reset stock for absent products in DFC catalog #13191
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, looks good to me.
I have to admit it took me a while to get my head around the logic, it's complicated! Well done.
I suggest a comment to explain the intent (mostly copied from your issue description)
Also what do you think about conditionally showing the reset_products
message only when count.positive?
Thank you, done.
Yes, that had crossed my mind and I almost did it yesterday. Now I added that condition. I also added a preview of the products that will be reset. It's not perfect because I'm not passing on the variant ids of products to reset but that should be okay for now. This uncertainty would also occur during automatic import. I think I have a new idea about how to go forward with this. During manual import, we could give the choice between resetting stock (default behaviour) or unlinking the variant. Once the semantic link is removed, the automatic import won't reset it anymore. But let's wait for someone to have a problem before we suggest a solution. 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, that makes things much more transparent. And it's really well explained too 💯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍
Further update following slack conversation... I don't think we can just remove a product. If the product is back ordered, the OFN hub could be holding stock (for a mapped variant product). In that scenario, we want the hub to be able to sell the rest of the stock, but not back order more. In other scenarios (for non-mapped products), we need to prevent any further sales... as the hub won't be holding any stock. @mkllnk - Will your suggestion (to just amend the on demand flag) work for both of those scenarios? Do we need different logic, depending on whether the product has variant mappings or not? |
Let's play it through. Mapped variants, stock controlThe variant becomes unavailable. The stock had been calculated from the wholesale stock but should now be reduced to zero. Mapped variants, on-demandThe distributor has left-over stock from the last order cycle and is happy to sell that until sold out. The solution is to set the variant to stock-controlled but not touch the stock level. Non-mapped products, stock controlThe product becomes unavailable. We need to set the stock to zero. Non-mapped products, on-demandSince there was no mapping, we were able to backorder the exact amount we needed. The stock level should be 0 already. A positive stock level is only achieved if orders were cancelled and the backorder couldn't be adjusted (already complete). In that case we have left-over stock and the distributor may be happy to sell that? General solutionWhen we have a product locally that is missing in the remote catalog, we need to distinguish between two cases:
|
Not sure I agree with this case. If it's a mapped variant, I'm ordering cases, so the OFN stock reflects locally held stock right? 😕 Does it make a difference whether it's limited or not? Or is OFN tracking when to reorder wholesale variants somewhere else?
✔️
✔️
✔️
I think those are the 2 scenarios, I'm not sure we're aligned on when to apply them. I think we need to determine when stock reflects locally held stock (for split wholesale cases) and leave that in place (but remove the on demand flag to prevent more back orders). |
That's not how it works at the moment. If the variant in Shopify has limited stock then we just cache the stock level in OFN. We don't remember any local stock. We only remember local stock when the variant is set to on-demand, unlimited stock. We don't have a way to track the remote stock level and remember left-overs from the last order cycle. We would need two stock levels for that while OFN has only one per variant. This discussion is now getting out of the scope of this issue about resetting stock. I think it would be a bigger piece of work to introduce two stock levels. |
Ok. So if I have a Product with mapped variants & variants have limited stock, OFN doesn't set it to On Demand ? 😕 I'm really confused - how does OFN handle mapped variant stock levels, if they're not unlimited ? Or are we not handling that yet ? (I checked & Hod's don't have any on the FDC export atm 😅 )
So, we can't track the remote stock level, but if it's unlimited we are tracking local stock levels, is that correct ?
Agreed, and I hope we don't need to. |
We don't handle that yet. |
Correct. |
Thanks @mkllnk. I think this makes sense now & it's the most sensible course for now. 1 final follow up question - if OFN was to handle limited stock of mapped variants, how would you go about it (understanding that will be a separate issue) ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great explanation 👍
Garethe provided feedback via Slack, I should be able to proceed now 👍 |
Hey @mkllnk @dacook @RaggedStaff , On the proposed test cases: Product Import i) If a product is set to on demand (with on_hand = 0) and another one is stock controlled (on_hand = 2), then: Removing these two products from the catalog on Shopify, and re-importing the catalog: This removes the products from the shopfront, in both cases, the available stock is zero. ii) If a product is set to on demand (but has available stock which is non-zero, in the example below, on_hand = 222) and another one is stock controlled (on_hand = 2): then, repeating the steps above (removing the products from the DFC catalog, and re-importing them):
Order Cycle Opening (Product Sync) The outcome is the same, on product sync, by opening of an order cycle, i.e.,:
So, this looks good to merge? I've noticed a minor regression though, but it is only affecting the UI, and not the import functionality itself: I've noticed that on product import, the number of successfully imported products is not displayed, as it used to. After this PR, importing 10 products, displays: Before this PR: |
Great news, thanks Filipe. I'll have a look at that regression tomorrow. |
It took me an embarrassingly long time to figure out what was happening there. I discovered that the count variable has been removed in the translations. I'm not sure why, will ask in #translations |
@@ -3,5 +3,6 @@ | |||
|
|||
= render partial: 'spree/admin/shared/product_sub_menu' | |||
|
|||
%p= t(".imported_products") | |||
= @count | |||
%p= t(".imported_products", count: @count) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is an existing translation, the old translation (without count variable) is already present in about 11 locale files. This results in the @count
variable no longer printing:
I've noticed that on product import, the number of successfully imported products is not displayed, as it used to.
Ideally, I think we would announce to translators to re-translate (maybe through transifex if there's a feature for that). Or create a different key.
But given that it's going to display exactly as it was before, I will go ahead and update the locale files to resolve this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this now, I'm not sure why the spec ./spec/system/admin/dfc_product_import_spec.rb:20
did not catch this regression... It fails on my local system (before you've fixed it @dacook ).
imports from given catalog (FAILED - 1)
Failures:
1) DFC Product Import imports from given catalog
Failure/Error: expect(page).to have_content "Imported products: 1"
expected to find text "Imported products: 1" in "Logged in as : [email protected] Account Logout Store Dashboard Products Reports Enterprises Products Inventory Import DFC product catalog import Imported products:"
Normally I'd avoid editing these files, but this results in translations appearing exactly as they did prior to the PR. Ideally I would notify translators to re-translate but I don't know that there's a good process for that. Hopefully this is fine and doesn't cause any conflicts...
Gaetan are you ok with the final commit? I think it should be ok but it would be good to have another sense check. |
Yeah it should be good. |
Hey @dacook , I see your latest commit only changes the locales, so I did not perform additional tests on the functionality introduced on this PR, just on how the import page is rendered. I think changing the
Merging, thanks for addressing this. |
ℹ️ Funded Feature. Please track ALL ASSOCIATED WORK under the associated tracking code
#11678 DFC Orders
What? Why?
During DFC product import, we now reset stock for absent products. The exact conditions are:
Review notes
The pull request includes:
New commits start at: Reset stock for absent products in DFC catalog
What should we test?
Release notes
Changelog Category (reviewers may add a label for the release notes):
The title of the pull request will be included in the release notes.
Dependencies
Follow-up