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

Delete dead feature product distributions #3570

Merged

Conversation

luisramos0
Copy link
Contributor

@luisramos0 luisramos0 commented Mar 3, 2019

What? Why?

Closes #3525
I think this is the perfect timing to do this, just before we get to v2.

Product Distributions were an alternative way to get products into the shop list and into the orders. Order Cycle is now mandatory for an order to go through the cart phase.

What should we test?

We need to carefully validate these areas of the app:

  • create product
  • bulk product edit page - changing product and variants details
  • product edit page
    • there should be no product distributions sub menu now and all other sub menus should work normally
  • not directly related to this PR but a question was raised about recalculating enterprise fees on orders where the products were removed from the order cycle: 1. create an order with OC fees in an OC, 2. remove product from OC, 3. edit order and recalculate fees.
  • same as above but for closed order cycles: 1. create order with OC fees, 2. close the OC, 3- edit order and recalculate fees.
  • reports that were slightly changed (removed the product distributions part of the queries) and should work correctly:
    • order_cycle_management, packing, sales_tax, bulk_coop, payments, xero_invoices, customers and products_and_inventory
  • enterprise fees
    • add fee to order cycle and see the correct adjustment in the order
  • shop front list of products with correct enterprise fees
  • add variant to cart and checkout
    • we must test the case where user selects one distributor and order cycle, adds products to cart and then changes to another order cycle or distributor, checkout should still work

In the add to cart stage, there's this scenario where user adds a variant to the cart and then changes to another order cycle where this same variant is also available, from the code it seems this was possible in the past, I am not sure if this a valid user case right now. maybe we should check and decide.

Release notes

Changelog Category: Removed
Remove a feature that was not working: Product Distributions, the predecessor of order cycles.

How is this related to the Spree upgrade?

It's not related.

Dependencies

There will be a conflict with #3569.

@luisramos0 luisramos0 self-assigned this Mar 3, 2019
@luisramos0 luisramos0 force-pushed the byebye-prod-distributions branch 12 times, most recently from d1efe7e to 2149937 Compare March 3, 2019 16:08
@luisramos0 luisramos0 changed the title WIP Delete dead feature product distributions Delete dead feature product distributions Mar 3, 2019
@luisramos0 luisramos0 removed the pr-wip label Mar 3, 2019
@luisramos0 luisramos0 force-pushed the byebye-prod-distributions branch from 2149937 to 9f0a609 Compare March 3, 2019 22:47
Copy link
Contributor

@sauloperez sauloperez left a comment

Choose a reason for hiding this comment

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

This is massive @luisramos0 !! IMO is worth digging deeper on the test cases that must be tested. At least, the particular actions and methods that were refactored.

@sauloperez
Copy link
Contributor

sauloperez commented Mar 4, 2019

Have we checked if there any recently created product_distributions in production servers? in OFF I get

openfoodnetwork=> select * from product_distributions order by id desc limit 1;
 id | product_id | distributor_id |         created_at         |         updated_at         | enterprise_fee_id 
----+------------+----------------+----------------------------+----------------------------+-------------------
 44 |       4390 |            572 | 2019-02-07 10:19:57.291831 | 2019-02-07 10:19:57.291831 |                95

While from Katuma I get

 id | product_id | distributor_id |         created_at         |         updated_at         | enterprise_fee_id 
----+------------+----------------+----------------------------+----------------------------+-------------------
  5 |       1008 |            152 | 2019-01-29 17:14:23.109552 | 2019-01-29 17:14:23.109552 |                25

It could as well be that the feature is not really used by we still create these from callbacks without us noticing. Perhaps the client-side is still populating it through accepts_nested_attributes_for :product_distributions?

@luisramos0 luisramos0 force-pushed the byebye-prod-distributions branch 2 times, most recently from c99e20f to 85aef52 Compare March 4, 2019 16:03
@luisramos0
Copy link
Contributor Author

luisramos0 commented Mar 4, 2019

In terms of usage, I dont see any other explanation other than: users are using the product distributions page and selecting enterprises thinking it works, in some way.
The numbers in the databases are:
354 rows in UK, some entries from Oct 2018 from one single distributor id 200270.
173 entries in AUS, one entry from Nov 2018 and others before Mars 2018.
44 entries in FR, some recent entries from a specific user.

I think these are all entries created by users that think the page works. I am also saying this because I was one of theses users during a demo in Portugal... later on, looking at the code, I realized the page is useless...

@sauloperez
Copy link
Contributor

That would be a feasible explanation. Just out of curiosity I'd check with Matomo what that user did in FR although we know the actions were useless.

@luisramos0 luisramos0 force-pushed the byebye-prod-distributions branch from 37695e8 to e59d5b5 Compare March 6, 2019 16:08
@luisramos0
Copy link
Contributor Author

I resolved conflicts and improved the "what to test" description as suggested by @sauloperez

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.

This is such good work. Well done! It should speed up our tests and prevents us from wasting time with dead code. I got a couple of questions but I'm otherwise very happy with this. It will need some really thorough testing though.

Oh, and we should query all affected enterprises so that we can ask them if they are using it (and why).

@@ -218,10 +218,6 @@ def update_distribution_charge!
line_items.each do |line_item|
if provided_by_order_cycle? line_item
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if this method can go as well. Without product distributions, all items of an order should be in the order cycle of that order, right?

What else could happen? A product can be removed from an order cycle after it has been ordered. Would that cause any problem? Could it be that they disappear from a report?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I think that is one case in which this is protecting against. Products removed from OCs.

