-
-
Notifications
You must be signed in to change notification settings - Fork 725
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
Refactor uses of spree_variants.count_on_hand #2014
Comments
|
unless suppliers_to_reset_inventories.empty? | |
@products_reset_count += VariantOverride. | |
where('variant_overrides.hub_id IN (?) | |
AND variant_overrides.id NOT IN (?)', suppliers_to_reset_inventories, @updated_ids). | |
update_all(count_on_hand: 0) | |
end |
VariantOverride
which is not affected by the Spree upgrade.openfoodnetwork/app/models/product_import/entry_processor.rb
Lines 196 to 198 in eb9064f
if object.send(attribute).blank? || ((attribute == 'on_hand' || attribute == 'count_on_hand') && entry.on_hand_nil) | |
object.assign_attributes(attribute => setting['value']) | |
end |
assign_attributes
will send on_hand=
to the object which should work once we implemented the old API in [Spree 2 Upgrade] Restore Variant.on_hand
methods #2575.openfoodnetwork/app/models/product_import/entry_validator.rb
Lines 265 to 271 in eb9064f
def check_on_hand_nil(entry, object) | |
return if entry.on_hand.present? | |
object.on_hand = 0 if object.respond_to?(:on_hand) | |
object.count_on_hand = 0 if object.respond_to?(:count_on_hand) | |
entry.on_hand_nil = true | |
end |
Variant.on_hand
methods #2575Code calling method count_on_hand
- Proposal in [WIP] Import count_on_hand methods for Spree 2 #2417
attributes :id, :is_master, :count_on_hand, :name_to_display, :unit_to_display, :unit_value - Proposal in [WIP] Import count_on_hand methods for Spree 2 #2417
li[:quantity] = stock_limited_quantity(variant.count_on_hand, li[:quantity]) - Proposal in [WIP] Import count_on_hand methods for Spree 2 #2417
%shop-variant{variant: 'variant', "ng-repeat" => "variant in product.variants | orderBy: ['name_to_display','unit_value'] track by variant.id", "id" => "variant-{{ variant.id }}", "ng-class" => "{'out-of-stock': !variant.on_demand && variant.count_on_hand == 0}"} - Proposal in [WIP] Import count_on_hand methods for Spree 2 #2417
<li class='variant-on_hand'><strong>{{t 'on_hand'}}:</strong> {{variant.count_on_hand}}</li> - Proposal in [WIP] Import count_on_hand methods for Spree 2 #2417
attributes :sku, :options_text, :count_on_hand, :id, :cost_price
Code using count_on_hand
in SQL
- 2014 refactor variant count on hand #2413
variants.where('spree_variants.count_on_hand > 0')
Code calling decrement!
or increment!
openfoodnetwork/lib/open_food_network/scope_variant_to_hub.rb
Lines 43 to 47 in eb9064f
if attribute == :count_on_hand && @variant_override.andand.stock_overridden? @variant_override.decrement_stock! by else super end VariantOverride
, notSpree::Variant
.openfoodnetwork/lib/open_food_network/scope_variant_to_hub.rb
Lines 51 to 55 in eb9064f
if attribute == :count_on_hand && @variant_override.andand.stock_overridden? @variant_override.increment_stock! by else super end VariantOverride
, notSpree::Variant
.
Other code
-
this call is to VariantOverride and still valid@variant_override.andand.count_on_hand || super - Lots of specs
After reviewing all uses again, I found that #2575 is the only issue left to do. That should solve all listed issues. Closing this one. |
VariantOverride
is particularly coupled to this column, but we should be able to override the newvariant.total_on_hand
method instead ofvariant.count_on_hand
to achieve the same result. This is a bandaid solution but a longer term solution to this issue will likely appear out of Networked Products discussions.The text was updated successfully, but these errors were encountered: