Skip to content
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

Conversation

luisramos0
Copy link
Contributor

@luisramos0 luisramos0 commented Feb 18, 2019

What? Why?

In this PR I am proposing replacing all calls to variant.count_on_hand with variant.on_hand.

I dont think we should make major refactoring work now before we go live with v2, but this one was clearly needed to keep variant stock management at acceptable levels of complexity :-)

The only two changes required were:

  • variant.on_hand will not return infinity if variant is on_demand, this required to adapt some code in the cart and the bulk product update page
  • product import will only take on_hand, no count_on_hand

I recommend the review per commit because one of the commits is a find/replace exercise.

What should we test?

Build should be green.
I think this is the right time to put this PR in as we will be able to validate the full v2 version very soon.

variant.on_hand will not return infinity any longer if variant.on_demand is true. Clients of these methods will have to handle the combinations between on_hand and on_demand values
…ed on the server side, the UI can make the decision to show on_demand on the on_hand column if on_demand is true
@luisramos0 luisramos0 self-assigned this Feb 18, 2019
@luisramos0 luisramos0 changed the title WIP 2 0 remove variant count on hand [Spree Upgrade] Remove variant.count_on_hand (keep variant.on_hand only) Feb 18, 2019
@luisramos0 luisramos0 removed the pr-wip label Feb 18, 2019
@luisramos0 luisramos0 force-pushed the 2-0-remove-variant-count-on-hand branch from f78dd21 to ffbe790 Compare February 18, 2019 23:39
@@ -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' }
Copy link
Contributor

Choose a reason for hiding this comment

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

why is the ng-bind not needed now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

scope.variants.push li.variant
if li.variant.on_hand == 0 && li.max_quantity > li.variant.on_hand
li.max_quantity = li.variant.on_hand
scope.variants.push(li.variant) unless li.variant in scope.variants
Copy link
Contributor

@sauloperez sauloperez Feb 19, 2019

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 😱

Copy link
Contributor Author

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...

Copy link
Contributor

@sauloperez sauloperez Feb 22, 2019

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...

Copy link
Contributor Author

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

@luisramos0 luisramos0 force-pushed the 2-0-remove-variant-count-on-hand branch from ffbe790 to 8ee14cc Compare February 19, 2019 11:56
#
# @return [Float|Integer]
def on_hand
warn_deprecation(__method__, '#total_on_hand')

if on_demand
Float::INFINITY
Copy link
Member

Choose a reason for hiding this comment

The 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 9999 value in the cart logic is just a workaround for not dealing with infinity properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is a step forward Maikel. I will explain.
Returning Infinity is poor, it's magic, the client should get specific on_hand and on_demand values all the time and the client should decide what to do, no magic.

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

Copy link
Contributor Author

@luisramos0 luisramos0 Feb 22, 2019

Choose a reason for hiding this comment

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

"The 9999 value in the cart logic is just a workaround"

I am not too worried with client side code here (although I have tested it and it works), we can improve it later.
Here we are changing OFN core behaviour, and I think that it is important to be very clear and simple, i.e., not mixing on_hand and on_demand in the core. Leaving that up to the client.

Copy link
Member

Choose a reason for hiding this comment

The 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:

  • How many can I order? Infinity is right here.
  • How many are in stock? That's a finite number of the stock item.

And on_hand sounds a bit more like the answer to the second question.

Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

There are some conflicts that need to be resolved but otherwise I'm happy now. 👍

@luisramos0
Copy link
Contributor Author

Conflicts resolved.

@mkllnk mkllnk merged commit 65ba932 into openfoodfoundation:2-0-stable Feb 27, 2019
@luisramos0 luisramos0 deleted the 2-0-remove-variant-count-on-hand branch February 27, 2019 22:15
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.

3 participants