I am not sure how the system behaves in terms of modifying orders with products that are no longer in the order cycle, or even modifying orders where the OC is already closed...
I'll add that to the test scenarios of this PR.

@@ -0,0 +1,37 @@
class DropProductDistributions < ActiveRecord::Migration
def up
drop_table :product_distributions
Copy link
Member

Choose a reason for hiding this comment

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

Did you run this against production data? Is there any dependent data destroyed?

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 tried it now, it just works.

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 tried with AUS data.

@luisramos0
Copy link
Contributor Author

In terms of enterprises, in AUS live data there's only one enterprise using it and the entries are from 2013, I think we will be ok :-)
In UK and FR there are more recent entries.

  • there are 15 enterprises in the UK. I have the list of enterprises and emails. @lin-d-hop would you be the right person to contact the users asking them if/why they use product distributions and alerting them it will be deleted from the system?
  • in FR we have 11 enterprises, @RachL would you want to do this communication?
  • in Katuma, there are 4 enterprises but only one of the enterprises with orders

@RachL
Copy link
Contributor

RachL commented Mar 8, 2019

@luisramos0 yes. Do you have the list?

@luisramos0
Copy link
Contributor Author

yes, just sent you on slack.

@luisramos0 luisramos0 force-pushed the byebye-prod-distributions branch from 2751044 to 786ba15 Compare March 13, 2019 12:24
@luisramos0
Copy link
Contributor Author

rebased, build green, ready for testing!

luisramos0 added a commit to luisramos0/openfoodnetwork that referenced this pull request Mar 18, 2019
We ignore product distributions as it will be deleted soon (see openfoodfoundation#3570) and we do not include stock management from v2 as we will only use the variants edit page to manage on_hand and on_demand
@RachL RachL added the pr-staged-uk staging.openfoodnetwork.org.uk label Mar 18, 2019
@RachL RachL self-assigned this Mar 18, 2019
@RachL
Copy link
Contributor

RachL commented Mar 18, 2019

@luisramos0 I've tested all the cases. It seems to me that enterprise fees are not working. Now please take into account that I'm kind of a fee newbie. I've asked Myriam for some detailed test cases but she didn't had the time to write them so far. So I'm sorry but we will have to look at this step by step :(
Note that so far I've only played with the "Flat percent" Calculator. However I've tried packing / transport / admin type of fees. I know that packing and transport should appear in the OC, while admin fees are only added at checkout. I've checked that I've added them both on incoming and outgoing... but still I could only see fees linked to payment method....

Do you see a step missing in my tests?

add variant to cart and checkout
we must test the case where user selects one distributor and order cycle, adds products to cart and then changes to another order cycle or distributor, checkout should still work

Also FYI I've added screenshots in my notes for this. The UI does not allow a user to shop from different shops or from different OC. Meaning 1 order = 1 OC = 1 distributor. It's a bit a pity if you think about it, but this can be dealt with as wishlist items. So you can 🔥 anything related to a different behaviour in the code.

Testing notes: https://docs.google.com/document/d/1m_nmQU4Xki5xlHAGeOf-gdbVqIMsTNLpkOT4Ual1zc8/edit#

@luisramos0
Copy link
Contributor Author

Can you be a bit more specific in terms of fees not working?
I just went to uk staging, opened your test OC "manana in Rachel fee report test", added your test admin Fee to outgoing and I can see the prices changing in the shop front...

re 1 order = 1 OC = 1 distributor
👍

@luisramos0
Copy link
Contributor Author

luisramos0 commented Mar 18, 2019

In terms of calculators, one important part is that "per order" fees are only seen in cart and checkout, not in the product list.

re " I know that packing and transport should appear in the OC, while admin fees are only added at checkout."
I scanned the code quickly to see how the different types of fees work (admin, transport, etc)...
I dont see any logic applied to these, are you sure about your statement?

and thanks a lot for testing this 🎉

@RachL
Copy link
Contributor

RachL commented Mar 19, 2019

@luisramos0

I scanned the code quickly to see how the different types of fees work (admin, transport, etc)...
I dont see any logic applied to these, are you sure about your statement?

Not at all. I saw this in an old testing scenario, but I can't find the PR, so let's say I was totally wrong on this.

Can you be a bit more specific in terms of fees not working? I just went to uk staging, opened your test OC "manana in Rachel fee report test", added your test admin Fee to outgoing and I can see the prices changing in the shop front...

😊 Could this be I forgot to add them in outgoing? 😱 If it is I'm deeply sorry.

However my fee is a flat percent per item set at 50. So in this following screenshot I should see an amount of 1.5 not 2, right?

image

@luisramos0
Copy link
Contributor Author

you have the fee in both incoming and outgoing, that's 50% + 50%, right ?

@RachL
Copy link
Contributor

RachL commented Mar 19, 2019

@luisramos0 yes I just saw that. Nevermind, coffee was slow to kick in on this one. Ahem. I'm re-checking all of this right now.

@RachL
Copy link
Contributor

RachL commented Mar 19, 2019

Alright, I've combined all possible calculators. I didn't see something weird. So I think we are good to go! I've updated the notes.

@RachL RachL removed the pr-staged-uk staging.openfoodnetwork.org.uk label Mar 19, 2019
@luisramos0
Copy link
Contributor Author

great, thanks a lot @RachL :-D

@sauloperez sauloperez merged commit 2a3a935 into openfoodfoundation:master Mar 20, 2019
@luisramos0 luisramos0 deleted the byebye-prod-distributions branch March 20, 2019 12:00
luisramos0 pushed a commit to luisramos0/openfoodnetwork that referenced this pull request Mar 21, 2019
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.

Remove Product Distributions
5 participants