-
-
Notifications
You must be signed in to change notification settings - Fork 729
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
[Spree Upgrade] Remove variant.count_on_hand (keep variant.on_hand only) #3513
Changes from all commits
f0842fc
12eab1b
30967a5
8ee14cc
a36722c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,61 +20,30 @@ module VariantStock | |
after_update :save_stock | ||
end | ||
|
||
# Returns the number of items of the variant available in the stock. When | ||
# allowing on demand, it returns infinite. | ||
# | ||
# Spree computes it as the sum of the count_on_hand of all its stock_items. | ||
# Returns the number of items of the variant available. | ||
# Spree computes total_on_hand as the sum of the count_on_hand of all its stock_items. | ||
# | ||
# @return [Float|Integer] | ||
def on_hand | ||
warn_deprecation(__method__, '#total_on_hand') | ||
|
||
if on_demand | ||
Float::INFINITY | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a step backwards. We changed this because Spree introduced this logic of returning infinity. This change would make us less compatible with Spree again. I would prefer to adjust the cart logic or the serializer to deal with infinity. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is a step forward Maikel. I will explain. Also, one important detail for this logic is that in spree, and soon in ofn, on_demand means backorderable: that means that even if the item is backorderable (which will be the on_demand field), the on_hand value will still be used. Basically stock can go to negative. So, this is a move in the direction of making on_demand equal to backorderable and also it removes magic. did I convince you? :-D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "The I am not too worried with client side code here (although I have tested it and it works), we can improve it later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really liked the infinity solution as it seemed mathematically correct and solving all the problems. But you convinced me with the different use of on_hand. There are two different uses that Spree started to separate:
And on_hand sounds a bit more like the answer to the second question. |
||
else | ||
total_on_hand | ||
end | ||
end | ||
|
||
# Returns the number of items available in the stock for this variant | ||
# | ||
# @return [Float|Integer] | ||
def count_on_hand | ||
warn_deprecation(__method__, '#total_on_hand') | ||
total_on_hand | ||
end | ||
|
||
# Sets the stock level when `track_inventory_levels` config is | ||
# set. It raises otherwise. | ||
# Sets the stock level of the variant. | ||
# This will only work if `track_inventory_levels` config is set | ||
# and if there is a stock item for the variant. | ||
# | ||
# @raise [StandardError] when the track_inventory_levels config | ||
# key is not set. | ||
# @raise [StandardError] when the track_inventory_levels config key is not set | ||
# and when the variant has no stock item | ||
def on_hand=(new_level) | ||
warn_deprecation(__method__, '#total_on_hand') | ||
|
||
error = 'Cannot set on_hand value when Spree::Config[:track_inventory_levels] is false' | ||
raise error unless Spree::Config.track_inventory_levels | ||
|
||
self.count_on_hand = new_level | ||
end | ||
|
||
# Sets the stock level. As opposed to #on_hand= it does not check | ||
# `track_inventory_levels`'s value as it was previously an ActiveModel | ||
# setter of the database column of the `spree_variants` table. That is why | ||
# #on_hand= is more widely used in Spree's codebase using #count_on_hand= | ||
# underneath. | ||
# | ||
# So, if #count_on_hand= is used, `track_inventory_levels` won't be taken | ||
# into account thus dismissing instance's configuration. | ||
# | ||
# It does ensure there's a stock item for the variant however. See | ||
# #raise_error_if_no_stock_item_available for details. | ||
# | ||
# @raise [StandardError] when the variant has no stock item yet | ||
def count_on_hand=(new_level) | ||
warn_deprecation(__method__, '#total_on_hand') | ||
|
||
raise_error_if_no_stock_item_available | ||
|
||
overwrite_stock_levels(new_level) | ||
end | ||
|
||
|
@@ -131,7 +100,7 @@ def can_supply?(quantity) | |
# Here we depend only on variant.total_on_hand and variant.on_demand. | ||
# This way, variant_overrides only need to override variant.total_on_hand and variant.on_demand. | ||
def fill_status(quantity) | ||
if count_on_hand >= quantity | ||
if on_hand >= quantity | ||
on_hand = quantity | ||
backordered = 0 | ||
else | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,8 @@ | |
%input{ 'ng-model' => 'variant.price', 'ofn-decimal' => :true, :name => 'variant_price', 'ofn-track-variant' => 'price', :type => 'text' } | ||
%td{ 'ng-show' => 'columns.on_hand.visible' } | ||
%input.field{ 'ng-model' => 'variant.on_hand', 'ng-change' => 'updateOnHand(product)', :name => 'variant_on_hand', 'ng-if' => '!variant.on_demand', 'ofn-track-variant' => 'on_hand', :type => 'number' } | ||
%span{ 'ng-bind' => 'variant.on_hand', :name => 'variant_on_hand', 'ng-if' => 'variant.on_demand' } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't want "on demand" to be bound to the on_hand value, ng-bind would do that. the binding is only when variant is not on_demand, the ng-ifs are controlling that. |
||
%span{ :name => 'variant_on_hand', 'ng-if' => 'variant.on_demand' } | ||
= t(:on_demand) | ||
%td{ 'ng-show' => 'columns.on_demand.visible' } | ||
%input.field{ 'ng-model' => 'variant.on_demand', :name => 'variant_on_demand', 'ofn-track-variant' => 'on_demand', :type => 'checkbox' } | ||
%td{ 'ng-show' => 'columns.category.visible' } | ||
|
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.
can we add some blank lines in between? It's feel like a wall 😱
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.
I have added some line breaks... I dont want to change this logic but it sure is calling for some improvement...
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.
not changing logic but a bit of spacing would ease the reading...
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.
Ive added some spaces, I am not sure if you are ok with it now or if you are asking for more spaces? :-D