From 6f3663f1b960799afcf7f250ac88e3bb66c614f3 Mon Sep 17 00:00:00 2001 From: Hugo Daniel Date: Wed, 11 Apr 2018 16:56:08 +0200 Subject: [PATCH 01/42] update gemfile to spree 2.0.13 --- Gemfile | 16 ++-- Gemfile.lock | 242 +++++++++++++++++++++++++-------------------------- 2 files changed, 127 insertions(+), 131 deletions(-) diff --git a/Gemfile b/Gemfile index 0e2d21d89c6..feb780db3be 100644 --- a/Gemfile +++ b/Gemfile @@ -11,17 +11,17 @@ gem 'i18n-js', '~> 3.0.0' gem 'nokogiri', '>= 1.6.7.1' gem 'pg' -gem 'spree', github: 'openfoodfoundation/spree', branch: 'step-6a', ref: '86bf87f1b1e1b299edc8cd10a2486e44ba0a3987' +gem 'spree', '2.0.13' gem 'spree_i18n', github: 'spree/spree_i18n', branch: '1-3-stable' -gem 'spree_auth_devise', github: 'openfoodfoundation/spree_auth_devise', branch: 'spree-upgrade-intermediate' +gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-0-stable' # Our branch contains two changes # - Pass customer email and phone number to PayPal (merged to upstream master) # - Change type of password from string to password to hide it in the form -gem 'spree_paypal_express', github: "openfoodfoundation/better_spree_paypal_express", branch: "spree-upgrade-intermediate" -#gem 'spree_paypal_express', github: "spree-contrib/better_spree_paypal_express", branch: "1-3-stable" +# gem 'spree_paypal_express' +gem 'spree_paypal_express', github: "spree-contrib/better_spree_paypal_express", branch: "2-0-stable" gem 'stripe', '~> 3.3.1' -gem 'activemerchant', '~> 1.71.0' +gem 'activemerchant' gem 'oauth2', '~> 1.2.0' # Used for Stripe Connect gem 'jwt', '~> 1.5' @@ -49,8 +49,8 @@ gem 'representative_view' gem 'rabl' gem "active_model_serializers" gem 'oj' -gem 'deface', github: 'spree/deface', ref: '1110a13' -gem 'paperclip' +gem 'deface', '1.0.0' +gem 'paperclip', '~> 3.4.1' gem 'dalli' gem 'geocoder' gem 'gmaps4rails' @@ -95,7 +95,7 @@ end gem "foundation-rails" gem 'foundation_rails_helper', github: 'willrjmarshall/foundation_rails_helper', branch: "rails3" -gem 'jquery-rails' +gem 'jquery-rails', '3.0.0' gem 'jquery-migrate-rails' gem 'css_splitter' diff --git a/Gemfile.lock b/Gemfile.lock index 44197d99a47..6dbbd9439fe 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,15 +12,6 @@ GIT specs: custom_error_message (1.1.1) -GIT - remote: https://github.com/openfoodfoundation/better_spree_paypal_express.git - revision: 8d95f4544c682634812becaf50999fba0cd04df0 - branch: spree-upgrade-intermediate - specs: - spree_paypal_express (2.0.3) - paypal-sdk-merchant (= 1.106.1) - spree_core (~> 1.3.99) - GIT remote: https://github.com/openfoodfoundation/ofn-qz.git revision: 60da2ae4c44cbb4c8d602f59fb5fff8d0f21db3c @@ -30,88 +21,25 @@ GIT railties (~> 3.1) GIT - remote: https://github.com/openfoodfoundation/spree.git - revision: 86bf87f1b1e1b299edc8cd10a2486e44ba0a3987 - ref: 86bf87f1b1e1b299edc8cd10a2486e44ba0a3987 - branch: step-6a + remote: https://github.com/spree-contrib/better_spree_paypal_express.git + revision: 1206925d1c85bdc4b68b728d6676150ab0785486 + branch: 2-0-stable specs: - spree (1.3.99) - spree_api (= 1.3.99) - spree_backend (= 1.3.99) - spree_cmd (= 1.3.99) - spree_core (= 1.3.99) - spree_dash (= 1.3.99) - spree_frontend (= 1.3.99) - spree_sample (= 1.3.99) - spree_api (1.3.99) - rabl (= 0.7.2) - spree_core (= 1.3.99) - versioncake (= 0.4.0) - spree_backend (1.3.99) - deface (>= 0.9.0) - jquery-rails (~> 2.0) - rails (~> 3.2.8) - select2-rails (~> 3.2) - spree_api (= 1.3.99) - spree_core (= 1.3.99) - stringex (~> 1.3.2) - spree_cmd (1.3.99) - thor (>= 0.14.6) - spree_core (1.3.99) - activemerchant (~> 1.50) - acts_as_list (= 0.1.9) - awesome_nested_set (= 2.1.5) - aws-sdk (~> 1.11.1) - cancan (= 1.6.8) - deface (>= 0.9.0) - ffaker (~> 1.15.0) - highline (= 1.6.15) - httparty (= 0.9.0) - json (>= 1.5.5) - kaminari (= 0.13.0) - money (= 5.1.0) - paperclip (~> 3.0) - rails (~> 3.2.13) - ransack (= 0.7.2) - state_machine (= 1.2.0) - stringex (~> 1.3.2) - truncate_html (= 0.9.2) - spree_dash (1.3.99) - httparty (~> 0.9.0) - spree_backend (= 1.3.99) - spree_frontend (= 1.3.99) - spree_frontend (1.3.99) - deface (>= 0.9.0) - jquery-rails (~> 2.2.1) - rails (~> 3.2.8) - select2-rails (~> 3.2) - spree_api (= 1.3.99) - spree_core (= 1.3.99) - stringex (~> 1.3.2) - spree_sample (1.3.99) - spree_core (= 1.3.99) + spree_paypal_express (2.0.3) + paypal-sdk-merchant (= 1.106.1) + spree_core (~> 2.0.3) GIT - remote: https://github.com/openfoodfoundation/spree_auth_devise.git - revision: da9eecefc6fe13dedf4c6f3febec79caad839ec3 - branch: spree-upgrade-intermediate + remote: https://github.com/spree/spree_auth_devise.git + revision: 0181835fb6ac77a05191d26f6f32a0f4a548d851 + branch: 2-0-stable specs: spree_auth_devise (2.0.0) devise (~> 2.2.5) devise-encryptable (= 0.1.2) - spree_backend (~> 1.3.6) - spree_core (~> 1.3.6) - spree_frontend (~> 1.3.6) - -GIT - remote: https://github.com/spree/deface.git - revision: 1110a1336252109bce7f98f9182042e0bc2930ae - ref: 1110a13 - specs: - deface (1.0.0.rc3) - colorize (>= 0.5.8) - nokogiri (~> 1.6.0) - rails (>= 3.1) + spree_backend (~> 2.0.0) + spree_core (~> 2.0.0) + spree_frontend (~> 2.0.0) GIT remote: https://github.com/spree/spree_i18n.git @@ -152,10 +80,16 @@ GEM sprockets (~> 2.2.1) active_model_serializers (0.8.3) activemodel (>= 3.0) - activemerchant (1.71.0) - activesupport (>= 3.2.14, < 6.x) + active_utils (2.2.3) + activesupport (>= 2.3.11) + i18n + activemerchant (1.43.3) + active_utils (~> 2.0, >= 2.0.1) + activesupport (>= 2.3.14, < 5.0.0) builder (>= 2.1.2, < 4.0.0) - i18n (>= 0.6.9) + i18n (~> 0.5) + json (~> 1.7) + money (< 7.0.0) nokogiri (~> 1.4) activemodel (3.2.21) activesupport (= 3.2.21) @@ -173,7 +107,8 @@ GEM multi_json (~> 1.0) acts-as-taggable-on (3.5.0) activerecord (>= 3.2, < 5) - acts_as_list (0.1.9) + acts_as_list (0.3.0) + activerecord (>= 3.0) addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) andand (1.3.3) @@ -186,10 +121,10 @@ GEM arel (3.0.3) ast (2.3.0) atomic (1.1.99) - awesome_nested_set (2.1.5) + awesome_nested_set (2.1.6) activerecord (>= 3.0.0) awesome_print (1.0.2) - aws-sdk (1.11.1) + aws-sdk (1.31.3) json (~> 1.4) nokogiri (>= 1.4.4) uuidtools (~> 2.1) @@ -200,7 +135,9 @@ GEM bugsnag (4.1.0) builder (3.0.4) byebug (9.0.6) - cancan (1.6.8) + cancan (1.6.10) + canonical-rails (0.1.0) + rails (>= 3.1, < 5.1) capybara (2.18.0) addressable mini_mime (>= 0.1.3) @@ -210,7 +147,7 @@ GEM xpath (>= 2.0, < 4.0) chronic (0.10.2) chunky_png (1.3.4) - climate_control (0.1.0) + climate_control (0.2.0) cliver (0.3.2) cocaine (0.5.8) climate_control (>= 0.0.3, < 1.0) @@ -253,6 +190,10 @@ GEM fog (~> 1.0) rails (~> 3.0) debugger-linecache (1.2.0) + deface (1.0.0) + colorize (>= 0.5.8) + nokogiri (~> 1.6.0) + rails (>= 3.1) delayed_job (4.1.4) activesupport (>= 3.0, < 5.2) delayed_job_active_record (4.1.2) @@ -281,7 +222,7 @@ GEM railties (>= 3.0.0) faraday (0.9.2) multipart-post (>= 1.2, < 3) - ffaker (1.15.0) + ffaker (1.22.1) ffi (1.9.18) figaro (0.7.0) bundler (~> 1.0) @@ -432,12 +373,11 @@ GEM rspec (>= 2.99.0, < 4.0) haml (4.0.4) tilt - highline (1.6.15) + highline (1.6.21) hike (1.2.3) http_parser.rb (0.6.0) - httparty (0.9.0) - multi_json (~> 1.0) - multi_xml + httparty (0.16.2) + multi_xml (>= 0.5.2) i18n (0.6.11) i18n-js (3.0.0) i18n (~> 0.6, >= 0.6.6) @@ -448,18 +388,19 @@ GEM ipaddress (0.8.0) journey (1.0.4) jquery-migrate-rails (1.2.1) - jquery-rails (2.2.2) + jquery-rails (3.0.0) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) + jquery-ui-rails (4.0.5) + railties (>= 3.1.0) json (1.8.6) json_spec (1.1.5) multi_json (~> 1.0) rspec (>= 2.0, < 4.0) jwt (1.5.4) - kaminari (0.13.0) + kaminari (0.15.1) actionpack (>= 3.0.0) activesupport (>= 3.0.0) - railties (>= 3.0.0) kgio (2.9.3) knapsack (1.16.0) rake @@ -481,8 +422,10 @@ GEM mini_portile2 (2.1.0) momentjs-rails (2.5.1) railties (>= 3.1) - money (5.1.0) - i18n (~> 0.6.0) + monetize (1.7.0) + money (~> 6.9) + money (6.11.0) + i18n (>= 0.6.4, < 1.1) multi_json (1.12.1) multi_xml (0.6.0) multipart-post (2.0.0) @@ -504,14 +447,17 @@ GEM paper_trail (3.0.8) activerecord (>= 3.0, < 5.0) activesupport (>= 3.0, < 5.0) - paperclip (3.5.4) + paperclip (3.4.2) activemodel (>= 3.0.0) + activerecord (>= 3.0.0) activesupport (>= 3.0.0) - cocaine (~> 0.5.3) + cocaine (~> 0.5.0) mime-types parallel (1.11.2) parallel_tests (2.14.1) parallel + paranoia (1.3.4) + activerecord (~> 3.1) parser (2.4.0.0) ast (~> 2.2) paypal-sdk-core (0.2.10) @@ -524,8 +470,8 @@ GEM capybara (~> 2.1) cliver (~> 0.3.1) websocket-driver (>= 0.2.0) - polyamorous (0.5.0) - activerecord (~> 3.0) + polyamorous (0.6.4) + activerecord (>= 3.0) polyglot (0.3.5) powerpack (0.1.1) pry (0.11.2) @@ -535,9 +481,8 @@ GEM byebug (>= 9.0, < 9.1) pry (~> 0.10) public_suffix (3.0.0) - rabl (0.7.2) + rabl (0.9.3) activesupport (>= 2.3.14) - multi_json (~> 1.0) rack (1.4.7) rack-cache (1.7.0) rack (>= 0.4) @@ -569,10 +514,10 @@ GEM rake raindrops (0.13.0) rake (10.5.0) - ransack (0.7.2) - actionpack (~> 3.0) - activerecord (~> 3.0) - polyamorous (~> 0.5.0) + ransack (1.1.0) + actionpack (>= 3.0) + activerecord (>= 3.0) + polyamorous (~> 0.6.0) rb-fsevent (0.10.2) rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) @@ -635,7 +580,8 @@ GEM railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) - select2-rails (3.5.10) + select2-rails (3.4.9) + sass-rails thor (~> 0.14) shellany (0.0.1) shoulda-matchers (2.8.0) @@ -644,13 +590,62 @@ GEM activesupport (>= 3.0.0) spinjs-rails (1.3) rails (>= 3.1) + spree (2.0.13) + spree_api (= 2.0.13) + spree_backend (= 2.0.13) + spree_cmd (= 2.0.13) + spree_core (= 2.0.13) + spree_frontend (= 2.0.13) + spree_sample (= 2.0.13) + spree_api (2.0.13) + rabl (= 0.9.3) + spree_core (= 2.0.13) + versioncake (~> 1.2.0) + spree_backend (2.0.13) + jquery-rails (~> 3.0.0) + jquery-ui-rails (~> 4.0.0) + select2-rails (~> 3.4.7) + spree_api (= 2.0.13) + spree_core (= 2.0.13) + spree_cmd (2.0.13) + thor (~> 0.14) + spree_core (2.0.13) + activemerchant (~> 1.43.1) + acts_as_list (= 0.3.0) + awesome_nested_set (= 2.1.6) + aws-sdk (= 1.31.3) + cancan (~> 1.6.10) + deface (= 1.0.0) + ffaker (~> 1.22.0) + highline (~> 1.6.18) + httparty (~> 0.11) + json (~> 1.7) + kaminari (~> 0.15.0) + monetize + paperclip (~> 3.4.1) + paranoia (~> 1.3) + rails (~> 3.2.21) + ransack (~> 1.1.0) + state_machine (= 1.2.0) + stringex (~> 1.5.1) + truncate_html (= 0.9.2) + spree_frontend (2.0.13) + canonical-rails + deface (>= 0.9.0) + jquery-rails (~> 3.0.0) + rails (~> 3.2.13) + spree_api (= 2.0.13) + spree_core (= 2.0.13) + stringex (~> 1.5.1) + spree_sample (2.0.13) + spree_core (= 2.0.13) sprockets (2.2.3) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) state_machine (1.2.0) - stringex (1.3.3) + stringex (1.5.1) stripe (3.3.1) faraday (~> 0.9) therubyracer (0.12.0) @@ -679,10 +674,11 @@ GEM rack unicorn uuidtools (2.1.5) - versioncake (0.4.0) - actionpack (>= 3.0) - activesupport (>= 3.0) - railties (>= 3.0) + versioncake (1.2.0) + actionpack (>= 3.2) + activesupport (>= 3.2) + railties (>= 3.2) + tzinfo warden (1.2.7) rack (>= 1.0) webmock (1.8.11) @@ -705,7 +701,7 @@ PLATFORMS DEPENDENCIES active_model_serializers - activemerchant (~> 1.71.0) + activemerchant acts-as-taggable-on (~> 3.4) andand angular-rails-templates (~> 0.2.0) @@ -727,7 +723,7 @@ DEPENDENCIES database_cleaner (= 0.7.1) db2fog debugger-linecache - deface! + deface (= 1.0.0) delayed_job_active_record diffy eventmachine (>= 1.2.3) @@ -749,7 +745,7 @@ DEPENDENCIES i18n-js (~> 3.0.0) immigrant jquery-migrate-rails - jquery-rails + jquery-rails (= 3.0.0) json_spec (~> 1.1.4) jwt (~> 1.5) knapsack @@ -762,7 +758,7 @@ DEPENDENCIES ofn-qz! oj paper_trail (~> 3.0.8) - paperclip + paperclip (~> 3.4.1) parallel_tests pg poltergeist (>= 1.16.0) @@ -785,7 +781,7 @@ DEPENDENCIES simple_form! skylight (< 2.0) spinjs-rails - spree! + spree (= 2.0.13) spree_auth_devise! spree_i18n! spree_paypal_express! From e6b58c6db427d9746c1763e4b697b5360a0ce0fc Mon Sep 17 00:00:00 2001 From: Hugo Daniel Date: Thu, 12 Apr 2018 15:09:16 +0200 Subject: [PATCH 02/42] Remove ssl deprecated configuration --- config/initializers/spree.rb | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/config/initializers/spree.rb b/config/initializers/spree.rb index 9b62e3ad6e3..8495ec38241 100644 --- a/config/initializers/spree.rb +++ b/config/initializers/spree.rb @@ -27,14 +27,3 @@ # unless the empty module is explicity 'registered' here. Something to do with autoloading? module OpenFoodNetwork end - -# Forcing spree to always allow SSL connections -# Since we are using config.force_ssl = true -# Without this we get a redirect loop: see https://groups.google.com/forum/#!topic/spree-user/NwpqGxJ4klk -SslRequirement.module_eval do - protected - - def ssl_allowed? - true - end -end From abe5d3596c84e294f2814ac6672da4664fb3f197 Mon Sep 17 00:00:00 2001 From: Hugo Daniel Date: Thu, 12 Apr 2018 19:29:09 +0200 Subject: [PATCH 03/42] Refactor Order#current_order argument --- app/controllers/base_controller.rb | 2 +- app/controllers/enterprises_controller.rb | 4 ++-- app/controllers/shop_controller.rb | 2 +- app/controllers/spree/orders_controller_decorator.rb | 8 ++++---- app/helpers/enterprises_helper.rb | 2 +- app/helpers/order_cycles_helper.rb | 2 +- app/helpers/shared_helper.rb | 2 +- app/helpers/spree/orders_helper.rb | 2 +- app/services/reset_order_service.rb | 2 +- app/views/spree/products/_add_to_cart.html.haml | 2 +- .../spree/products/_distributor_details.html.haml | 2 +- app/views/spree/products/_source.html.haml | 2 +- lib/spree/core/controller_helpers/order_decorator.rb | 4 ++-- spec/controllers/checkout_controller_spec.rb | 2 +- spec/controllers/enterprises_controller_spec.rb | 2 +- spec/controllers/spree/checkout_controller_spec.rb | 2 +- spec/controllers/spree/orders_controller_spec.rb | 10 +++++----- spec/controllers/spree/paypal_controller_spec.rb | 2 +- spec/performance/orders_controller_spec.rb | 2 +- 19 files changed, 28 insertions(+), 28 deletions(-) diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index 36bf72fd9c1..18bc679fbed 100644 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -37,7 +37,7 @@ def set_order_cycles # And default to the only order cycle if there's only the one if @order_cycles.count == 1 - current_order(true).set_order_cycle! @order_cycles.first + current_order({ create_order_if_necessary: true }).set_order_cycle! @order_cycles.first end end end diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb index 2b2a639b87e..88621ec53c7 100644 --- a/app/controllers/enterprises_controller.rb +++ b/app/controllers/enterprises_controller.rb @@ -49,14 +49,14 @@ def clean_permalink end def check_stock_levels - if current_order(true).insufficient_stock_lines.present? + if current_order({ create_order_if_necessary: true }).insufficient_stock_lines.present? redirect_to spree.cart_path end end def reset_order distributor = Enterprise.is_distributor.find_by_permalink(params[:id]) || Enterprise.is_distributor.find(params[:id]) - order = current_order(true) + order = current_order({ create_order_if_necessary: true }) reset_distributor(order, distributor) diff --git a/app/controllers/shop_controller.rb b/app/controllers/shop_controller.rb index a32d5d0b855..b9136c01bbd 100644 --- a/app/controllers/shop_controller.rb +++ b/app/controllers/shop_controller.rb @@ -26,7 +26,7 @@ def products def order_cycle if request.post? if oc = OrderCycle.with_distributor(@distributor).active.find_by_id(params[:order_cycle_id]) - current_order(true).set_order_cycle! oc + current_order({ create_order_if_necessary: true }).set_order_cycle! oc render partial: "json/order_cycle" else render status: 404, json: "" diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb index 47425bcbf2c..9d22a33b64c 100644 --- a/app/controllers/spree/orders_controller_decorator.rb +++ b/app/controllers/spree/orders_controller_decorator.rb @@ -18,7 +18,7 @@ # Patching to redirect to shop if order is empty def edit - @order = current_order(true) + @order = current_order({ create_order_if_necessary: true }) @insufficient_stock_lines = @order.insufficient_stock_lines if @order.line_items.empty? @@ -78,7 +78,7 @@ def populate # callbacks on Spree::Adjustment and then manually invoke Spree::Order#update! on success. Spree::Adjustment.without_callbacks do - populator = Spree::OrderPopulator.new(current_order(true), current_currency) + populator = Spree::OrderPopulator.new(current_order({ create_order_if_necessary: true }), current_currency) if populator.populate(params.slice(:products, :variants, :quantity), true) fire_event('spree.cart.add') @@ -127,7 +127,7 @@ def li_stock_levels(order) end def update_distribution - @order = current_order(true) + @order = current_order({ create_order_if_necessary: true }) if params[:commit] == 'Choose Hub' distributor = Enterprise.is_distributor.find params[:order][:distributor_id] @@ -159,7 +159,7 @@ def remove_missing_line_items(attrs) end def clear - @order = current_order(true) + @order = current_order({ create_order_if_necessary: true }) @order.empty! @order.set_order_cycle! nil redirect_to main_app.enterprise_path(@order.distributor.id) diff --git a/app/helpers/enterprises_helper.rb b/app/helpers/enterprises_helper.rb index 8cef0281b19..432ef6777c5 100644 --- a/app/helpers/enterprises_helper.rb +++ b/app/helpers/enterprises_helper.rb @@ -2,7 +2,7 @@ module EnterprisesHelper def current_distributor - @current_distributor ||= current_order(false).andand.distributor + @current_distributor ||= current_order({ create_order_if_necessary: false }).andand.distributor end def current_customer diff --git a/app/helpers/order_cycles_helper.rb b/app/helpers/order_cycles_helper.rb index 8afca2b9491..6c83ca5d099 100644 --- a/app/helpers/order_cycles_helper.rb +++ b/app/helpers/order_cycles_helper.rb @@ -1,6 +1,6 @@ module OrderCyclesHelper def current_order_cycle - @current_order_cycle ||= current_order(false).andand.order_cycle + @current_order_cycle ||= current_order({ create_order_if_necessary: false }).andand.order_cycle end def permitted_enterprises_for(order_cycle) diff --git a/app/helpers/shared_helper.rb b/app/helpers/shared_helper.rb index a1e1f84ec25..4ec9f88926e 100644 --- a/app/helpers/shared_helper.rb +++ b/app/helpers/shared_helper.rb @@ -1,6 +1,6 @@ module SharedHelper def distributor_link_class(distributor) - cart = current_order(true) + cart = current_order({ create_order_if_necessary: true }) @active_distributors ||= Enterprise.distributors_with_active_order_cycles klass = "shop-distributor" diff --git a/app/helpers/spree/orders_helper.rb b/app/helpers/spree/orders_helper.rb index 99540f6ed45..78d45c34b84 100644 --- a/app/helpers/spree/orders_helper.rb +++ b/app/helpers/spree/orders_helper.rb @@ -1,7 +1,7 @@ module Spree module OrdersHelper def cart_is_empty - order = current_order(false) + order = current_order({ create_order_if_necessary: false }) order.nil? || order.line_items.empty? end diff --git a/app/services/reset_order_service.rb b/app/services/reset_order_service.rb index 402c377eb74..ff369caee99 100644 --- a/app/services/reset_order_service.rb +++ b/app/services/reset_order_service.rb @@ -23,7 +23,7 @@ def call # Builds an order setting the token and distributor of the one specified def build_new_order - new_order = controller.current_order(true) + new_order = controller.current_order({ create_order_if_necessary: true }) new_order.set_distributor!(distributor) new_order.tokenized_permission.token = token new_order.tokenized_permission.save! diff --git a/app/views/spree/products/_add_to_cart.html.haml b/app/views/spree/products/_add_to_cart.html.haml index dd406ff50ba..c2e967dd6d0 100644 --- a/app/views/spree/products/_add_to_cart.html.haml +++ b/app/views/spree/products/_add_to_cart.html.haml @@ -1,5 +1,5 @@ .add-to-cart - - order = current_order(false) + - order = current_order({ create_order_if_necessary: false }) - if product_out_of_stock = content_tag('strong', t(:out_of_stock)) diff --git a/app/views/spree/products/_distributor_details.html.haml b/app/views/spree/products/_distributor_details.html.haml index e91c0ea6e57..e762ed97e10 100644 --- a/app/views/spree/products/_distributor_details.html.haml +++ b/app/views/spree/products/_distributor_details.html.haml @@ -2,7 +2,7 @@ %legend = t :products_distributor .distributor-details - - order = current_order(false) + - order = current_order({ create_order_if_necessary: false }) - if order.andand.distributor.present? = render 'enterprises/distributor_details', :distributor => order.distributor - else diff --git a/app/views/spree/products/_source.html.haml b/app/views/spree/products/_source.html.haml index 7751ba36ef0..ca952bb5171 100644 --- a/app/views/spree/products/_source.html.haml +++ b/app/views/spree/products/_source.html.haml @@ -10,7 +10,7 @@ %h6.product-section-title= t(:distributors) %table#product-source.table-display{:width => "100%"} %tbody - - order = current_order(false) + - order = current_order({ create_order_if_necessary: false }) - validator = DistributionChangeValidator.new(order) - Enterprise.distributing_products(@product).each do |distributor| - if !order.nil? && distributor == order.distributor diff --git a/lib/spree/core/controller_helpers/order_decorator.rb b/lib/spree/core/controller_helpers/order_decorator.rb index dc38e861e64..d72fc7b22f3 100644 --- a/lib/spree/core/controller_helpers/order_decorator.rb +++ b/lib/spree/core/controller_helpers/order_decorator.rb @@ -1,6 +1,6 @@ Spree::Core::ControllerHelpers::Order.class_eval do - def current_order_with_scoped_variants(create_order_if_necessary = false) - order = current_order_without_scoped_variants(create_order_if_necessary) + def current_order_with_scoped_variants(options = {}) + order = current_order_without_scoped_variants(options) if order scoper = OpenFoodNetwork::ScopeVariantToHub.new(order.distributor) diff --git a/spec/controllers/checkout_controller_spec.rb b/spec/controllers/checkout_controller_spec.rb index b373ae64b5f..ed11ad2955c 100644 --- a/spec/controllers/checkout_controller_spec.rb +++ b/spec/controllers/checkout_controller_spec.rb @@ -94,7 +94,7 @@ end it "sets the new order's token to the same as the old order" do - order = controller.current_order(true) + order = controller.current_order({ create_order_if_necessary: true }) spree_post :update, order: {} expect(controller.current_order.token).to eq order.token end diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index eedcb5ad160..7aef356a8d5 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -2,7 +2,7 @@ describe EnterprisesController, type: :controller do describe "shopping for a distributor" do - let(:order) { controller.current_order(true) } + let(:order) { controller.current_order({ create_order_if_necessary: true }) } let!(:current_distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) } diff --git a/spec/controllers/spree/checkout_controller_spec.rb b/spec/controllers/spree/checkout_controller_spec.rb index b91c19f7444..bc21a068bd9 100644 --- a/spec/controllers/spree/checkout_controller_spec.rb +++ b/spec/controllers/spree/checkout_controller_spec.rb @@ -5,7 +5,7 @@ describe Spree::CheckoutController, type: :controller do context 'rendering edit from within spree for the current checkout state' do - let(:order) { controller.current_order(true) } + let(:order) { controller.current_order({ create_order_if_necessary: true }) } let(:user) { create(:user) } before do diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index fbcd5ec1078..6aa80973b80 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -30,7 +30,7 @@ it "redirects home with message if hub is not ready for checkout" do VariantOverride.stub(:indexed).and_return({}) - order = subject.current_order(true) + order = subject.current_order({ create_order_if_necessary: true }) distributor.stub(:ready_for_checkout?) { false } order.stub(distributor: distributor, order_cycle: order_cycle) @@ -44,7 +44,7 @@ end describe "when an item has insufficient stock" do - let(:order) { subject.current_order(true) } + let(:order) { subject.current_order({ create_order_if_necessary: true }) } let(:oc) { create(:simple_order_cycle, distributors: [d], variants: [variant]) } let(:d) { create(:distributor_enterprise, shipping_methods: [create(:shipping_method)], payment_methods: [create(:payment_method)]) } let(:variant) { create(:variant, on_demand: false, on_hand: 5) } @@ -129,7 +129,7 @@ distributor_product = create(:distributor_enterprise) p = create(:product, :distributors => [distributor_product], :group_buy => true) - order = subject.current_order(true) + order = subject.current_order({ create_order_if_necessary: true }) order.stub(:distributor) { distributor_product } order.should_receive(:set_variant_attributes).with(p.master, {'max_quantity' => '3'}) controller.stub(:current_order).and_return(order) @@ -164,7 +164,7 @@ describe "removing line items from cart" do describe "when I pass params that includes a line item no longer in our cart" do it "should silently ignore the missing line item" do - order = subject.current_order(true) + order = subject.current_order({ create_order_if_necessary: true }) li = order.add_variant(create(:simple_product, on_hand: 110).variants.first) spree_get :update, order: { line_items_attributes: { "0" => {quantity: "0", id: "9999"}, @@ -176,7 +176,7 @@ end it "filters line items that are missing from params" do - order = subject.current_order(true) + order = subject.current_order({ create_order_if_necessary: true }) li = order.add_variant(create(:simple_product).master) attrs = { diff --git a/spec/controllers/spree/paypal_controller_spec.rb b/spec/controllers/spree/paypal_controller_spec.rb index 90f97fcb7d7..6c284858e83 100644 --- a/spec/controllers/spree/paypal_controller_spec.rb +++ b/spec/controllers/spree/paypal_controller_spec.rb @@ -9,7 +9,7 @@ module Spree end context 'when confirming' do - let(:previous_order) { controller.current_order(true) } + let(:previous_order) { controller.current_order({ create_order_if_necessary: true }) } let(:payment_method) { create(:payment_method) } before do diff --git a/spec/performance/orders_controller_spec.rb b/spec/performance/orders_controller_spec.rb index e151e4f506f..5b6fb97e951 100644 --- a/spec/performance/orders_controller_spec.rb +++ b/spec/performance/orders_controller_spec.rb @@ -4,7 +4,7 @@ let(:distributor) { create(:distributor_enterprise) } let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], variants: products.map { |p| p.variants.first }) } let(:products) { (0...num_products).map { create(:product) } } - let(:order) { subject.current_order(true) } + let(:order) { subject.current_order({ create_order_if_necessary: true }) } let(:num_products) { 20 } before do From d9f451b6fee97a39c2f325cf9ed1902a4266340a Mon Sep 17 00:00:00 2001 From: Hugo Daniel Date: Fri, 13 Apr 2018 11:58:13 +0200 Subject: [PATCH 04/42] Removing redundant curly braces --- app/controllers/base_controller.rb | 2 +- app/controllers/enterprises_controller.rb | 4 ++-- app/controllers/shop_controller.rb | 2 +- app/controllers/spree/orders_controller_decorator.rb | 8 ++++---- app/helpers/enterprises_helper.rb | 2 +- app/helpers/order_cycles_helper.rb | 2 +- app/helpers/shared_helper.rb | 2 +- app/helpers/spree/orders_helper.rb | 2 +- app/services/reset_order_service.rb | 2 +- app/views/spree/products/_add_to_cart.html.haml | 2 +- .../spree/products/_distributor_details.html.haml | 2 +- app/views/spree/products/_source.html.haml | 2 +- spec/controllers/checkout_controller_spec.rb | 2 +- spec/controllers/enterprises_controller_spec.rb | 2 +- spec/controllers/spree/checkout_controller_spec.rb | 2 +- spec/controllers/spree/orders_controller_spec.rb | 10 +++++----- spec/controllers/spree/paypal_controller_spec.rb | 2 +- spec/performance/orders_controller_spec.rb | 2 +- 18 files changed, 26 insertions(+), 26 deletions(-) diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index 18bc679fbed..58a6c932b39 100644 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -37,7 +37,7 @@ def set_order_cycles # And default to the only order cycle if there's only the one if @order_cycles.count == 1 - current_order({ create_order_if_necessary: true }).set_order_cycle! @order_cycles.first + current_order( create_order_if_necessary: true ).set_order_cycle! @order_cycles.first end end end diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb index 88621ec53c7..17874c7e0e3 100644 --- a/app/controllers/enterprises_controller.rb +++ b/app/controllers/enterprises_controller.rb @@ -49,14 +49,14 @@ def clean_permalink end def check_stock_levels - if current_order({ create_order_if_necessary: true }).insufficient_stock_lines.present? + if current_order(create_order_if_necessary: true).insufficient_stock_lines.present? redirect_to spree.cart_path end end def reset_order distributor = Enterprise.is_distributor.find_by_permalink(params[:id]) || Enterprise.is_distributor.find(params[:id]) - order = current_order({ create_order_if_necessary: true }) + order = current_order(create_order_if_necessary: true) reset_distributor(order, distributor) diff --git a/app/controllers/shop_controller.rb b/app/controllers/shop_controller.rb index b9136c01bbd..c127e24ca9e 100644 --- a/app/controllers/shop_controller.rb +++ b/app/controllers/shop_controller.rb @@ -26,7 +26,7 @@ def products def order_cycle if request.post? if oc = OrderCycle.with_distributor(@distributor).active.find_by_id(params[:order_cycle_id]) - current_order({ create_order_if_necessary: true }).set_order_cycle! oc + current_order(create_order_if_necessary: true).set_order_cycle! oc render partial: "json/order_cycle" else render status: 404, json: "" diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb index 9d22a33b64c..2816ab6e26f 100644 --- a/app/controllers/spree/orders_controller_decorator.rb +++ b/app/controllers/spree/orders_controller_decorator.rb @@ -18,7 +18,7 @@ # Patching to redirect to shop if order is empty def edit - @order = current_order({ create_order_if_necessary: true }) + @order = current_order( create_order_if_necessary: true ) @insufficient_stock_lines = @order.insufficient_stock_lines if @order.line_items.empty? @@ -78,7 +78,7 @@ def populate # callbacks on Spree::Adjustment and then manually invoke Spree::Order#update! on success. Spree::Adjustment.without_callbacks do - populator = Spree::OrderPopulator.new(current_order({ create_order_if_necessary: true }), current_currency) + populator = Spree::OrderPopulator.new(current_order( create_order_if_necessary: true ), current_currency) if populator.populate(params.slice(:products, :variants, :quantity), true) fire_event('spree.cart.add') @@ -127,7 +127,7 @@ def li_stock_levels(order) end def update_distribution - @order = current_order({ create_order_if_necessary: true }) + @order = current_order( create_order_if_necessary: true ) if params[:commit] == 'Choose Hub' distributor = Enterprise.is_distributor.find params[:order][:distributor_id] @@ -159,7 +159,7 @@ def remove_missing_line_items(attrs) end def clear - @order = current_order({ create_order_if_necessary: true }) + @order = current_order( create_order_if_necessary: true ) @order.empty! @order.set_order_cycle! nil redirect_to main_app.enterprise_path(@order.distributor.id) diff --git a/app/helpers/enterprises_helper.rb b/app/helpers/enterprises_helper.rb index 432ef6777c5..511c55df04e 100644 --- a/app/helpers/enterprises_helper.rb +++ b/app/helpers/enterprises_helper.rb @@ -2,7 +2,7 @@ module EnterprisesHelper def current_distributor - @current_distributor ||= current_order({ create_order_if_necessary: false }).andand.distributor + @current_distributor ||= current_order( create_order_if_necessary: false ).andand.distributor end def current_customer diff --git a/app/helpers/order_cycles_helper.rb b/app/helpers/order_cycles_helper.rb index 6c83ca5d099..07a0ea488ac 100644 --- a/app/helpers/order_cycles_helper.rb +++ b/app/helpers/order_cycles_helper.rb @@ -1,6 +1,6 @@ module OrderCyclesHelper def current_order_cycle - @current_order_cycle ||= current_order({ create_order_if_necessary: false }).andand.order_cycle + @current_order_cycle ||= current_order( create_order_if_necessary: false ).andand.order_cycle end def permitted_enterprises_for(order_cycle) diff --git a/app/helpers/shared_helper.rb b/app/helpers/shared_helper.rb index 4ec9f88926e..253dceacb50 100644 --- a/app/helpers/shared_helper.rb +++ b/app/helpers/shared_helper.rb @@ -1,6 +1,6 @@ module SharedHelper def distributor_link_class(distributor) - cart = current_order({ create_order_if_necessary: true }) + cart = current_order( create_order_if_necessary: true ) @active_distributors ||= Enterprise.distributors_with_active_order_cycles klass = "shop-distributor" diff --git a/app/helpers/spree/orders_helper.rb b/app/helpers/spree/orders_helper.rb index 78d45c34b84..12e90bd482c 100644 --- a/app/helpers/spree/orders_helper.rb +++ b/app/helpers/spree/orders_helper.rb @@ -1,7 +1,7 @@ module Spree module OrdersHelper def cart_is_empty - order = current_order({ create_order_if_necessary: false }) + order = current_order( create_order_if_necessary: false ) order.nil? || order.line_items.empty? end diff --git a/app/services/reset_order_service.rb b/app/services/reset_order_service.rb index ff369caee99..3ffdf1ffb59 100644 --- a/app/services/reset_order_service.rb +++ b/app/services/reset_order_service.rb @@ -23,7 +23,7 @@ def call # Builds an order setting the token and distributor of the one specified def build_new_order - new_order = controller.current_order({ create_order_if_necessary: true }) + new_order = controller.current_order( create_order_if_necessary: true ) new_order.set_distributor!(distributor) new_order.tokenized_permission.token = token new_order.tokenized_permission.save! diff --git a/app/views/spree/products/_add_to_cart.html.haml b/app/views/spree/products/_add_to_cart.html.haml index c2e967dd6d0..e5d5248f2f7 100644 --- a/app/views/spree/products/_add_to_cart.html.haml +++ b/app/views/spree/products/_add_to_cart.html.haml @@ -1,5 +1,5 @@ .add-to-cart - - order = current_order({ create_order_if_necessary: false }) + - order = current_order( create_order_if_necessary: false ) - if product_out_of_stock = content_tag('strong', t(:out_of_stock)) diff --git a/app/views/spree/products/_distributor_details.html.haml b/app/views/spree/products/_distributor_details.html.haml index e762ed97e10..f044c622a70 100644 --- a/app/views/spree/products/_distributor_details.html.haml +++ b/app/views/spree/products/_distributor_details.html.haml @@ -2,7 +2,7 @@ %legend = t :products_distributor .distributor-details - - order = current_order({ create_order_if_necessary: false }) + - order = current_order( create_order_if_necessary: false ) - if order.andand.distributor.present? = render 'enterprises/distributor_details', :distributor => order.distributor - else diff --git a/app/views/spree/products/_source.html.haml b/app/views/spree/products/_source.html.haml index ca952bb5171..8c5ac66fe30 100644 --- a/app/views/spree/products/_source.html.haml +++ b/app/views/spree/products/_source.html.haml @@ -10,7 +10,7 @@ %h6.product-section-title= t(:distributors) %table#product-source.table-display{:width => "100%"} %tbody - - order = current_order({ create_order_if_necessary: false }) + - order = current_order( create_order_if_necessary: false ) - validator = DistributionChangeValidator.new(order) - Enterprise.distributing_products(@product).each do |distributor| - if !order.nil? && distributor == order.distributor diff --git a/spec/controllers/checkout_controller_spec.rb b/spec/controllers/checkout_controller_spec.rb index ed11ad2955c..151af21ae83 100644 --- a/spec/controllers/checkout_controller_spec.rb +++ b/spec/controllers/checkout_controller_spec.rb @@ -94,7 +94,7 @@ end it "sets the new order's token to the same as the old order" do - order = controller.current_order({ create_order_if_necessary: true }) + order = controller.current_order( create_order_if_necessary: true ) spree_post :update, order: {} expect(controller.current_order.token).to eq order.token end diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index 7aef356a8d5..d459c937fba 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -2,7 +2,7 @@ describe EnterprisesController, type: :controller do describe "shopping for a distributor" do - let(:order) { controller.current_order({ create_order_if_necessary: true }) } + let(:order) { controller.current_order( create_order_if_necessary: true ) } let!(:current_distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) } diff --git a/spec/controllers/spree/checkout_controller_spec.rb b/spec/controllers/spree/checkout_controller_spec.rb index bc21a068bd9..47537e21330 100644 --- a/spec/controllers/spree/checkout_controller_spec.rb +++ b/spec/controllers/spree/checkout_controller_spec.rb @@ -5,7 +5,7 @@ describe Spree::CheckoutController, type: :controller do context 'rendering edit from within spree for the current checkout state' do - let(:order) { controller.current_order({ create_order_if_necessary: true }) } + let(:order) { controller.current_order( create_order_if_necessary: true ) } let(:user) { create(:user) } before do diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index 6aa80973b80..9574d5f41b2 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -30,7 +30,7 @@ it "redirects home with message if hub is not ready for checkout" do VariantOverride.stub(:indexed).and_return({}) - order = subject.current_order({ create_order_if_necessary: true }) + order = subject.current_order( create_order_if_necessary: true ) distributor.stub(:ready_for_checkout?) { false } order.stub(distributor: distributor, order_cycle: order_cycle) @@ -44,7 +44,7 @@ end describe "when an item has insufficient stock" do - let(:order) { subject.current_order({ create_order_if_necessary: true }) } + let(:order) { subject.current_order( create_order_if_necessary: true ) } let(:oc) { create(:simple_order_cycle, distributors: [d], variants: [variant]) } let(:d) { create(:distributor_enterprise, shipping_methods: [create(:shipping_method)], payment_methods: [create(:payment_method)]) } let(:variant) { create(:variant, on_demand: false, on_hand: 5) } @@ -129,7 +129,7 @@ distributor_product = create(:distributor_enterprise) p = create(:product, :distributors => [distributor_product], :group_buy => true) - order = subject.current_order({ create_order_if_necessary: true }) + order = subject.current_order( create_order_if_necessary: true ) order.stub(:distributor) { distributor_product } order.should_receive(:set_variant_attributes).with(p.master, {'max_quantity' => '3'}) controller.stub(:current_order).and_return(order) @@ -164,7 +164,7 @@ describe "removing line items from cart" do describe "when I pass params that includes a line item no longer in our cart" do it "should silently ignore the missing line item" do - order = subject.current_order({ create_order_if_necessary: true }) + order = subject.current_order( create_order_if_necessary: true ) li = order.add_variant(create(:simple_product, on_hand: 110).variants.first) spree_get :update, order: { line_items_attributes: { "0" => {quantity: "0", id: "9999"}, @@ -176,7 +176,7 @@ end it "filters line items that are missing from params" do - order = subject.current_order({ create_order_if_necessary: true }) + order = subject.current_order( create_order_if_necessary: true ) li = order.add_variant(create(:simple_product).master) attrs = { diff --git a/spec/controllers/spree/paypal_controller_spec.rb b/spec/controllers/spree/paypal_controller_spec.rb index 6c284858e83..4ce004183c6 100644 --- a/spec/controllers/spree/paypal_controller_spec.rb +++ b/spec/controllers/spree/paypal_controller_spec.rb @@ -9,7 +9,7 @@ module Spree end context 'when confirming' do - let(:previous_order) { controller.current_order({ create_order_if_necessary: true }) } + let(:previous_order) { controller.current_order( create_order_if_necessary: true ) } let(:payment_method) { create(:payment_method) } before do diff --git a/spec/performance/orders_controller_spec.rb b/spec/performance/orders_controller_spec.rb index 5b6fb97e951..58adf05540c 100644 --- a/spec/performance/orders_controller_spec.rb +++ b/spec/performance/orders_controller_spec.rb @@ -4,7 +4,7 @@ let(:distributor) { create(:distributor_enterprise) } let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], variants: products.map { |p| p.variants.first }) } let(:products) { (0...num_products).map { create(:product) } } - let(:order) { subject.current_order({ create_order_if_necessary: true }) } + let(:order) { subject.current_order( create_order_if_necessary: true ) } let(:num_products) { 20 } before do From 595a622d5bfee3a361454994dc954a50b77aff15 Mon Sep 17 00:00:00 2001 From: Hugo Daniel Date: Fri, 13 Apr 2018 17:53:13 +0200 Subject: [PATCH 05/42] Removing useless spaces --- app/controllers/base_controller.rb | 2 +- app/controllers/spree/orders_controller_decorator.rb | 8 ++++---- app/helpers/enterprises_helper.rb | 2 +- app/helpers/order_cycles_helper.rb | 2 +- app/helpers/shared_helper.rb | 2 +- app/helpers/spree/orders_helper.rb | 2 +- app/services/reset_order_service.rb | 2 +- app/views/spree/products/_add_to_cart.html.haml | 2 +- .../spree/products/_distributor_details.html.haml | 2 +- app/views/spree/products/_source.html.haml | 2 +- spec/controllers/checkout_controller_spec.rb | 2 +- spec/controllers/enterprises_controller_spec.rb | 2 +- spec/controllers/spree/checkout_controller_spec.rb | 2 +- spec/controllers/spree/orders_controller_spec.rb | 10 +++++----- spec/controllers/spree/paypal_controller_spec.rb | 2 +- spec/performance/orders_controller_spec.rb | 2 +- 16 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index 58a6c932b39..14f7e52371d 100644 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -37,7 +37,7 @@ def set_order_cycles # And default to the only order cycle if there's only the one if @order_cycles.count == 1 - current_order( create_order_if_necessary: true ).set_order_cycle! @order_cycles.first + current_order(create_order_if_necessary: true).set_order_cycle! @order_cycles.first end end end diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb index 2816ab6e26f..739aad3a7de 100644 --- a/app/controllers/spree/orders_controller_decorator.rb +++ b/app/controllers/spree/orders_controller_decorator.rb @@ -18,7 +18,7 @@ # Patching to redirect to shop if order is empty def edit - @order = current_order( create_order_if_necessary: true ) + @order = current_order(create_order_if_necessary: true) @insufficient_stock_lines = @order.insufficient_stock_lines if @order.line_items.empty? @@ -78,7 +78,7 @@ def populate # callbacks on Spree::Adjustment and then manually invoke Spree::Order#update! on success. Spree::Adjustment.without_callbacks do - populator = Spree::OrderPopulator.new(current_order( create_order_if_necessary: true ), current_currency) + populator = Spree::OrderPopulator.new(current_order(create_order_if_necessary: true), current_currency) if populator.populate(params.slice(:products, :variants, :quantity), true) fire_event('spree.cart.add') @@ -127,7 +127,7 @@ def li_stock_levels(order) end def update_distribution - @order = current_order( create_order_if_necessary: true ) + @order = current_order(create_order_if_necessary: true) if params[:commit] == 'Choose Hub' distributor = Enterprise.is_distributor.find params[:order][:distributor_id] @@ -159,7 +159,7 @@ def remove_missing_line_items(attrs) end def clear - @order = current_order( create_order_if_necessary: true ) + @order = current_order(create_order_if_necessary: true) @order.empty! @order.set_order_cycle! nil redirect_to main_app.enterprise_path(@order.distributor.id) diff --git a/app/helpers/enterprises_helper.rb b/app/helpers/enterprises_helper.rb index 511c55df04e..549c86f5730 100644 --- a/app/helpers/enterprises_helper.rb +++ b/app/helpers/enterprises_helper.rb @@ -2,7 +2,7 @@ module EnterprisesHelper def current_distributor - @current_distributor ||= current_order( create_order_if_necessary: false ).andand.distributor + @current_distributor ||= current_order(create_order_if_necessary: false).andand.distributor end def current_customer diff --git a/app/helpers/order_cycles_helper.rb b/app/helpers/order_cycles_helper.rb index 07a0ea488ac..064582aba50 100644 --- a/app/helpers/order_cycles_helper.rb +++ b/app/helpers/order_cycles_helper.rb @@ -1,6 +1,6 @@ module OrderCyclesHelper def current_order_cycle - @current_order_cycle ||= current_order( create_order_if_necessary: false ).andand.order_cycle + @current_order_cycle ||= current_order(create_order_if_necessary: false).andand.order_cycle end def permitted_enterprises_for(order_cycle) diff --git a/app/helpers/shared_helper.rb b/app/helpers/shared_helper.rb index 253dceacb50..bacf123814c 100644 --- a/app/helpers/shared_helper.rb +++ b/app/helpers/shared_helper.rb @@ -1,6 +1,6 @@ module SharedHelper def distributor_link_class(distributor) - cart = current_order( create_order_if_necessary: true ) + cart = current_order(create_order_if_necessary: true) @active_distributors ||= Enterprise.distributors_with_active_order_cycles klass = "shop-distributor" diff --git a/app/helpers/spree/orders_helper.rb b/app/helpers/spree/orders_helper.rb index 12e90bd482c..a37f4091994 100644 --- a/app/helpers/spree/orders_helper.rb +++ b/app/helpers/spree/orders_helper.rb @@ -1,7 +1,7 @@ module Spree module OrdersHelper def cart_is_empty - order = current_order( create_order_if_necessary: false ) + order = current_order(create_order_if_necessary: false) order.nil? || order.line_items.empty? end diff --git a/app/services/reset_order_service.rb b/app/services/reset_order_service.rb index 3ffdf1ffb59..95e73290c91 100644 --- a/app/services/reset_order_service.rb +++ b/app/services/reset_order_service.rb @@ -23,7 +23,7 @@ def call # Builds an order setting the token and distributor of the one specified def build_new_order - new_order = controller.current_order( create_order_if_necessary: true ) + new_order = controller.current_order(create_order_if_necessary: true) new_order.set_distributor!(distributor) new_order.tokenized_permission.token = token new_order.tokenized_permission.save! diff --git a/app/views/spree/products/_add_to_cart.html.haml b/app/views/spree/products/_add_to_cart.html.haml index e5d5248f2f7..dbc09929b70 100644 --- a/app/views/spree/products/_add_to_cart.html.haml +++ b/app/views/spree/products/_add_to_cart.html.haml @@ -1,5 +1,5 @@ .add-to-cart - - order = current_order( create_order_if_necessary: false ) + - order = current_order(create_order_if_necessary: false) - if product_out_of_stock = content_tag('strong', t(:out_of_stock)) diff --git a/app/views/spree/products/_distributor_details.html.haml b/app/views/spree/products/_distributor_details.html.haml index f044c622a70..1329a03f8a1 100644 --- a/app/views/spree/products/_distributor_details.html.haml +++ b/app/views/spree/products/_distributor_details.html.haml @@ -2,7 +2,7 @@ %legend = t :products_distributor .distributor-details - - order = current_order( create_order_if_necessary: false ) + - order = current_order(create_order_if_necessary: false) - if order.andand.distributor.present? = render 'enterprises/distributor_details', :distributor => order.distributor - else diff --git a/app/views/spree/products/_source.html.haml b/app/views/spree/products/_source.html.haml index 8c5ac66fe30..461a4dc6c97 100644 --- a/app/views/spree/products/_source.html.haml +++ b/app/views/spree/products/_source.html.haml @@ -10,7 +10,7 @@ %h6.product-section-title= t(:distributors) %table#product-source.table-display{:width => "100%"} %tbody - - order = current_order( create_order_if_necessary: false ) + - order = current_order(create_order_if_necessary: false) - validator = DistributionChangeValidator.new(order) - Enterprise.distributing_products(@product).each do |distributor| - if !order.nil? && distributor == order.distributor diff --git a/spec/controllers/checkout_controller_spec.rb b/spec/controllers/checkout_controller_spec.rb index 151af21ae83..5335b1f3871 100644 --- a/spec/controllers/checkout_controller_spec.rb +++ b/spec/controllers/checkout_controller_spec.rb @@ -94,7 +94,7 @@ end it "sets the new order's token to the same as the old order" do - order = controller.current_order( create_order_if_necessary: true ) + order = controller.current_order(create_order_if_necessary: true) spree_post :update, order: {} expect(controller.current_order.token).to eq order.token end diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index d459c937fba..bcd434302ec 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -2,7 +2,7 @@ describe EnterprisesController, type: :controller do describe "shopping for a distributor" do - let(:order) { controller.current_order( create_order_if_necessary: true ) } + let(:order) { controller.current_order(create_order_if_necessary: true) } let!(:current_distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) } diff --git a/spec/controllers/spree/checkout_controller_spec.rb b/spec/controllers/spree/checkout_controller_spec.rb index 47537e21330..37bd483d559 100644 --- a/spec/controllers/spree/checkout_controller_spec.rb +++ b/spec/controllers/spree/checkout_controller_spec.rb @@ -5,7 +5,7 @@ describe Spree::CheckoutController, type: :controller do context 'rendering edit from within spree for the current checkout state' do - let(:order) { controller.current_order( create_order_if_necessary: true ) } + let(:order) { controller.current_order(create_order_if_necessary: true) } let(:user) { create(:user) } before do diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index 9574d5f41b2..ce15c8cacca 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -30,7 +30,7 @@ it "redirects home with message if hub is not ready for checkout" do VariantOverride.stub(:indexed).and_return({}) - order = subject.current_order( create_order_if_necessary: true ) + order = subject.current_order(create_order_if_necessary: true) distributor.stub(:ready_for_checkout?) { false } order.stub(distributor: distributor, order_cycle: order_cycle) @@ -44,7 +44,7 @@ end describe "when an item has insufficient stock" do - let(:order) { subject.current_order( create_order_if_necessary: true ) } + let(:order) { subject.current_order(create_order_if_necessary: true) } let(:oc) { create(:simple_order_cycle, distributors: [d], variants: [variant]) } let(:d) { create(:distributor_enterprise, shipping_methods: [create(:shipping_method)], payment_methods: [create(:payment_method)]) } let(:variant) { create(:variant, on_demand: false, on_hand: 5) } @@ -129,7 +129,7 @@ distributor_product = create(:distributor_enterprise) p = create(:product, :distributors => [distributor_product], :group_buy => true) - order = subject.current_order( create_order_if_necessary: true ) + order = subject.current_order(create_order_if_necessary: true) order.stub(:distributor) { distributor_product } order.should_receive(:set_variant_attributes).with(p.master, {'max_quantity' => '3'}) controller.stub(:current_order).and_return(order) @@ -164,7 +164,7 @@ describe "removing line items from cart" do describe "when I pass params that includes a line item no longer in our cart" do it "should silently ignore the missing line item" do - order = subject.current_order( create_order_if_necessary: true ) + order = subject.current_order(create_order_if_necessary: true) li = order.add_variant(create(:simple_product, on_hand: 110).variants.first) spree_get :update, order: { line_items_attributes: { "0" => {quantity: "0", id: "9999"}, @@ -176,7 +176,7 @@ end it "filters line items that are missing from params" do - order = subject.current_order( create_order_if_necessary: true ) + order = subject.current_order(create_order_if_necessary: true) li = order.add_variant(create(:simple_product).master) attrs = { diff --git a/spec/controllers/spree/paypal_controller_spec.rb b/spec/controllers/spree/paypal_controller_spec.rb index 4ce004183c6..4843eef98df 100644 --- a/spec/controllers/spree/paypal_controller_spec.rb +++ b/spec/controllers/spree/paypal_controller_spec.rb @@ -9,7 +9,7 @@ module Spree end context 'when confirming' do - let(:previous_order) { controller.current_order( create_order_if_necessary: true ) } + let(:previous_order) { controller.current_order(create_order_if_necessary: true) } let(:payment_method) { create(:payment_method) } before do diff --git a/spec/performance/orders_controller_spec.rb b/spec/performance/orders_controller_spec.rb index 58adf05540c..ee856901217 100644 --- a/spec/performance/orders_controller_spec.rb +++ b/spec/performance/orders_controller_spec.rb @@ -4,7 +4,7 @@ let(:distributor) { create(:distributor_enterprise) } let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], variants: products.map { |p| p.variants.first }) } let(:products) { (0...num_products).map { create(:product) } } - let(:order) { subject.current_order( create_order_if_necessary: true ) } + let(:order) { subject.current_order(create_order_if_necessary: true) } let(:num_products) { 20 } before do From 06ef2a4c6362b056325d5df07bb6761f84c8ac60 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Mon, 16 Apr 2018 15:36:03 +0200 Subject: [PATCH 06/42] Remove commented out gem from Gemfile --- Gemfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Gemfile b/Gemfile index feb780db3be..c957fd4b4e8 100644 --- a/Gemfile +++ b/Gemfile @@ -18,7 +18,6 @@ gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-0-stable' # Our branch contains two changes # - Pass customer email and phone number to PayPal (merged to upstream master) # - Change type of password from string to password to hide it in the form -# gem 'spree_paypal_express' gem 'spree_paypal_express', github: "spree-contrib/better_spree_paypal_express", branch: "2-0-stable" gem 'stripe', '~> 3.3.1' gem 'activemerchant' From 58f3b5a97e01195f5dd3c377484a7993f3aee41c Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Wed, 18 Apr 2018 08:56:03 +0200 Subject: [PATCH 07/42] Upgrade Spree to 2.0.4 instead of 2.0.13 Although we don't know how big the fixes introduced between 2.0.4 and 2.0.13 are, jumping from roughly 1.3.99 to 2.0.13 seems too big of a change to do in one go. Unless more issues like this one come up that force us to upgrade to a newer version I believe it's best to be conservative. You'll find an in-depth explanation in https://github.com/openfoodfoundation/openfoodnetwork/wiki/Spree-2.0-upgrade#getting-to-version-204- A previous effort was done to upgrade to v2.0.13 in https://github.com/openfoodfoundation/openfoodnetwork/pull/2209 --- Gemfile | 2 +- Gemfile.lock | 112 +++++++++++++++++++++++++-------------------------- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/Gemfile b/Gemfile index c957fd4b4e8..aa3376f9792 100644 --- a/Gemfile +++ b/Gemfile @@ -11,7 +11,7 @@ gem 'i18n-js', '~> 3.0.0' gem 'nokogiri', '>= 1.6.7.1' gem 'pg' -gem 'spree', '2.0.13' +gem 'spree', '2.0.4' gem 'spree_i18n', github: 'spree/spree_i18n', branch: '1-3-stable' gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-0-stable' diff --git a/Gemfile.lock b/Gemfile.lock index 6dbbd9439fe..4838cbf3454 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -107,7 +107,7 @@ GEM multi_json (~> 1.0) acts-as-taggable-on (3.5.0) activerecord (>= 3.2, < 5) - acts_as_list (0.3.0) + acts_as_list (0.2.0) activerecord (>= 3.0) addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) @@ -121,10 +121,11 @@ GEM arel (3.0.3) ast (2.3.0) atomic (1.1.99) - awesome_nested_set (2.1.6) + awesome_nested_set (2.1.5) activerecord (>= 3.0.0) awesome_print (1.0.2) - aws-sdk (1.31.3) + aws-sdk (1.3.9) + httparty (~> 0.7) json (~> 1.4) nokogiri (>= 1.4.4) uuidtools (~> 2.1) @@ -373,7 +374,7 @@ GEM rspec (>= 2.99.0, < 4.0) haml (4.0.4) tilt - highline (1.6.21) + highline (1.6.18) hike (1.2.3) http_parser.rb (0.6.0) httparty (0.16.2) @@ -398,7 +399,7 @@ GEM multi_json (~> 1.0) rspec (>= 2.0, < 4.0) jwt (1.5.4) - kaminari (0.15.1) + kaminari (0.14.1) actionpack (>= 3.0.0) activesupport (>= 3.0.0) kgio (2.9.3) @@ -422,10 +423,8 @@ GEM mini_portile2 (2.1.0) momentjs-rails (2.5.1) railties (>= 3.1) - monetize (1.7.0) - money (~> 6.9) - money (6.11.0) - i18n (>= 0.6.4, < 1.1) + money (5.1.1) + i18n (~> 0.6.0) multi_json (1.12.1) multi_xml (0.6.0) multipart-post (2.0.0) @@ -470,8 +469,8 @@ GEM capybara (~> 2.1) cliver (~> 0.3.1) websocket-driver (>= 0.2.0) - polyamorous (0.6.4) - activerecord (>= 3.0) + polyamorous (0.5.0) + activerecord (~> 3.0) polyglot (0.3.5) powerpack (0.1.1) pry (0.11.2) @@ -481,7 +480,7 @@ GEM byebug (>= 9.0, < 9.1) pry (~> 0.10) public_suffix (3.0.0) - rabl (0.9.3) + rabl (0.8.4) activesupport (>= 2.3.14) rack (1.4.7) rack-cache (1.7.0) @@ -514,10 +513,10 @@ GEM rake raindrops (0.13.0) rake (10.5.0) - ransack (1.1.0) - actionpack (>= 3.0) - activerecord (>= 3.0) - polyamorous (~> 0.6.0) + ransack (0.7.2) + actionpack (~> 3.0) + activerecord (~> 3.0) + polyamorous (~> 0.5.0) rb-fsevent (0.10.2) rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) @@ -590,55 +589,57 @@ GEM activesupport (>= 3.0.0) spinjs-rails (1.3) rails (>= 3.1) - spree (2.0.13) - spree_api (= 2.0.13) - spree_backend (= 2.0.13) - spree_cmd (= 2.0.13) - spree_core (= 2.0.13) - spree_frontend (= 2.0.13) - spree_sample (= 2.0.13) - spree_api (2.0.13) - rabl (= 0.9.3) - spree_core (= 2.0.13) - versioncake (~> 1.2.0) - spree_backend (2.0.13) + spree (2.0.4) + spree_api (= 2.0.4) + spree_backend (= 2.0.4) + spree_cmd (= 2.0.4) + spree_core (= 2.0.4) + spree_frontend (= 2.0.4) + spree_sample (= 2.0.4) + spree_api (2.0.4) + rabl (= 0.8.4) + spree_core (= 2.0.4) + versioncake (= 1.0.0) + spree_backend (2.0.4) + deface (>= 0.9.0) jquery-rails (~> 3.0.0) jquery-ui-rails (~> 4.0.0) + rails (~> 3.2.8) select2-rails (~> 3.4.7) - spree_api (= 2.0.13) - spree_core (= 2.0.13) - spree_cmd (2.0.13) - thor (~> 0.14) - spree_core (2.0.13) - activemerchant (~> 1.43.1) - acts_as_list (= 0.3.0) - awesome_nested_set (= 2.1.6) - aws-sdk (= 1.31.3) + spree_api (= 2.0.4) + spree_core (= 2.0.4) + spree_cmd (2.0.4) + thor (>= 0.14.6) + spree_core (2.0.4) + activemerchant (~> 1.34) + acts_as_list (= 0.2.0) + awesome_nested_set (= 2.1.5) + aws-sdk (~> 1.3.4) cancan (~> 1.6.10) - deface (= 1.0.0) - ffaker (~> 1.22.0) - highline (~> 1.6.18) + deface (>= 0.9.1) + ffaker (~> 1.16) + highline (= 1.6.18) httparty (~> 0.11) - json (~> 1.7) - kaminari (~> 0.15.0) - monetize + json (>= 1.7.7) + kaminari (~> 0.14.1) + money (= 5.1.1) paperclip (~> 3.4.1) paranoia (~> 1.3) - rails (~> 3.2.21) - ransack (~> 1.1.0) + rails (~> 3.2.14) + ransack (= 0.7.2) state_machine (= 1.2.0) stringex (~> 1.5.1) truncate_html (= 0.9.2) - spree_frontend (2.0.13) + spree_frontend (2.0.4) canonical-rails deface (>= 0.9.0) jquery-rails (~> 3.0.0) rails (~> 3.2.13) - spree_api (= 2.0.13) - spree_core (= 2.0.13) + spree_api (= 2.0.4) + spree_core (= 2.0.4) stringex (~> 1.5.1) - spree_sample (2.0.13) - spree_core (= 2.0.13) + spree_sample (2.0.4) + spree_core (= 2.0.4) sprockets (2.2.3) hike (~> 1.2) multi_json (~> 1.0) @@ -674,11 +675,10 @@ GEM rack unicorn uuidtools (2.1.5) - versioncake (1.2.0) - actionpack (>= 3.2) - activesupport (>= 3.2) - railties (>= 3.2) - tzinfo + versioncake (1.0.0) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) warden (1.2.7) rack (>= 1.0) webmock (1.8.11) @@ -781,7 +781,7 @@ DEPENDENCIES simple_form! skylight (< 2.0) spinjs-rails - spree (= 2.0.13) + spree (= 2.0.4) spree_auth_devise! spree_i18n! spree_paypal_express! From 97e8adf7a712416c82131d19c79357b5d1e581c9 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Thu, 26 Apr 2018 16:26:00 +0200 Subject: [PATCH 08/42] Use OFN's Spree fork of 2.0.4 to get fixes We encountered the bug that https://github.com/spree/spree/commit/3fd1535e75d383fa7119d2f3b985f8c12731302c fixes, which is needed to boot the app using Spree 2.0.4. This stems from https://github.com/openfoodfoundation/openfoodnetwork/issues/2236#issuecomment-384633612 --- Gemfile | 7 +++- Gemfile.lock | 110 +++++++++++++++++++++++++++------------------------ 2 files changed, 64 insertions(+), 53 deletions(-) diff --git a/Gemfile b/Gemfile index aa3376f9792..91d0d9ad8af 100644 --- a/Gemfile +++ b/Gemfile @@ -11,7 +11,12 @@ gem 'i18n-js', '~> 3.0.0' gem 'nokogiri', '>= 1.6.7.1' gem 'pg' -gem 'spree', '2.0.4' + +# OFN-maintained and patched version of Spree v2.0.4. See +# https://github.com/openfoodfoundation/openfoodnetwork/wiki/Spree-2.0-upgrade +# for details. +gem 'spree', github: 'coopdevs/spree', branch: '2-0-4-stable' + gem 'spree_i18n', github: 'spree/spree_i18n', branch: '1-3-stable' gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-0-stable' diff --git a/Gemfile.lock b/Gemfile.lock index 4838cbf3454..b274d0b7205 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,6 +6,63 @@ GIT actionpack (~> 3.0) activemodel (~> 3.0) +GIT + remote: https://github.com/coopdevs/spree.git + revision: 6c3d8841018de80f41c9400611de2e8a51923711 + branch: 2-0-4-stable + specs: + spree (2.0.4) + spree_api (= 2.0.4) + spree_backend (= 2.0.4) + spree_cmd (= 2.0.4) + spree_core (= 2.0.4) + spree_frontend (= 2.0.4) + spree_sample (= 2.0.4) + spree_api (2.0.4) + rabl (= 0.8.4) + spree_core (= 2.0.4) + versioncake (= 1.0.0) + spree_backend (2.0.4) + deface (>= 0.9.0) + jquery-rails (~> 3.0.0) + jquery-ui-rails (~> 4.0.0) + rails (~> 3.2.8) + select2-rails (~> 3.4.7) + spree_api (= 2.0.4) + spree_core (= 2.0.4) + spree_cmd (2.0.4) + thor (>= 0.14.6) + spree_core (2.0.4) + activemerchant (~> 1.34) + acts_as_list (= 0.2.0) + awesome_nested_set (= 2.1.5) + aws-sdk (~> 1.3.4) + cancan (~> 1.6.10) + deface (>= 0.9.1) + ffaker (~> 1.16) + highline (= 1.6.18) + httparty (~> 0.11) + json (>= 1.7.7) + kaminari (~> 0.14.1) + money (= 5.1.1) + paperclip (~> 3.4.1) + paranoia (~> 1.3) + rails (~> 3.2.14) + ransack (= 0.7.2) + state_machine (= 1.2.0) + stringex (~> 1.5.1) + truncate_html (= 0.9.2) + spree_frontend (2.0.4) + canonical-rails + deface (>= 0.9.0) + jquery-rails (~> 3.0.0) + rails (~> 3.2.13) + spree_api (= 2.0.4) + spree_core (= 2.0.4) + stringex (~> 1.5.1) + spree_sample (2.0.4) + spree_core (= 2.0.4) + GIT remote: https://github.com/jeremydurham/custom-err-msg.git revision: 3a8ec9dddc7a5b0aab7c69a6060596de300c68f4 @@ -589,57 +646,6 @@ GEM activesupport (>= 3.0.0) spinjs-rails (1.3) rails (>= 3.1) - spree (2.0.4) - spree_api (= 2.0.4) - spree_backend (= 2.0.4) - spree_cmd (= 2.0.4) - spree_core (= 2.0.4) - spree_frontend (= 2.0.4) - spree_sample (= 2.0.4) - spree_api (2.0.4) - rabl (= 0.8.4) - spree_core (= 2.0.4) - versioncake (= 1.0.0) - spree_backend (2.0.4) - deface (>= 0.9.0) - jquery-rails (~> 3.0.0) - jquery-ui-rails (~> 4.0.0) - rails (~> 3.2.8) - select2-rails (~> 3.4.7) - spree_api (= 2.0.4) - spree_core (= 2.0.4) - spree_cmd (2.0.4) - thor (>= 0.14.6) - spree_core (2.0.4) - activemerchant (~> 1.34) - acts_as_list (= 0.2.0) - awesome_nested_set (= 2.1.5) - aws-sdk (~> 1.3.4) - cancan (~> 1.6.10) - deface (>= 0.9.1) - ffaker (~> 1.16) - highline (= 1.6.18) - httparty (~> 0.11) - json (>= 1.7.7) - kaminari (~> 0.14.1) - money (= 5.1.1) - paperclip (~> 3.4.1) - paranoia (~> 1.3) - rails (~> 3.2.14) - ransack (= 0.7.2) - state_machine (= 1.2.0) - stringex (~> 1.5.1) - truncate_html (= 0.9.2) - spree_frontend (2.0.4) - canonical-rails - deface (>= 0.9.0) - jquery-rails (~> 3.0.0) - rails (~> 3.2.13) - spree_api (= 2.0.4) - spree_core (= 2.0.4) - stringex (~> 1.5.1) - spree_sample (2.0.4) - spree_core (= 2.0.4) sprockets (2.2.3) hike (~> 1.2) multi_json (~> 1.0) @@ -781,7 +787,7 @@ DEPENDENCIES simple_form! skylight (< 2.0) spinjs-rails - spree (= 2.0.4) + spree! spree_auth_devise! spree_i18n! spree_paypal_express! From 19870eccdce3e36f3181358db7f67b733facc614 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Thu, 26 Apr 2018 16:59:34 +0200 Subject: [PATCH 09/42] Install and run Spree v2.0.4 migrations --- ...26145630_create_spree_stock_items.spree.rb | 15 ++ ...5631_create_spree_stock_locations.spree.rb | 12 ++ ...180426145632_create_default_stock.spree.rb | 27 ++++ ...ck_location_id_to_spree_shipments.spree.rb | 6 + ...634_add_pending_to_inventory_unit.spree.rb | 7 + ...n_demand_from_product_and_variant.spree.rb | 7 + ...45636_create_shipping_method_zone.spree.rb | 23 +++ ..._category_id_from_shipping_method.spree.rb | 6 + ...create_shipping_method_categories.spree.rb | 14 ++ ...45639_create_spree_shipping_rates.spree.rb | 25 ++++ ...h_attributes_from_shipping_method.spree.rb | 8 ++ ...0426145641_create_stock_movements.spree.rb | 13 ++ ..._address_fields_to_stock_location.spree.rb | 23 +++ ...d_active_field_to_stock_locations.spree.rb | 6 + ...4_add_backorderable_to_stock_item.spree.rb | 6 + ...efault_quantity_to_stock_movement.spree.rb | 6 + ...nd_destination_to_stock_movements.spree.rb | 9 ++ ..._add_originator_to_stock_movement.spree.rb | 8 ++ ...d_destination_from_stock_movement.spree.rb | 16 +++ ...te_inventory_unit_sold_to_on_hand.spree.rb | 10 ++ ...6145650_add_stock_location_to_rma.spree.rb | 6 + ...hipment_state_for_canceled_orders.spree.rb | 16 +++ ...emove_stock_item_and_variant_lock.spree.rb | 15 ++ ...3_add_shipping_rates_to_shipments.spree.rb | 16 +++ ...5654_create_spree_stock_transfers.spree.rb | 15 ++ ...45655_drop_products_count_on_hand.spree.rb | 6 + ...56_set_default_shipping_rate_cost.spree.rb | 6 + ...5657_add_number_to_stock_transfer.spree.rb | 24 ++++ ...8_add_sku_index_to_spree_variants.spree.rb | 6 + ...e_default_to_spree_stock_location.spree.rb | 6 + ..._variants_to_spree_stock_location.spree.rb | 6 + ...s_to_spree_shipping_methods_zones.spree.rb | 6 + ...add_deleted_at_to_spree_tax_rates.spree.rb | 6 + ...lock_version_from_inventory_units.spree.rb | 7 + ...45664_add_cost_price_to_line_item.spree.rb | 6 + ...backorderable_to_default_to_false.spree.rb | 7 + ...add_created_by_id_to_spree_orders.spree.rb | 6 + ...ndex_completed_at_on_spree_orders.spree.rb | 6 + ...x_category_id_to_spree_line_items.spree.rb | 6 + ...rate_tax_categories_to_line_items.spree.rb | 10 ++ db/schema.rb | 133 ++++++++++++++---- 41 files changed, 533 insertions(+), 29 deletions(-) create mode 100644 db/migrate/20180426145630_create_spree_stock_items.spree.rb create mode 100644 db/migrate/20180426145631_create_spree_stock_locations.spree.rb create mode 100644 db/migrate/20180426145632_create_default_stock.spree.rb create mode 100644 db/migrate/20180426145633_add_stock_location_id_to_spree_shipments.spree.rb create mode 100644 db/migrate/20180426145634_add_pending_to_inventory_unit.spree.rb create mode 100644 db/migrate/20180426145635_remove_on_demand_from_product_and_variant.spree.rb create mode 100644 db/migrate/20180426145636_create_shipping_method_zone.spree.rb create mode 100644 db/migrate/20180426145637_remove_shipping_category_id_from_shipping_method.spree.rb create mode 100644 db/migrate/20180426145638_create_shipping_method_categories.spree.rb create mode 100644 db/migrate/20180426145639_create_spree_shipping_rates.spree.rb create mode 100644 db/migrate/20180426145640_remove_category_match_attributes_from_shipping_method.spree.rb create mode 100644 db/migrate/20180426145641_create_stock_movements.spree.rb create mode 100644 db/migrate/20180426145642_add_address_fields_to_stock_location.spree.rb create mode 100644 db/migrate/20180426145643_add_active_field_to_stock_locations.spree.rb create mode 100644 db/migrate/20180426145644_add_backorderable_to_stock_item.spree.rb create mode 100644 db/migrate/20180426145645_add_default_quantity_to_stock_movement.spree.rb create mode 100644 db/migrate/20180426145646_add_source_and_destination_to_stock_movements.spree.rb create mode 100644 db/migrate/20180426145647_add_originator_to_stock_movement.spree.rb create mode 100644 db/migrate/20180426145648_drop_source_and_destination_from_stock_movement.spree.rb create mode 100644 db/migrate/20180426145649_migrate_inventory_unit_sold_to_on_hand.spree.rb create mode 100644 db/migrate/20180426145650_add_stock_location_to_rma.spree.rb create mode 100644 db/migrate/20180426145651_update_shipment_state_for_canceled_orders.spree.rb create mode 100644 db/migrate/20180426145652_remove_stock_item_and_variant_lock.spree.rb create mode 100644 db/migrate/20180426145653_add_shipping_rates_to_shipments.spree.rb create mode 100644 db/migrate/20180426145654_create_spree_stock_transfers.spree.rb create mode 100644 db/migrate/20180426145655_drop_products_count_on_hand.spree.rb create mode 100644 db/migrate/20180426145656_set_default_shipping_rate_cost.spree.rb create mode 100644 db/migrate/20180426145657_add_number_to_stock_transfer.spree.rb create mode 100644 db/migrate/20180426145658_add_sku_index_to_spree_variants.spree.rb create mode 100644 db/migrate/20180426145659_add_backorderable_default_to_spree_stock_location.spree.rb create mode 100644 db/migrate/20180426145660_add_propage_all_variants_to_spree_stock_location.spree.rb create mode 100644 db/migrate/20180426145661_rename_shipping_methods_zones_to_spree_shipping_methods_zones.spree.rb create mode 100644 db/migrate/20180426145662_add_deleted_at_to_spree_tax_rates.spree.rb create mode 100644 db/migrate/20180426145663_remove_lock_version_from_inventory_units.spree.rb create mode 100644 db/migrate/20180426145664_add_cost_price_to_line_item.spree.rb create mode 100644 db/migrate/20180426145665_set_backorderable_to_default_to_false.spree.rb create mode 100644 db/migrate/20180426145666_add_created_by_id_to_spree_orders.spree.rb create mode 100644 db/migrate/20180426145667_index_completed_at_on_spree_orders.spree.rb create mode 100644 db/migrate/20180426145668_add_tax_category_id_to_spree_line_items.spree.rb create mode 100644 db/migrate/20180426145669_migrate_tax_categories_to_line_items.spree.rb diff --git a/db/migrate/20180426145630_create_spree_stock_items.spree.rb b/db/migrate/20180426145630_create_spree_stock_items.spree.rb new file mode 100644 index 00000000000..cd6f349740f --- /dev/null +++ b/db/migrate/20180426145630_create_spree_stock_items.spree.rb @@ -0,0 +1,15 @@ +# This migration comes from spree (originally 20130211190146) +class CreateSpreeStockItems < ActiveRecord::Migration + def change + create_table :spree_stock_items do |t| + t.belongs_to :stock_location + t.belongs_to :variant + t.integer :count_on_hand, null: false, default: 0 + t.integer :lock_version + + t.timestamps + end + add_index :spree_stock_items, :stock_location_id + add_index :spree_stock_items, [:stock_location_id, :variant_id], :name => 'stock_item_by_loc_and_var_id' + end +end diff --git a/db/migrate/20180426145631_create_spree_stock_locations.spree.rb b/db/migrate/20180426145631_create_spree_stock_locations.spree.rb new file mode 100644 index 00000000000..a3e4d1a4dc8 --- /dev/null +++ b/db/migrate/20180426145631_create_spree_stock_locations.spree.rb @@ -0,0 +1,12 @@ +# This migration comes from spree (originally 20130211191120) +class CreateSpreeStockLocations < ActiveRecord::Migration + def change + create_table :spree_stock_locations do |t| + t.string :name + t.belongs_to :address + + t.timestamps + end + add_index :spree_stock_locations, :address_id + end +end diff --git a/db/migrate/20180426145632_create_default_stock.spree.rb b/db/migrate/20180426145632_create_default_stock.spree.rb new file mode 100644 index 00000000000..b1fc601078f --- /dev/null +++ b/db/migrate/20180426145632_create_default_stock.spree.rb @@ -0,0 +1,27 @@ +# This migration comes from spree (originally 20130213191427) +class CreateDefaultStock < ActiveRecord::Migration + def up + Spree::StockLocation.skip_callback(:create, :after, :create_stock_items) + Spree::StockItem.skip_callback(:save, :after, :process_backorders) + location = Spree::StockLocation.create(name: 'default') + Spree::Variant.all.each do |variant| + stock_item = location.stock_items.build(variant: variant) + stock_item.send(:count_on_hand=, variant.count_on_hand) + stock_item.save! + end + + remove_column :spree_variants, :count_on_hand + end + + def down + add_column :spree_variants, :count_on_hand, :integer + + Spree::StockItem.all.each do |stock_item| + stock_item.variant.update_column :count_on_hand, stock_item.count_on_hand + end + + Spree::StockLocation.delete_all + Spree::StockItem.delete_all + end +end + diff --git a/db/migrate/20180426145633_add_stock_location_id_to_spree_shipments.spree.rb b/db/migrate/20180426145633_add_stock_location_id_to_spree_shipments.spree.rb new file mode 100644 index 00000000000..e102d7febb2 --- /dev/null +++ b/db/migrate/20180426145633_add_stock_location_id_to_spree_shipments.spree.rb @@ -0,0 +1,6 @@ +# This migration comes from spree (originally 20130226191231) +class AddStockLocationIdToSpreeShipments < ActiveRecord::Migration + def change + add_column :spree_shipments, :stock_location_id, :integer + end +end diff --git a/db/migrate/20180426145634_add_pending_to_inventory_unit.spree.rb b/db/migrate/20180426145634_add_pending_to_inventory_unit.spree.rb new file mode 100644 index 00000000000..c3879d3604c --- /dev/null +++ b/db/migrate/20180426145634_add_pending_to_inventory_unit.spree.rb @@ -0,0 +1,7 @@ +# This migration comes from spree (originally 20130227143905) +class AddPendingToInventoryUnit < ActiveRecord::Migration + def change + add_column :spree_inventory_units, :pending, :boolean, :default => true + Spree::InventoryUnit.update_all(:pending => false) + end +end diff --git a/db/migrate/20180426145635_remove_on_demand_from_product_and_variant.spree.rb b/db/migrate/20180426145635_remove_on_demand_from_product_and_variant.spree.rb new file mode 100644 index 00000000000..72ac77b9ec3 --- /dev/null +++ b/db/migrate/20180426145635_remove_on_demand_from_product_and_variant.spree.rb @@ -0,0 +1,7 @@ +# This migration comes from spree (originally 20130228164411) +class RemoveOnDemandFromProductAndVariant < ActiveRecord::Migration + def change + remove_column :spree_products, :on_demand + remove_column :spree_variants, :on_demand + end +end diff --git a/db/migrate/20180426145636_create_shipping_method_zone.spree.rb b/db/migrate/20180426145636_create_shipping_method_zone.spree.rb new file mode 100644 index 00000000000..2d99447b139 --- /dev/null +++ b/db/migrate/20180426145636_create_shipping_method_zone.spree.rb @@ -0,0 +1,23 @@ +# This migration comes from spree (originally 20130228210442) +class CreateShippingMethodZone < ActiveRecord::Migration + def up + create_table :shipping_methods_zones, :id => false do |t| + t.integer :shipping_method_id + t.integer :zone_id + end + # This association has been corrected in a latter migration + # but when this database migration runs, the table is still incorrectly named + # 'shipping_methods_zones' instead of 'spre_shipping_methods_zones' + Spree::ShippingMethod.has_and_belongs_to_many :zones, :join_table => 'shipping_methods_zones', + :class_name => 'Spree::Zone', + :foreign_key => 'shipping_method_id' + Spree::ShippingMethod.all.each{|sm| sm.zones << Spree::Zone.find(sm.zone_id)} + + remove_column :spree_shipping_methods, :zone_id + end + + def down + drop_table :shipping_methods_zones + add_column :spree_shipping_methods, :zone_id, :integer + end +end diff --git a/db/migrate/20180426145637_remove_shipping_category_id_from_shipping_method.spree.rb b/db/migrate/20180426145637_remove_shipping_category_id_from_shipping_method.spree.rb new file mode 100644 index 00000000000..f686ac4aa7b --- /dev/null +++ b/db/migrate/20180426145637_remove_shipping_category_id_from_shipping_method.spree.rb @@ -0,0 +1,6 @@ +# This migration comes from spree (originally 20130301162745) +class RemoveShippingCategoryIdFromShippingMethod < ActiveRecord::Migration + def change + remove_column :spree_shipping_methods, :shipping_category_id + end +end diff --git a/db/migrate/20180426145638_create_shipping_method_categories.spree.rb b/db/migrate/20180426145638_create_shipping_method_categories.spree.rb new file mode 100644 index 00000000000..2af03a7ec04 --- /dev/null +++ b/db/migrate/20180426145638_create_shipping_method_categories.spree.rb @@ -0,0 +1,14 @@ +# This migration comes from spree (originally 20130301162924) +class CreateShippingMethodCategories < ActiveRecord::Migration + def change + create_table :spree_shipping_method_categories do |t| + t.integer :shipping_method_id, :null => false + t.integer :shipping_category_id, :null => false + + t.timestamps + end + + add_index :spree_shipping_method_categories, :shipping_method_id + add_index :spree_shipping_method_categories, :shipping_category_id + end +end diff --git a/db/migrate/20180426145639_create_spree_shipping_rates.spree.rb b/db/migrate/20180426145639_create_spree_shipping_rates.spree.rb new file mode 100644 index 00000000000..f2932a57b31 --- /dev/null +++ b/db/migrate/20180426145639_create_spree_shipping_rates.spree.rb @@ -0,0 +1,25 @@ +# This migration comes from spree (originally 20130304162240) +class CreateSpreeShippingRates < ActiveRecord::Migration + def up + create_table :spree_shipping_rates do |t| + t.belongs_to :shipment + t.belongs_to :shipping_method + t.boolean :selected, :default => false + t.decimal :cost, :precision => 8, :scale => 2 + t.timestamps + end + add_index(:spree_shipping_rates, [:shipment_id, :shipping_method_id], + :name => 'spree_shipping_rates_join_index', + :unique => true) + + # Spree::Shipment.all.each do |shipment| + # shipping_method = Spree::ShippingMethod.find(shipment.shipment_method_id) + # shipment.add_shipping_method(shipping_method, true) + # end + end + + def down + # add_column :spree_shipments, :shipping_method_id, :integer + drop_table :spree_shipping_rates + end +end diff --git a/db/migrate/20180426145640_remove_category_match_attributes_from_shipping_method.spree.rb b/db/migrate/20180426145640_remove_category_match_attributes_from_shipping_method.spree.rb new file mode 100644 index 00000000000..1562aecdb2b --- /dev/null +++ b/db/migrate/20180426145640_remove_category_match_attributes_from_shipping_method.spree.rb @@ -0,0 +1,8 @@ +# This migration comes from spree (originally 20130304192936) +class RemoveCategoryMatchAttributesFromShippingMethod < ActiveRecord::Migration + def change + remove_column :spree_shipping_methods, :match_none + remove_column :spree_shipping_methods, :match_one + remove_column :spree_shipping_methods, :match_all + end +end diff --git a/db/migrate/20180426145641_create_stock_movements.spree.rb b/db/migrate/20180426145641_create_stock_movements.spree.rb new file mode 100644 index 00000000000..d7c8cb88d35 --- /dev/null +++ b/db/migrate/20180426145641_create_stock_movements.spree.rb @@ -0,0 +1,13 @@ +# This migration comes from spree (originally 20130305143310) +class CreateStockMovements < ActiveRecord::Migration + def change + create_table :spree_stock_movements do |t| + t.belongs_to :stock_item + t.integer :quantity + t.string :action + + t.timestamps + end + add_index :spree_stock_movements, :stock_item_id + end +end diff --git a/db/migrate/20180426145642_add_address_fields_to_stock_location.spree.rb b/db/migrate/20180426145642_add_address_fields_to_stock_location.spree.rb new file mode 100644 index 00000000000..4a16efeb406 --- /dev/null +++ b/db/migrate/20180426145642_add_address_fields_to_stock_location.spree.rb @@ -0,0 +1,23 @@ +# This migration comes from spree (originally 20130306181701) +class AddAddressFieldsToStockLocation < ActiveRecord::Migration + def change + remove_column :spree_stock_locations, :address_id + + add_column :spree_stock_locations, :address1, :string + add_column :spree_stock_locations, :address2, :string + add_column :spree_stock_locations, :city, :string + add_column :spree_stock_locations, :state_id, :integer + add_column :spree_stock_locations, :state_name, :string + add_column :spree_stock_locations, :country_id, :integer + add_column :spree_stock_locations, :zipcode, :string + add_column :spree_stock_locations, :phone, :string + + + usa = Spree::Country.where(:iso => 'US').first + # In case USA isn't found. + # See #3115 + country = usa || Spree::Country.first + Spree::Country.reset_column_information + Spree::StockLocation.update_all(:country_id => country) + end +end diff --git a/db/migrate/20180426145643_add_active_field_to_stock_locations.spree.rb b/db/migrate/20180426145643_add_active_field_to_stock_locations.spree.rb new file mode 100644 index 00000000000..0e69642de23 --- /dev/null +++ b/db/migrate/20180426145643_add_active_field_to_stock_locations.spree.rb @@ -0,0 +1,6 @@ +# This migration comes from spree (originally 20130306191917) +class AddActiveFieldToStockLocations < ActiveRecord::Migration + def change + add_column :spree_stock_locations, :active, :boolean, :default => true + end +end diff --git a/db/migrate/20180426145644_add_backorderable_to_stock_item.spree.rb b/db/migrate/20180426145644_add_backorderable_to_stock_item.spree.rb new file mode 100644 index 00000000000..839e3b3d090 --- /dev/null +++ b/db/migrate/20180426145644_add_backorderable_to_stock_item.spree.rb @@ -0,0 +1,6 @@ +# This migration comes from spree (originally 20130306195650) +class AddBackorderableToStockItem < ActiveRecord::Migration + def change + add_column :spree_stock_items, :backorderable, :boolean, :default => true + end +end diff --git a/db/migrate/20180426145645_add_default_quantity_to_stock_movement.spree.rb b/db/migrate/20180426145645_add_default_quantity_to_stock_movement.spree.rb new file mode 100644 index 00000000000..c991b94e4aa --- /dev/null +++ b/db/migrate/20180426145645_add_default_quantity_to_stock_movement.spree.rb @@ -0,0 +1,6 @@ +# This migration comes from spree (originally 20130307161754) +class AddDefaultQuantityToStockMovement < ActiveRecord::Migration + def change + change_column :spree_stock_movements, :quantity, :integer, :default => 0 + end +end diff --git a/db/migrate/20180426145646_add_source_and_destination_to_stock_movements.spree.rb b/db/migrate/20180426145646_add_source_and_destination_to_stock_movements.spree.rb new file mode 100644 index 00000000000..7e0f0987b79 --- /dev/null +++ b/db/migrate/20180426145646_add_source_and_destination_to_stock_movements.spree.rb @@ -0,0 +1,9 @@ +# This migration comes from spree (originally 20130318151756) +class AddSourceAndDestinationToStockMovements < ActiveRecord::Migration + def change + change_table :spree_stock_movements do |t| + t.references :source, polymorphic: true + t.references :destination, polymorphic: true + end + end +end diff --git a/db/migrate/20180426145647_add_originator_to_stock_movement.spree.rb b/db/migrate/20180426145647_add_originator_to_stock_movement.spree.rb new file mode 100644 index 00000000000..7c1a74679af --- /dev/null +++ b/db/migrate/20180426145647_add_originator_to_stock_movement.spree.rb @@ -0,0 +1,8 @@ +# This migration comes from spree (originally 20130319183250) +class AddOriginatorToStockMovement < ActiveRecord::Migration + def change + change_table :spree_stock_movements do |t| + t.references :originator, polymorphic: true + end + end +end diff --git a/db/migrate/20180426145648_drop_source_and_destination_from_stock_movement.spree.rb b/db/migrate/20180426145648_drop_source_and_destination_from_stock_movement.spree.rb new file mode 100644 index 00000000000..6735614f4e3 --- /dev/null +++ b/db/migrate/20180426145648_drop_source_and_destination_from_stock_movement.spree.rb @@ -0,0 +1,16 @@ +# This migration comes from spree (originally 20130319190507) +class DropSourceAndDestinationFromStockMovement < ActiveRecord::Migration + def up + change_table :spree_stock_movements do |t| + t.remove_references :source, :polymorphic => true + t.remove_references :destination, :polymorphic => true + end + end + + def down + change_table :spree_stock_movements do |t| + t.references :source, polymorphic: true + t.references :destination, polymorphic: true + end + end +end diff --git a/db/migrate/20180426145649_migrate_inventory_unit_sold_to_on_hand.spree.rb b/db/migrate/20180426145649_migrate_inventory_unit_sold_to_on_hand.spree.rb new file mode 100644 index 00000000000..4f759427ee9 --- /dev/null +++ b/db/migrate/20180426145649_migrate_inventory_unit_sold_to_on_hand.spree.rb @@ -0,0 +1,10 @@ +# This migration comes from spree (originally 20130325163316) +class MigrateInventoryUnitSoldToOnHand < ActiveRecord::Migration + def up + Spree::InventoryUnit.where(:state => 'sold').update_all(:state => 'on_hand') + end + + def down + Spree::InventoryUnit.where(:state => 'on_hand').update_all(:state => 'sold') + end +end diff --git a/db/migrate/20180426145650_add_stock_location_to_rma.spree.rb b/db/migrate/20180426145650_add_stock_location_to_rma.spree.rb new file mode 100644 index 00000000000..54d85f76a4a --- /dev/null +++ b/db/migrate/20180426145650_add_stock_location_to_rma.spree.rb @@ -0,0 +1,6 @@ +# This migration comes from spree (originally 20130326175857) +class AddStockLocationToRma < ActiveRecord::Migration + def change + add_column :spree_return_authorizations, :stock_location_id, :integer + end +end diff --git a/db/migrate/20180426145651_update_shipment_state_for_canceled_orders.spree.rb b/db/migrate/20180426145651_update_shipment_state_for_canceled_orders.spree.rb new file mode 100644 index 00000000000..f5c1b5a0cf6 --- /dev/null +++ b/db/migrate/20180426145651_update_shipment_state_for_canceled_orders.spree.rb @@ -0,0 +1,16 @@ +# This migration comes from spree (originally 20130328130308) +class UpdateShipmentStateForCanceledOrders < ActiveRecord::Migration + def up + shipments = Spree::Shipment.joins(:order). + where("spree_orders.state = 'canceled'") + case Spree::Shipment.connection.adapter_name + when "SQLite3" + shipments.update_all("state = 'cancelled'") + when "MySQL" || "PostgreSQL" + shipments.update_all("spree_shipments.state = 'cancelled'") + end + end + + def down + end +end diff --git a/db/migrate/20180426145652_remove_stock_item_and_variant_lock.spree.rb b/db/migrate/20180426145652_remove_stock_item_and_variant_lock.spree.rb new file mode 100644 index 00000000000..c522a765ccd --- /dev/null +++ b/db/migrate/20180426145652_remove_stock_item_and_variant_lock.spree.rb @@ -0,0 +1,15 @@ +# This migration comes from spree (originally 20130329134939) +class RemoveStockItemAndVariantLock < ActiveRecord::Migration + def up + # we are moving to pessimistic locking on stock_items + remove_column :spree_stock_items, :lock_version + + # variants no longer manage their count_on_hand so we are removing their lock + remove_column :spree_variants, :lock_version + end + + def down + add_column :spree_stock_items, :lock_version, :integer + add_column :spree_variants, :lock_version, :integer + end +end diff --git a/db/migrate/20180426145653_add_shipping_rates_to_shipments.spree.rb b/db/migrate/20180426145653_add_shipping_rates_to_shipments.spree.rb new file mode 100644 index 00000000000..a9ae3bd83d5 --- /dev/null +++ b/db/migrate/20180426145653_add_shipping_rates_to_shipments.spree.rb @@ -0,0 +1,16 @@ +# This migration comes from spree (originally 20130417123427) +class AddShippingRatesToShipments < ActiveRecord::Migration + def up + Spree::Shipment.all.each do |shipment| + shipment.shipping_rates.create(:shipping_method_id => shipment.shipping_method_id, + :cost => shipment.cost, + :selected => true) + end + + remove_column :spree_shipments, :shipping_method_id + end + + def down + add_column :spree_shipments, :shipping_method_id, :integer + end +end diff --git a/db/migrate/20180426145654_create_spree_stock_transfers.spree.rb b/db/migrate/20180426145654_create_spree_stock_transfers.spree.rb new file mode 100644 index 00000000000..1b73d9b1762 --- /dev/null +++ b/db/migrate/20180426145654_create_spree_stock_transfers.spree.rb @@ -0,0 +1,15 @@ +# This migration comes from spree (originally 20130418125341) +class CreateSpreeStockTransfers < ActiveRecord::Migration + def change + create_table :spree_stock_transfers do |t| + t.string :type + t.string :reference_number + t.integer :source_location_id + t.integer :destination_location_id + t.timestamps + end + + add_index :spree_stock_transfers, :source_location_id + add_index :spree_stock_transfers, :destination_location_id + end +end diff --git a/db/migrate/20180426145655_drop_products_count_on_hand.spree.rb b/db/migrate/20180426145655_drop_products_count_on_hand.spree.rb new file mode 100644 index 00000000000..29cb947a56e --- /dev/null +++ b/db/migrate/20180426145655_drop_products_count_on_hand.spree.rb @@ -0,0 +1,6 @@ +# This migration comes from spree (originally 20130423110707) +class DropProductsCountOnHand < ActiveRecord::Migration + def up + remove_column :spree_products, :count_on_hand + end +end diff --git a/db/migrate/20180426145656_set_default_shipping_rate_cost.spree.rb b/db/migrate/20180426145656_set_default_shipping_rate_cost.spree.rb new file mode 100644 index 00000000000..64b9ccb108c --- /dev/null +++ b/db/migrate/20180426145656_set_default_shipping_rate_cost.spree.rb @@ -0,0 +1,6 @@ +# This migration comes from spree (originally 20130423223847) +class SetDefaultShippingRateCost < ActiveRecord::Migration + def change + change_column :spree_shipping_rates, :cost, :decimal, default: 0, precision: 8, scale: 2 + end +end diff --git a/db/migrate/20180426145657_add_number_to_stock_transfer.spree.rb b/db/migrate/20180426145657_add_number_to_stock_transfer.spree.rb new file mode 100644 index 00000000000..cf06743da0a --- /dev/null +++ b/db/migrate/20180426145657_add_number_to_stock_transfer.spree.rb @@ -0,0 +1,24 @@ +# This migration comes from spree (originally 20130509115210) +class AddNumberToStockTransfer < ActiveRecord::Migration + def up + remove_index :spree_stock_transfers, :source_location_id + remove_index :spree_stock_transfers, :destination_location_id + + rename_column :spree_stock_transfers, :reference_number, :reference + add_column :spree_stock_transfers, :number, :string + + Spree::StockTransfer.all.each do |transfer| + transfer.send(:generate_stock_transfer_number) + transfer.save! + end + + add_index :spree_stock_transfers, :number + add_index :spree_stock_transfers, :source_location_id + add_index :spree_stock_transfers, :destination_location_id + end + + def down + rename_column :spree_stock_transfers, :reference, :reference_number + remove_column :spree_stock_transfers, :number, :string + end +end diff --git a/db/migrate/20180426145658_add_sku_index_to_spree_variants.spree.rb b/db/migrate/20180426145658_add_sku_index_to_spree_variants.spree.rb new file mode 100644 index 00000000000..cd089f846d7 --- /dev/null +++ b/db/migrate/20180426145658_add_sku_index_to_spree_variants.spree.rb @@ -0,0 +1,6 @@ +# This migration comes from spree (originally 20130514151929) +class AddSkuIndexToSpreeVariants < ActiveRecord::Migration + def change + add_index :spree_variants, :sku + end +end diff --git a/db/migrate/20180426145659_add_backorderable_default_to_spree_stock_location.spree.rb b/db/migrate/20180426145659_add_backorderable_default_to_spree_stock_location.spree.rb new file mode 100644 index 00000000000..29939c59e64 --- /dev/null +++ b/db/migrate/20180426145659_add_backorderable_default_to_spree_stock_location.spree.rb @@ -0,0 +1,6 @@ +# This migration comes from spree (originally 20130515180736) +class AddBackorderableDefaultToSpreeStockLocation < ActiveRecord::Migration + def change + add_column :spree_stock_locations, :backorderable_default, :boolean, default: true + end +end diff --git a/db/migrate/20180426145660_add_propage_all_variants_to_spree_stock_location.spree.rb b/db/migrate/20180426145660_add_propage_all_variants_to_spree_stock_location.spree.rb new file mode 100644 index 00000000000..bfc55eac56b --- /dev/null +++ b/db/migrate/20180426145660_add_propage_all_variants_to_spree_stock_location.spree.rb @@ -0,0 +1,6 @@ +# This migration comes from spree (originally 20130516151222) +class AddPropageAllVariantsToSpreeStockLocation < ActiveRecord::Migration + def change + add_column :spree_stock_locations, :propagate_all_variants, :boolean, default: true + end +end diff --git a/db/migrate/20180426145661_rename_shipping_methods_zones_to_spree_shipping_methods_zones.spree.rb b/db/migrate/20180426145661_rename_shipping_methods_zones_to_spree_shipping_methods_zones.spree.rb new file mode 100644 index 00000000000..5c7ee6dd952 --- /dev/null +++ b/db/migrate/20180426145661_rename_shipping_methods_zones_to_spree_shipping_methods_zones.spree.rb @@ -0,0 +1,6 @@ +# This migration comes from spree (originally 20130611054351) +class RenameShippingMethodsZonesToSpreeShippingMethodsZones < ActiveRecord::Migration + def change + rename_table :shipping_methods_zones, :spree_shipping_methods_zones + end +end diff --git a/db/migrate/20180426145662_add_deleted_at_to_spree_tax_rates.spree.rb b/db/migrate/20180426145662_add_deleted_at_to_spree_tax_rates.spree.rb new file mode 100644 index 00000000000..c804d9a1f70 --- /dev/null +++ b/db/migrate/20180426145662_add_deleted_at_to_spree_tax_rates.spree.rb @@ -0,0 +1,6 @@ +# This migration comes from spree (originally 20130708052307) +class AddDeletedAtToSpreeTaxRates < ActiveRecord::Migration + def change + add_column :spree_tax_rates, :deleted_at, :datetime + end +end diff --git a/db/migrate/20180426145663_remove_lock_version_from_inventory_units.spree.rb b/db/migrate/20180426145663_remove_lock_version_from_inventory_units.spree.rb new file mode 100644 index 00000000000..42c60bd3f36 --- /dev/null +++ b/db/migrate/20180426145663_remove_lock_version_from_inventory_units.spree.rb @@ -0,0 +1,7 @@ +# This migration comes from spree (originally 20130711200933) +class RemoveLockVersionFromInventoryUnits < ActiveRecord::Migration + def change + # we are moving to pessimistic locking on stock_items + remove_column :spree_inventory_units, :lock_version + end +end diff --git a/db/migrate/20180426145664_add_cost_price_to_line_item.spree.rb b/db/migrate/20180426145664_add_cost_price_to_line_item.spree.rb new file mode 100644 index 00000000000..d54222f5592 --- /dev/null +++ b/db/migrate/20180426145664_add_cost_price_to_line_item.spree.rb @@ -0,0 +1,6 @@ +# This migration comes from spree (originally 20130718042445) +class AddCostPriceToLineItem < ActiveRecord::Migration + def change + add_column :spree_line_items, :cost_price, :decimal, :precision => 8, :scale => 2 + end +end diff --git a/db/migrate/20180426145665_set_backorderable_to_default_to_false.spree.rb b/db/migrate/20180426145665_set_backorderable_to_default_to_false.spree.rb new file mode 100644 index 00000000000..a05f4279a44 --- /dev/null +++ b/db/migrate/20180426145665_set_backorderable_to_default_to_false.spree.rb @@ -0,0 +1,7 @@ +# This migration comes from spree (originally 20130718233855) +class SetBackorderableToDefaultToFalse < ActiveRecord::Migration + def change + change_column :spree_stock_items, :backorderable, :boolean, :default => false + change_column :spree_stock_locations, :backorderable_default, :boolean, :default => false + end +end diff --git a/db/migrate/20180426145666_add_created_by_id_to_spree_orders.spree.rb b/db/migrate/20180426145666_add_created_by_id_to_spree_orders.spree.rb new file mode 100644 index 00000000000..fe59c0fc212 --- /dev/null +++ b/db/migrate/20180426145666_add_created_by_id_to_spree_orders.spree.rb @@ -0,0 +1,6 @@ +# This migration comes from spree (originally 20130725031716) +class AddCreatedByIdToSpreeOrders < ActiveRecord::Migration + def change + add_column :spree_orders, :created_by_id, :integer + end +end diff --git a/db/migrate/20180426145667_index_completed_at_on_spree_orders.spree.rb b/db/migrate/20180426145667_index_completed_at_on_spree_orders.spree.rb new file mode 100644 index 00000000000..c4c279ca4cd --- /dev/null +++ b/db/migrate/20180426145667_index_completed_at_on_spree_orders.spree.rb @@ -0,0 +1,6 @@ +# This migration comes from spree (originally 20130729214043) +class IndexCompletedAtOnSpreeOrders < ActiveRecord::Migration + def change + add_index :spree_orders, :completed_at + end +end diff --git a/db/migrate/20180426145668_add_tax_category_id_to_spree_line_items.spree.rb b/db/migrate/20180426145668_add_tax_category_id_to_spree_line_items.spree.rb new file mode 100644 index 00000000000..2b7e1a51bc7 --- /dev/null +++ b/db/migrate/20180426145668_add_tax_category_id_to_spree_line_items.spree.rb @@ -0,0 +1,6 @@ +# This migration comes from spree (originally 20130802014537) +class AddTaxCategoryIdToSpreeLineItems < ActiveRecord::Migration + def change + add_column :spree_line_items, :tax_category_id, :integer + end +end diff --git a/db/migrate/20180426145669_migrate_tax_categories_to_line_items.spree.rb b/db/migrate/20180426145669_migrate_tax_categories_to_line_items.spree.rb new file mode 100644 index 00000000000..80a82ea1af2 --- /dev/null +++ b/db/migrate/20180426145669_migrate_tax_categories_to_line_items.spree.rb @@ -0,0 +1,10 @@ +# This migration comes from spree (originally 20130802022321) +class MigrateTaxCategoriesToLineItems < ActiveRecord::Migration + def change + Spree::LineItem.includes(:variant => { :product => :tax_category }).find_in_batches do |line_items| + line_items.each do |line_item| + line_item.update_column(:tax_category_id, line_item.product.tax_category.id) + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index cdad7c28076..8ce0862f949 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20180316034336) do +ActiveRecord::Schema.define(:version => 20180426145669) do create_table "account_invoices", :force => true do |t| t.integer "user_id", :null => false @@ -514,14 +514,14 @@ end create_table "spree_inventory_units", :force => true do |t| - t.integer "lock_version", :default => 0 t.string "state" t.integer "variant_id" t.integer "order_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.integer "shipment_id" t.integer "return_authorization_id" + t.boolean "pending", :default => true end add_index "spree_inventory_units", ["order_id"], :name => "index_inventory_units_on_order_id" @@ -540,6 +540,8 @@ t.decimal "distribution_fee", :precision => 10, :scale => 2 t.string "shipping_method_name" t.decimal "final_weight_volume", :precision => 10, :scale => 2 + t.decimal "cost_price", :precision => 8, :scale => 2 + t.integer "tax_category_id" end add_index "spree_line_items", ["order_id"], :name => "index_line_items_on_order_id" @@ -621,8 +623,10 @@ t.string "last_ip_address" t.integer "cart_id" t.integer "customer_id" + t.integer "created_by_id" end + add_index "spree_orders", ["completed_at"], :name => "index_spree_orders_on_completed_at" add_index "spree_orders", ["customer_id"], :name => "index_spree_orders_on_customer_id" add_index "spree_orders", ["number"], :name => "index_orders_on_number" @@ -745,7 +749,7 @@ add_index "spree_product_scopes", ["product_group_id"], :name => "index_product_scopes_on_product_group_id" create_table "spree_products", :force => true do |t| - t.string "name", :default => "", :null => false + t.string "name", :default => "", :null => false t.text "description" t.datetime "available_on" t.datetime "deleted_at" @@ -754,19 +758,17 @@ t.string "meta_keywords" t.integer "tax_category_id" t.integer "shipping_category_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.integer "count_on_hand", :default => 0 + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.integer "supplier_id" t.boolean "group_buy" t.float "group_buy_unit_size" - t.boolean "on_demand", :default => false t.string "variant_unit" t.float "variant_unit_scale" t.string "variant_unit_name" t.text "notes" - t.integer "primary_taxon_id", :null => false - t.boolean "inherits_properties", :default => true, :null => false + t.integer "primary_taxon_id", :null => false + t.boolean "inherits_properties", :default => true, :null => false end add_index "spree_products", ["available_on"], :name => "index_products_on_available_on" @@ -845,11 +847,12 @@ create_table "spree_return_authorizations", :force => true do |t| t.string "number" t.string "state" - t.decimal "amount", :precision => 10, :scale => 2, :default => 0.0, :null => false + t.decimal "amount", :precision => 10, :scale => 2, :default => 0.0, :null => false t.integer "order_id" t.text "reason" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.integer "stock_location_id" end create_table "spree_roles", :force => true do |t| @@ -867,14 +870,14 @@ create_table "spree_shipments", :force => true do |t| t.string "tracking" t.string "number" - t.decimal "cost", :precision => 8, :scale => 2 + t.decimal "cost", :precision => 8, :scale => 2 t.datetime "shipped_at" t.integer "order_id" - t.integer "shipping_method_id" t.integer "address_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "state" + t.integer "stock_location_id" end add_index "spree_shipments", ["number"], :name => "index_shipments_on_number" @@ -887,22 +890,43 @@ t.boolean "temperature_controlled", :default => false, :null => false end + create_table "spree_shipping_method_categories", :force => true do |t| + t.integer "shipping_method_id", :null => false + t.integer "shipping_category_id", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + add_index "spree_shipping_method_categories", ["shipping_category_id"], :name => "index_spree_shipping_method_categories_on_shipping_category_id" + add_index "spree_shipping_method_categories", ["shipping_method_id"], :name => "index_spree_shipping_method_categories_on_shipping_method_id" + create_table "spree_shipping_methods", :force => true do |t| t.string "name" - t.integer "zone_id" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false t.string "display_on" - t.integer "shipping_category_id" - t.boolean "match_none" - t.boolean "match_all" - t.boolean "match_one" t.datetime "deleted_at" t.boolean "require_ship_address", :default => true t.text "description" t.string "tracking_url" end + create_table "spree_shipping_methods_zones", :id => false, :force => true do |t| + t.integer "shipping_method_id" + t.integer "zone_id" + end + + create_table "spree_shipping_rates", :force => true do |t| + t.integer "shipment_id" + t.integer "shipping_method_id" + t.boolean "selected", :default => false + t.decimal "cost", :precision => 8, :scale => 2, :default => 0.0 + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + add_index "spree_shipping_rates", ["shipment_id", "shipping_method_id"], :name => "spree_shipping_rates_join_index", :unique => true + create_table "spree_skrill_transactions", :force => true do |t| t.string "email" t.float "amount" @@ -931,6 +955,61 @@ t.integer "country_id" end + create_table "spree_stock_items", :force => true do |t| + t.integer "stock_location_id" + t.integer "variant_id" + t.integer "count_on_hand", :default => 0, :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.boolean "backorderable", :default => false + end + + add_index "spree_stock_items", ["stock_location_id", "variant_id"], :name => "stock_item_by_loc_and_var_id" + add_index "spree_stock_items", ["stock_location_id"], :name => "index_spree_stock_items_on_stock_location_id" + + create_table "spree_stock_locations", :force => true do |t| + t.string "name" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.string "address1" + t.string "address2" + t.string "city" + t.integer "state_id" + t.string "state_name" + t.integer "country_id" + t.string "zipcode" + t.string "phone" + t.boolean "active", :default => true + t.boolean "backorderable_default", :default => false + t.boolean "propagate_all_variants", :default => true + end + + create_table "spree_stock_movements", :force => true do |t| + t.integer "stock_item_id" + t.integer "quantity", :default => 0 + t.string "action" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.integer "originator_id" + t.string "originator_type" + end + + add_index "spree_stock_movements", ["stock_item_id"], :name => "index_spree_stock_movements_on_stock_item_id" + + create_table "spree_stock_transfers", :force => true do |t| + t.string "type" + t.string "reference" + t.integer "source_location_id" + t.integer "destination_location_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.string "number" + end + + add_index "spree_stock_transfers", ["destination_location_id"], :name => "index_spree_stock_transfers_on_destination_location_id" + add_index "spree_stock_transfers", ["number"], :name => "index_spree_stock_transfers_on_number" + add_index "spree_stock_transfers", ["source_location_id"], :name => "index_spree_stock_transfers_on_source_location_id" + create_table "spree_tax_categories", :force => true do |t| t.string "name" t.string "description" @@ -949,6 +1028,7 @@ t.boolean "included_in_price", :default => false t.string "name" t.boolean "show_rate_in_label", :default => true + t.datetime "deleted_at" end create_table "spree_taxonomies", :force => true do |t| @@ -1048,11 +1128,8 @@ t.datetime "deleted_at" t.boolean "is_master", :default => false t.integer "product_id" - t.integer "count_on_hand", :default => 0 t.decimal "cost_price", :precision => 8, :scale => 2 t.integer "position" - t.integer "lock_version", :default => 0 - t.boolean "on_demand", :default => false t.string "cost_currency" t.float "unit_value" t.string "unit_description", :default => "" @@ -1061,6 +1138,7 @@ end add_index "spree_variants", ["product_id"], :name => "index_variants_on_product_id" + add_index "spree_variants", ["sku"], :name => "index_spree_variants_on_sku" create_table "spree_zone_members", :force => true do |t| t.integer "zoneable_id" @@ -1331,9 +1409,6 @@ add_foreign_key "spree_shipments", "spree_addresses", name: "spree_shipments_address_id_fk", column: "address_id" add_foreign_key "spree_shipments", "spree_orders", name: "spree_shipments_order_id_fk", column: "order_id" - add_foreign_key "spree_shipping_methods", "spree_shipping_categories", name: "spree_shipping_methods_shipping_category_id_fk", column: "shipping_category_id" - add_foreign_key "spree_shipping_methods", "spree_zones", name: "spree_shipping_methods_zone_id_fk", column: "zone_id" - add_foreign_key "spree_state_changes", "spree_users", name: "spree_state_changes_user_id_fk", column: "user_id" add_foreign_key "spree_states", "spree_countries", name: "spree_states_country_id_fk", column: "country_id" From c3132e87d6d5b62bfb3ec6064a2cd0b993017ac2 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Mon, 30 Apr 2018 13:49:52 +0200 Subject: [PATCH 10/42] Rename and fix simple_product to base_product This factory has been merged into the base_product factory. Besides, products no longer have on_hand attribute. --- app/models/spree/product_decorator.rb | 1 - spec/factories.rb | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index 5f2eaab5f6c..06970f0a132 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -246,7 +246,6 @@ def ensure_standard_variant variant = self.master.dup variant.product = self variant.is_master = false - variant.on_demand = self.on_demand self.variants << variant end end diff --git a/spec/factories.rb b/spec/factories.rb index ebe8d05dd84..47319670553 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -460,7 +460,8 @@ factory :product do primary_taxon { Spree::Taxon.first || FactoryGirl.create(:taxon) } end - factory :simple_product do + + factory :base_product do # Fix product factory name sequence with Kernel.rand so it is not interpreted as a Spree::Product method # Pull request: https://github.com/spree/spree/pull/1964 # When this fix has been merged into a version of Spree that we're using, this line can be removed. @@ -468,7 +469,6 @@ supplier { Enterprise.is_primary_producer.first || FactoryGirl.create(:supplier_enterprise) } primary_taxon { Spree::Taxon.first || FactoryGirl.create(:taxon) } - on_hand 3 unit_value 1 unit_description '' From 6784621c1be10989894912b370c340f0bf776122 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Mon, 30 Apr 2018 13:53:23 +0200 Subject: [PATCH 11/42] Remove invalid spree config According to https://github.com/spree/spree/commit/5ef8dc67dffe8950805bb8a7c9acb62c76aa7a2f "Backorders can be configured now as per stock location or stock item". --- spec/spec_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0679613855f..4d6410ec11b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -114,7 +114,6 @@ def restart_phantomjs spree_config.currency = currency spree_config.shipping_instructions = true spree_config.auto_capture = true - spree_config.allow_backorders = false end Spree::Api::Config[:requires_authentication] = true From 776b5a23f6ea694ecc810eacfa182c4b2e9be034 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Mon, 30 Apr 2018 13:54:40 +0200 Subject: [PATCH 12/42] Skip methods that distributor can't use in Package This ensures that Spree's shipping methods take into account the ones the order's distributor uses. This reimplements what `#available_to_order_with_distributor_check?` used to do and it doesn't work with Spree 2.0.4. --- app/models/spree/shipping_method_decorator.rb | 6 --- app/models/stock/package.rb | 33 ++++++++++++ config/initializers/spree.rb | 2 + spec/models/stock/package_spec.rb | 51 +++++++++++++++++++ 4 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 app/models/stock/package.rb create mode 100644 spec/models/stock/package_spec.rb diff --git a/app/models/spree/shipping_method_decorator.rb b/app/models/spree/shipping_method_decorator.rb index a900f149366..6a512737bd1 100644 --- a/app/models/spree/shipping_method_decorator.rb +++ b/app/models/spree/shipping_method_decorator.rb @@ -42,12 +42,6 @@ def self.services ] end - def available_to_order_with_distributor_check?(order) - available_to_order_without_distributor_check?(order) && - self.distributors.include?(order.distributor) - end - alias_method_chain :available_to_order?, :distributor_check - def within_zone?(order) if order.ship_address zone && zone.include?(order.ship_address) diff --git a/app/models/stock/package.rb b/app/models/stock/package.rb new file mode 100644 index 00000000000..012e2265d4d --- /dev/null +++ b/app/models/stock/package.rb @@ -0,0 +1,33 @@ +# Extends Spree's Package implementation to skip shipping methods that are not +# valid for OFN. +# +# It requires the following configuration in config/initializers/spree.rb: +# +# Spree.config do |config| +# ... +# config.package_factory = Stock::Package +# end +# +module Stock + class Package < Spree::Stock::Package + # Skips the methods that are not used by the order's distributor + # + # @return [Array] + def shipping_methods + super.delete_if do |shipping_method| + !ships_with?(order.distributor, shipping_method) + end + end + + private + + # Checks whether the given distributor provides the specified shipping method + # + # @param distributor [Spree::Enterprise] + # @param shipping_method [Spree::ShippingMethod] + # @return [Boolean] + def ships_with?(distributor, shipping_method) + distributor.shipping_methods.include?(shipping_method) + end + end +end diff --git a/config/initializers/spree.rb b/config/initializers/spree.rb index 8495ec38241..77243c8ebbd 100644 --- a/config/initializers/spree.rb +++ b/config/initializers/spree.rb @@ -20,6 +20,8 @@ # Auto-capture payments. Without this option, payments must be manually captured in the paypal interface. config.auto_capture = true #config.override_actionmailer_config = false + + config.package_factory = Stock::Package end # TODO Work out why this is necessary diff --git a/spec/models/stock/package_spec.rb b/spec/models/stock/package_spec.rb new file mode 100644 index 00000000000..2c85b9b0793 --- /dev/null +++ b/spec/models/stock/package_spec.rb @@ -0,0 +1,51 @@ +require 'spec_helper' + +module Stock + describe Package do + describe '#shipping_methods' do + let(:stock_location) { double(:stock_location) } + let(:order) { build(:order) } + + subject(:package) { Package.new(stock_location, order, contents) } + + describe '#shipping_methods' do + let(:enterprise) { build(:enterprise) } + let(:other_enterprise) { build(:enterprise) } + + let(:order) { build(:order, distributor: enterprise) } + + let(:variant1) do + instance_double( + Spree::Variant, + shipping_category: shipping_method1.shipping_categories.first + ) + end + let(:variant2) do + instance_double( + Spree::Variant, + shipping_category: shipping_method2.shipping_categories.first + ) + end + let(:variant3) do + instance_double(Spree::Variant, shipping_category: nil) + end + + let(:contents) do + [ + Package::ContentItem.new(variant1, 1), + Package::ContentItem.new(variant1, 1), + Package::ContentItem.new(variant2, 1), + Package::ContentItem.new(variant3, 1) + ] + end + + let(:shipping_method1) { create(:shipping_method, distributors: [enterprise]) } + let(:shipping_method2) { create(:shipping_method, distributors: [other_enterprise]) } + + it 'does not return shipping methods not used by the package\'s order distributor' do + expect(package.shipping_methods).to eq [shipping_method1] + end + end + end + end +end From 5c260dae51b02560020a25642fd38da5d9e7747d Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Mon, 14 May 2018 12:30:11 +0200 Subject: [PATCH 13/42] Remove no longer valid tests `#available_to_order?` is gone in Spree 2.0 and our customization on top of it went away with #2256. --- spec/models/spree/shipping_method_spec.rb | 28 ----------------------- 1 file changed, 28 deletions(-) diff --git a/spec/models/spree/shipping_method_spec.rb b/spec/models/spree/shipping_method_spec.rb index bd759edcc7d..afb0ea59c4c 100644 --- a/spec/models/spree/shipping_method_spec.rb +++ b/spec/models/spree/shipping_method_spec.rb @@ -35,34 +35,6 @@ module Spree ShippingMethod.by_name.should == [sm2, sm3, sm1] end - - describe "availability" do - let(:sm) { create(:shipping_method) } - let(:currency) { 'AUD' } - - before do - sm.calculator.preferred_currency = currency - end - - it "is available to orders that match its distributor" do - o = create(:order, ship_address: create(:address), - distributor: sm.distributors.first, currency: currency) - sm.should be_available_to_order o - end - - it "is not available to orders that do not match its distributor" do - o = create(:order, ship_address: create(:address), - distributor: create(:distributor_enterprise), currency: currency) - sm.should_not be_available_to_order o - end - - it "is available to orders with no shipping address" do - o = create(:order, ship_address: nil, - distributor: sm.distributors.first, currency: currency) - sm.should be_available_to_order o - end - end - describe "finding services offered by all distributors" do let!(:d1) { create(:distributor_enterprise) } let!(:d2) { create(:distributor_enterprise) } From 6f8317b00704f8a05145f78816ae291043b5a64a Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Mon, 14 May 2018 12:48:15 +0200 Subject: [PATCH 14/42] Upgrade spree to point to 1c3dfc7fb This will fetch latest changes applied in the fork. It also changes the Github organization we fetch it from. From now on we'll work there and not in Coopdevs org. --- Gemfile | 2 +- Gemfile.lock | 44 +++++++++++++++++++------------------------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/Gemfile b/Gemfile index 91d0d9ad8af..c5872098669 100644 --- a/Gemfile +++ b/Gemfile @@ -15,7 +15,7 @@ gem 'pg' # OFN-maintained and patched version of Spree v2.0.4. See # https://github.com/openfoodfoundation/openfoodnetwork/wiki/Spree-2.0-upgrade # for details. -gem 'spree', github: 'coopdevs/spree', branch: '2-0-4-stable' +gem 'spree', github: 'openfoodfoundation/spree', branch: '2-0-4-stable' gem 'spree_i18n', github: 'spree/spree_i18n', branch: '1-3-stable' gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-0-stable' diff --git a/Gemfile.lock b/Gemfile.lock index b274d0b7205..eb41eed5b05 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,8 +7,22 @@ GIT activemodel (~> 3.0) GIT - remote: https://github.com/coopdevs/spree.git - revision: 6c3d8841018de80f41c9400611de2e8a51923711 + remote: https://github.com/jeremydurham/custom-err-msg.git + revision: 3a8ec9dddc7a5b0aab7c69a6060596de300c68f4 + specs: + custom_error_message (1.1.1) + +GIT + remote: https://github.com/openfoodfoundation/ofn-qz.git + revision: 60da2ae4c44cbb4c8d602f59fb5fff8d0f21db3c + ref: 60da2ae4c44cbb4c8d602f59fb5fff8d0f21db3c + specs: + ofn-qz (0.1.0) + railties (~> 3.1) + +GIT + remote: https://github.com/openfoodfoundation/spree.git + revision: 1c3dfc7fb48cde32f7dc49a59c1daf65a3ee6974 branch: 2-0-4-stable specs: spree (2.0.4) @@ -63,20 +77,6 @@ GIT spree_sample (2.0.4) spree_core (= 2.0.4) -GIT - remote: https://github.com/jeremydurham/custom-err-msg.git - revision: 3a8ec9dddc7a5b0aab7c69a6060596de300c68f4 - specs: - custom_error_message (1.1.1) - -GIT - remote: https://github.com/openfoodfoundation/ofn-qz.git - revision: 60da2ae4c44cbb4c8d602f59fb5fff8d0f21db3c - ref: 60da2ae4c44cbb4c8d602f59fb5fff8d0f21db3c - specs: - ofn-qz (0.1.0) - railties (~> 3.1) - GIT remote: https://github.com/spree-contrib/better_spree_paypal_express.git revision: 1206925d1c85bdc4b68b728d6676150ab0785486 @@ -137,16 +137,10 @@ GEM sprockets (~> 2.2.1) active_model_serializers (0.8.3) activemodel (>= 3.0) - active_utils (2.2.3) - activesupport (>= 2.3.11) - i18n - activemerchant (1.43.3) - active_utils (~> 2.0, >= 2.0.1) - activesupport (>= 2.3.14, < 5.0.0) + activemerchant (1.78.0) + activesupport (>= 3.2.14, < 6.x) builder (>= 2.1.2, < 4.0.0) - i18n (~> 0.5) - json (~> 1.7) - money (< 7.0.0) + i18n (>= 0.6.9) nokogiri (~> 1.4) activemodel (3.2.21) activesupport (= 3.2.21) From 32069cffe101193220b6e43320ae51a1de91413a Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Tue, 5 Jun 2018 18:42:19 +0200 Subject: [PATCH 15/42] Revert "Removing useless spaces" This reverts commit d81b6be25990b056ae57641e99bc673ed5db9fc9. --- app/controllers/base_controller.rb | 2 +- app/controllers/spree/orders_controller_decorator.rb | 8 ++++---- app/helpers/enterprises_helper.rb | 2 +- app/helpers/order_cycles_helper.rb | 2 +- app/helpers/shared_helper.rb | 2 +- app/helpers/spree/orders_helper.rb | 2 +- app/services/reset_order_service.rb | 2 +- app/views/spree/products/_add_to_cart.html.haml | 2 +- .../spree/products/_distributor_details.html.haml | 2 +- app/views/spree/products/_source.html.haml | 2 +- spec/controllers/checkout_controller_spec.rb | 2 +- spec/controllers/enterprises_controller_spec.rb | 2 +- spec/controllers/spree/checkout_controller_spec.rb | 2 +- spec/controllers/spree/orders_controller_spec.rb | 10 +++++----- spec/controllers/spree/paypal_controller_spec.rb | 2 +- spec/performance/orders_controller_spec.rb | 2 +- 16 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index 14f7e52371d..58a6c932b39 100644 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -37,7 +37,7 @@ def set_order_cycles # And default to the only order cycle if there's only the one if @order_cycles.count == 1 - current_order(create_order_if_necessary: true).set_order_cycle! @order_cycles.first + current_order( create_order_if_necessary: true ).set_order_cycle! @order_cycles.first end end end diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb index 739aad3a7de..2816ab6e26f 100644 --- a/app/controllers/spree/orders_controller_decorator.rb +++ b/app/controllers/spree/orders_controller_decorator.rb @@ -18,7 +18,7 @@ # Patching to redirect to shop if order is empty def edit - @order = current_order(create_order_if_necessary: true) + @order = current_order( create_order_if_necessary: true ) @insufficient_stock_lines = @order.insufficient_stock_lines if @order.line_items.empty? @@ -78,7 +78,7 @@ def populate # callbacks on Spree::Adjustment and then manually invoke Spree::Order#update! on success. Spree::Adjustment.without_callbacks do - populator = Spree::OrderPopulator.new(current_order(create_order_if_necessary: true), current_currency) + populator = Spree::OrderPopulator.new(current_order( create_order_if_necessary: true ), current_currency) if populator.populate(params.slice(:products, :variants, :quantity), true) fire_event('spree.cart.add') @@ -127,7 +127,7 @@ def li_stock_levels(order) end def update_distribution - @order = current_order(create_order_if_necessary: true) + @order = current_order( create_order_if_necessary: true ) if params[:commit] == 'Choose Hub' distributor = Enterprise.is_distributor.find params[:order][:distributor_id] @@ -159,7 +159,7 @@ def remove_missing_line_items(attrs) end def clear - @order = current_order(create_order_if_necessary: true) + @order = current_order( create_order_if_necessary: true ) @order.empty! @order.set_order_cycle! nil redirect_to main_app.enterprise_path(@order.distributor.id) diff --git a/app/helpers/enterprises_helper.rb b/app/helpers/enterprises_helper.rb index 549c86f5730..511c55df04e 100644 --- a/app/helpers/enterprises_helper.rb +++ b/app/helpers/enterprises_helper.rb @@ -2,7 +2,7 @@ module EnterprisesHelper def current_distributor - @current_distributor ||= current_order(create_order_if_necessary: false).andand.distributor + @current_distributor ||= current_order( create_order_if_necessary: false ).andand.distributor end def current_customer diff --git a/app/helpers/order_cycles_helper.rb b/app/helpers/order_cycles_helper.rb index 064582aba50..07a0ea488ac 100644 --- a/app/helpers/order_cycles_helper.rb +++ b/app/helpers/order_cycles_helper.rb @@ -1,6 +1,6 @@ module OrderCyclesHelper def current_order_cycle - @current_order_cycle ||= current_order(create_order_if_necessary: false).andand.order_cycle + @current_order_cycle ||= current_order( create_order_if_necessary: false ).andand.order_cycle end def permitted_enterprises_for(order_cycle) diff --git a/app/helpers/shared_helper.rb b/app/helpers/shared_helper.rb index bacf123814c..253dceacb50 100644 --- a/app/helpers/shared_helper.rb +++ b/app/helpers/shared_helper.rb @@ -1,6 +1,6 @@ module SharedHelper def distributor_link_class(distributor) - cart = current_order(create_order_if_necessary: true) + cart = current_order( create_order_if_necessary: true ) @active_distributors ||= Enterprise.distributors_with_active_order_cycles klass = "shop-distributor" diff --git a/app/helpers/spree/orders_helper.rb b/app/helpers/spree/orders_helper.rb index a37f4091994..12e90bd482c 100644 --- a/app/helpers/spree/orders_helper.rb +++ b/app/helpers/spree/orders_helper.rb @@ -1,7 +1,7 @@ module Spree module OrdersHelper def cart_is_empty - order = current_order(create_order_if_necessary: false) + order = current_order( create_order_if_necessary: false ) order.nil? || order.line_items.empty? end diff --git a/app/services/reset_order_service.rb b/app/services/reset_order_service.rb index 95e73290c91..3ffdf1ffb59 100644 --- a/app/services/reset_order_service.rb +++ b/app/services/reset_order_service.rb @@ -23,7 +23,7 @@ def call # Builds an order setting the token and distributor of the one specified def build_new_order - new_order = controller.current_order(create_order_if_necessary: true) + new_order = controller.current_order( create_order_if_necessary: true ) new_order.set_distributor!(distributor) new_order.tokenized_permission.token = token new_order.tokenized_permission.save! diff --git a/app/views/spree/products/_add_to_cart.html.haml b/app/views/spree/products/_add_to_cart.html.haml index dbc09929b70..e5d5248f2f7 100644 --- a/app/views/spree/products/_add_to_cart.html.haml +++ b/app/views/spree/products/_add_to_cart.html.haml @@ -1,5 +1,5 @@ .add-to-cart - - order = current_order(create_order_if_necessary: false) + - order = current_order( create_order_if_necessary: false ) - if product_out_of_stock = content_tag('strong', t(:out_of_stock)) diff --git a/app/views/spree/products/_distributor_details.html.haml b/app/views/spree/products/_distributor_details.html.haml index 1329a03f8a1..f044c622a70 100644 --- a/app/views/spree/products/_distributor_details.html.haml +++ b/app/views/spree/products/_distributor_details.html.haml @@ -2,7 +2,7 @@ %legend = t :products_distributor .distributor-details - - order = current_order(create_order_if_necessary: false) + - order = current_order( create_order_if_necessary: false ) - if order.andand.distributor.present? = render 'enterprises/distributor_details', :distributor => order.distributor - else diff --git a/app/views/spree/products/_source.html.haml b/app/views/spree/products/_source.html.haml index 461a4dc6c97..8c5ac66fe30 100644 --- a/app/views/spree/products/_source.html.haml +++ b/app/views/spree/products/_source.html.haml @@ -10,7 +10,7 @@ %h6.product-section-title= t(:distributors) %table#product-source.table-display{:width => "100%"} %tbody - - order = current_order(create_order_if_necessary: false) + - order = current_order( create_order_if_necessary: false ) - validator = DistributionChangeValidator.new(order) - Enterprise.distributing_products(@product).each do |distributor| - if !order.nil? && distributor == order.distributor diff --git a/spec/controllers/checkout_controller_spec.rb b/spec/controllers/checkout_controller_spec.rb index 5335b1f3871..151af21ae83 100644 --- a/spec/controllers/checkout_controller_spec.rb +++ b/spec/controllers/checkout_controller_spec.rb @@ -94,7 +94,7 @@ end it "sets the new order's token to the same as the old order" do - order = controller.current_order(create_order_if_necessary: true) + order = controller.current_order( create_order_if_necessary: true ) spree_post :update, order: {} expect(controller.current_order.token).to eq order.token end diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index bcd434302ec..d459c937fba 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -2,7 +2,7 @@ describe EnterprisesController, type: :controller do describe "shopping for a distributor" do - let(:order) { controller.current_order(create_order_if_necessary: true) } + let(:order) { controller.current_order( create_order_if_necessary: true ) } let!(:current_distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) } diff --git a/spec/controllers/spree/checkout_controller_spec.rb b/spec/controllers/spree/checkout_controller_spec.rb index 37bd483d559..47537e21330 100644 --- a/spec/controllers/spree/checkout_controller_spec.rb +++ b/spec/controllers/spree/checkout_controller_spec.rb @@ -5,7 +5,7 @@ describe Spree::CheckoutController, type: :controller do context 'rendering edit from within spree for the current checkout state' do - let(:order) { controller.current_order(create_order_if_necessary: true) } + let(:order) { controller.current_order( create_order_if_necessary: true ) } let(:user) { create(:user) } before do diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index ce15c8cacca..9574d5f41b2 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -30,7 +30,7 @@ it "redirects home with message if hub is not ready for checkout" do VariantOverride.stub(:indexed).and_return({}) - order = subject.current_order(create_order_if_necessary: true) + order = subject.current_order( create_order_if_necessary: true ) distributor.stub(:ready_for_checkout?) { false } order.stub(distributor: distributor, order_cycle: order_cycle) @@ -44,7 +44,7 @@ end describe "when an item has insufficient stock" do - let(:order) { subject.current_order(create_order_if_necessary: true) } + let(:order) { subject.current_order( create_order_if_necessary: true ) } let(:oc) { create(:simple_order_cycle, distributors: [d], variants: [variant]) } let(:d) { create(:distributor_enterprise, shipping_methods: [create(:shipping_method)], payment_methods: [create(:payment_method)]) } let(:variant) { create(:variant, on_demand: false, on_hand: 5) } @@ -129,7 +129,7 @@ distributor_product = create(:distributor_enterprise) p = create(:product, :distributors => [distributor_product], :group_buy => true) - order = subject.current_order(create_order_if_necessary: true) + order = subject.current_order( create_order_if_necessary: true ) order.stub(:distributor) { distributor_product } order.should_receive(:set_variant_attributes).with(p.master, {'max_quantity' => '3'}) controller.stub(:current_order).and_return(order) @@ -164,7 +164,7 @@ describe "removing line items from cart" do describe "when I pass params that includes a line item no longer in our cart" do it "should silently ignore the missing line item" do - order = subject.current_order(create_order_if_necessary: true) + order = subject.current_order( create_order_if_necessary: true ) li = order.add_variant(create(:simple_product, on_hand: 110).variants.first) spree_get :update, order: { line_items_attributes: { "0" => {quantity: "0", id: "9999"}, @@ -176,7 +176,7 @@ end it "filters line items that are missing from params" do - order = subject.current_order(create_order_if_necessary: true) + order = subject.current_order( create_order_if_necessary: true ) li = order.add_variant(create(:simple_product).master) attrs = { diff --git a/spec/controllers/spree/paypal_controller_spec.rb b/spec/controllers/spree/paypal_controller_spec.rb index 4843eef98df..4ce004183c6 100644 --- a/spec/controllers/spree/paypal_controller_spec.rb +++ b/spec/controllers/spree/paypal_controller_spec.rb @@ -9,7 +9,7 @@ module Spree end context 'when confirming' do - let(:previous_order) { controller.current_order(create_order_if_necessary: true) } + let(:previous_order) { controller.current_order( create_order_if_necessary: true ) } let(:payment_method) { create(:payment_method) } before do diff --git a/spec/performance/orders_controller_spec.rb b/spec/performance/orders_controller_spec.rb index ee856901217..58adf05540c 100644 --- a/spec/performance/orders_controller_spec.rb +++ b/spec/performance/orders_controller_spec.rb @@ -4,7 +4,7 @@ let(:distributor) { create(:distributor_enterprise) } let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], variants: products.map { |p| p.variants.first }) } let(:products) { (0...num_products).map { create(:product) } } - let(:order) { subject.current_order(create_order_if_necessary: true) } + let(:order) { subject.current_order( create_order_if_necessary: true ) } let(:num_products) { 20 } before do From 89c2733f509c93634a413a17a6b161b5be6deee7 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Tue, 5 Jun 2018 18:42:31 +0200 Subject: [PATCH 16/42] Revert "Removing redundant curly braces" This reverts commit 03173d4f7b113cc9f1e093cca1809ed86bcea132. --- app/controllers/base_controller.rb | 2 +- app/controllers/enterprises_controller.rb | 4 ++-- app/controllers/shop_controller.rb | 2 +- app/controllers/spree/orders_controller_decorator.rb | 8 ++++---- app/helpers/enterprises_helper.rb | 2 +- app/helpers/order_cycles_helper.rb | 2 +- app/helpers/shared_helper.rb | 2 +- app/helpers/spree/orders_helper.rb | 2 +- app/services/reset_order_service.rb | 2 +- app/views/spree/products/_add_to_cart.html.haml | 2 +- .../spree/products/_distributor_details.html.haml | 2 +- app/views/spree/products/_source.html.haml | 2 +- spec/controllers/checkout_controller_spec.rb | 2 +- spec/controllers/enterprises_controller_spec.rb | 2 +- spec/controllers/spree/checkout_controller_spec.rb | 2 +- spec/controllers/spree/orders_controller_spec.rb | 10 +++++----- spec/controllers/spree/paypal_controller_spec.rb | 2 +- spec/performance/orders_controller_spec.rb | 2 +- 18 files changed, 26 insertions(+), 26 deletions(-) diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index 58a6c932b39..18bc679fbed 100644 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -37,7 +37,7 @@ def set_order_cycles # And default to the only order cycle if there's only the one if @order_cycles.count == 1 - current_order( create_order_if_necessary: true ).set_order_cycle! @order_cycles.first + current_order({ create_order_if_necessary: true }).set_order_cycle! @order_cycles.first end end end diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb index 17874c7e0e3..88621ec53c7 100644 --- a/app/controllers/enterprises_controller.rb +++ b/app/controllers/enterprises_controller.rb @@ -49,14 +49,14 @@ def clean_permalink end def check_stock_levels - if current_order(create_order_if_necessary: true).insufficient_stock_lines.present? + if current_order({ create_order_if_necessary: true }).insufficient_stock_lines.present? redirect_to spree.cart_path end end def reset_order distributor = Enterprise.is_distributor.find_by_permalink(params[:id]) || Enterprise.is_distributor.find(params[:id]) - order = current_order(create_order_if_necessary: true) + order = current_order({ create_order_if_necessary: true }) reset_distributor(order, distributor) diff --git a/app/controllers/shop_controller.rb b/app/controllers/shop_controller.rb index c127e24ca9e..b9136c01bbd 100644 --- a/app/controllers/shop_controller.rb +++ b/app/controllers/shop_controller.rb @@ -26,7 +26,7 @@ def products def order_cycle if request.post? if oc = OrderCycle.with_distributor(@distributor).active.find_by_id(params[:order_cycle_id]) - current_order(create_order_if_necessary: true).set_order_cycle! oc + current_order({ create_order_if_necessary: true }).set_order_cycle! oc render partial: "json/order_cycle" else render status: 404, json: "" diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb index 2816ab6e26f..9d22a33b64c 100644 --- a/app/controllers/spree/orders_controller_decorator.rb +++ b/app/controllers/spree/orders_controller_decorator.rb @@ -18,7 +18,7 @@ # Patching to redirect to shop if order is empty def edit - @order = current_order( create_order_if_necessary: true ) + @order = current_order({ create_order_if_necessary: true }) @insufficient_stock_lines = @order.insufficient_stock_lines if @order.line_items.empty? @@ -78,7 +78,7 @@ def populate # callbacks on Spree::Adjustment and then manually invoke Spree::Order#update! on success. Spree::Adjustment.without_callbacks do - populator = Spree::OrderPopulator.new(current_order( create_order_if_necessary: true ), current_currency) + populator = Spree::OrderPopulator.new(current_order({ create_order_if_necessary: true }), current_currency) if populator.populate(params.slice(:products, :variants, :quantity), true) fire_event('spree.cart.add') @@ -127,7 +127,7 @@ def li_stock_levels(order) end def update_distribution - @order = current_order( create_order_if_necessary: true ) + @order = current_order({ create_order_if_necessary: true }) if params[:commit] == 'Choose Hub' distributor = Enterprise.is_distributor.find params[:order][:distributor_id] @@ -159,7 +159,7 @@ def remove_missing_line_items(attrs) end def clear - @order = current_order( create_order_if_necessary: true ) + @order = current_order({ create_order_if_necessary: true }) @order.empty! @order.set_order_cycle! nil redirect_to main_app.enterprise_path(@order.distributor.id) diff --git a/app/helpers/enterprises_helper.rb b/app/helpers/enterprises_helper.rb index 511c55df04e..432ef6777c5 100644 --- a/app/helpers/enterprises_helper.rb +++ b/app/helpers/enterprises_helper.rb @@ -2,7 +2,7 @@ module EnterprisesHelper def current_distributor - @current_distributor ||= current_order( create_order_if_necessary: false ).andand.distributor + @current_distributor ||= current_order({ create_order_if_necessary: false }).andand.distributor end def current_customer diff --git a/app/helpers/order_cycles_helper.rb b/app/helpers/order_cycles_helper.rb index 07a0ea488ac..6c83ca5d099 100644 --- a/app/helpers/order_cycles_helper.rb +++ b/app/helpers/order_cycles_helper.rb @@ -1,6 +1,6 @@ module OrderCyclesHelper def current_order_cycle - @current_order_cycle ||= current_order( create_order_if_necessary: false ).andand.order_cycle + @current_order_cycle ||= current_order({ create_order_if_necessary: false }).andand.order_cycle end def permitted_enterprises_for(order_cycle) diff --git a/app/helpers/shared_helper.rb b/app/helpers/shared_helper.rb index 253dceacb50..4ec9f88926e 100644 --- a/app/helpers/shared_helper.rb +++ b/app/helpers/shared_helper.rb @@ -1,6 +1,6 @@ module SharedHelper def distributor_link_class(distributor) - cart = current_order( create_order_if_necessary: true ) + cart = current_order({ create_order_if_necessary: true }) @active_distributors ||= Enterprise.distributors_with_active_order_cycles klass = "shop-distributor" diff --git a/app/helpers/spree/orders_helper.rb b/app/helpers/spree/orders_helper.rb index 12e90bd482c..78d45c34b84 100644 --- a/app/helpers/spree/orders_helper.rb +++ b/app/helpers/spree/orders_helper.rb @@ -1,7 +1,7 @@ module Spree module OrdersHelper def cart_is_empty - order = current_order( create_order_if_necessary: false ) + order = current_order({ create_order_if_necessary: false }) order.nil? || order.line_items.empty? end diff --git a/app/services/reset_order_service.rb b/app/services/reset_order_service.rb index 3ffdf1ffb59..ff369caee99 100644 --- a/app/services/reset_order_service.rb +++ b/app/services/reset_order_service.rb @@ -23,7 +23,7 @@ def call # Builds an order setting the token and distributor of the one specified def build_new_order - new_order = controller.current_order( create_order_if_necessary: true ) + new_order = controller.current_order({ create_order_if_necessary: true }) new_order.set_distributor!(distributor) new_order.tokenized_permission.token = token new_order.tokenized_permission.save! diff --git a/app/views/spree/products/_add_to_cart.html.haml b/app/views/spree/products/_add_to_cart.html.haml index e5d5248f2f7..c2e967dd6d0 100644 --- a/app/views/spree/products/_add_to_cart.html.haml +++ b/app/views/spree/products/_add_to_cart.html.haml @@ -1,5 +1,5 @@ .add-to-cart - - order = current_order( create_order_if_necessary: false ) + - order = current_order({ create_order_if_necessary: false }) - if product_out_of_stock = content_tag('strong', t(:out_of_stock)) diff --git a/app/views/spree/products/_distributor_details.html.haml b/app/views/spree/products/_distributor_details.html.haml index f044c622a70..e762ed97e10 100644 --- a/app/views/spree/products/_distributor_details.html.haml +++ b/app/views/spree/products/_distributor_details.html.haml @@ -2,7 +2,7 @@ %legend = t :products_distributor .distributor-details - - order = current_order( create_order_if_necessary: false ) + - order = current_order({ create_order_if_necessary: false }) - if order.andand.distributor.present? = render 'enterprises/distributor_details', :distributor => order.distributor - else diff --git a/app/views/spree/products/_source.html.haml b/app/views/spree/products/_source.html.haml index 8c5ac66fe30..ca952bb5171 100644 --- a/app/views/spree/products/_source.html.haml +++ b/app/views/spree/products/_source.html.haml @@ -10,7 +10,7 @@ %h6.product-section-title= t(:distributors) %table#product-source.table-display{:width => "100%"} %tbody - - order = current_order( create_order_if_necessary: false ) + - order = current_order({ create_order_if_necessary: false }) - validator = DistributionChangeValidator.new(order) - Enterprise.distributing_products(@product).each do |distributor| - if !order.nil? && distributor == order.distributor diff --git a/spec/controllers/checkout_controller_spec.rb b/spec/controllers/checkout_controller_spec.rb index 151af21ae83..ed11ad2955c 100644 --- a/spec/controllers/checkout_controller_spec.rb +++ b/spec/controllers/checkout_controller_spec.rb @@ -94,7 +94,7 @@ end it "sets the new order's token to the same as the old order" do - order = controller.current_order( create_order_if_necessary: true ) + order = controller.current_order({ create_order_if_necessary: true }) spree_post :update, order: {} expect(controller.current_order.token).to eq order.token end diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index d459c937fba..7aef356a8d5 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -2,7 +2,7 @@ describe EnterprisesController, type: :controller do describe "shopping for a distributor" do - let(:order) { controller.current_order( create_order_if_necessary: true ) } + let(:order) { controller.current_order({ create_order_if_necessary: true }) } let!(:current_distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) } diff --git a/spec/controllers/spree/checkout_controller_spec.rb b/spec/controllers/spree/checkout_controller_spec.rb index 47537e21330..bc21a068bd9 100644 --- a/spec/controllers/spree/checkout_controller_spec.rb +++ b/spec/controllers/spree/checkout_controller_spec.rb @@ -5,7 +5,7 @@ describe Spree::CheckoutController, type: :controller do context 'rendering edit from within spree for the current checkout state' do - let(:order) { controller.current_order( create_order_if_necessary: true ) } + let(:order) { controller.current_order({ create_order_if_necessary: true }) } let(:user) { create(:user) } before do diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index 9574d5f41b2..6aa80973b80 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -30,7 +30,7 @@ it "redirects home with message if hub is not ready for checkout" do VariantOverride.stub(:indexed).and_return({}) - order = subject.current_order( create_order_if_necessary: true ) + order = subject.current_order({ create_order_if_necessary: true }) distributor.stub(:ready_for_checkout?) { false } order.stub(distributor: distributor, order_cycle: order_cycle) @@ -44,7 +44,7 @@ end describe "when an item has insufficient stock" do - let(:order) { subject.current_order( create_order_if_necessary: true ) } + let(:order) { subject.current_order({ create_order_if_necessary: true }) } let(:oc) { create(:simple_order_cycle, distributors: [d], variants: [variant]) } let(:d) { create(:distributor_enterprise, shipping_methods: [create(:shipping_method)], payment_methods: [create(:payment_method)]) } let(:variant) { create(:variant, on_demand: false, on_hand: 5) } @@ -129,7 +129,7 @@ distributor_product = create(:distributor_enterprise) p = create(:product, :distributors => [distributor_product], :group_buy => true) - order = subject.current_order( create_order_if_necessary: true ) + order = subject.current_order({ create_order_if_necessary: true }) order.stub(:distributor) { distributor_product } order.should_receive(:set_variant_attributes).with(p.master, {'max_quantity' => '3'}) controller.stub(:current_order).and_return(order) @@ -164,7 +164,7 @@ describe "removing line items from cart" do describe "when I pass params that includes a line item no longer in our cart" do it "should silently ignore the missing line item" do - order = subject.current_order( create_order_if_necessary: true ) + order = subject.current_order({ create_order_if_necessary: true }) li = order.add_variant(create(:simple_product, on_hand: 110).variants.first) spree_get :update, order: { line_items_attributes: { "0" => {quantity: "0", id: "9999"}, @@ -176,7 +176,7 @@ end it "filters line items that are missing from params" do - order = subject.current_order( create_order_if_necessary: true ) + order = subject.current_order({ create_order_if_necessary: true }) li = order.add_variant(create(:simple_product).master) attrs = { diff --git a/spec/controllers/spree/paypal_controller_spec.rb b/spec/controllers/spree/paypal_controller_spec.rb index 4ce004183c6..6c284858e83 100644 --- a/spec/controllers/spree/paypal_controller_spec.rb +++ b/spec/controllers/spree/paypal_controller_spec.rb @@ -9,7 +9,7 @@ module Spree end context 'when confirming' do - let(:previous_order) { controller.current_order( create_order_if_necessary: true ) } + let(:previous_order) { controller.current_order({ create_order_if_necessary: true }) } let(:payment_method) { create(:payment_method) } before do diff --git a/spec/performance/orders_controller_spec.rb b/spec/performance/orders_controller_spec.rb index 58adf05540c..5b6fb97e951 100644 --- a/spec/performance/orders_controller_spec.rb +++ b/spec/performance/orders_controller_spec.rb @@ -4,7 +4,7 @@ let(:distributor) { create(:distributor_enterprise) } let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], variants: products.map { |p| p.variants.first }) } let(:products) { (0...num_products).map { create(:product) } } - let(:order) { subject.current_order( create_order_if_necessary: true ) } + let(:order) { subject.current_order({ create_order_if_necessary: true }) } let(:num_products) { 20 } before do From daf12d1300e2fcb10b5c991b193a877df5c938c8 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Tue, 5 Jun 2018 18:42:41 +0200 Subject: [PATCH 17/42] Revert "Refactor Order#current_order argument" This reverts commit ae935202be00ddddcce76a900d228f3121ba2d8b. --- app/controllers/base_controller.rb | 2 +- app/controllers/enterprises_controller.rb | 4 ++-- app/controllers/shop_controller.rb | 2 +- app/controllers/spree/orders_controller_decorator.rb | 8 ++++---- app/helpers/enterprises_helper.rb | 2 +- app/helpers/order_cycles_helper.rb | 2 +- app/helpers/shared_helper.rb | 2 +- app/helpers/spree/orders_helper.rb | 2 +- app/services/reset_order_service.rb | 2 +- app/views/spree/products/_add_to_cart.html.haml | 2 +- .../spree/products/_distributor_details.html.haml | 2 +- app/views/spree/products/_source.html.haml | 2 +- lib/spree/core/controller_helpers/order_decorator.rb | 4 ++-- spec/controllers/checkout_controller_spec.rb | 2 +- spec/controllers/enterprises_controller_spec.rb | 2 +- spec/controllers/spree/checkout_controller_spec.rb | 2 +- spec/controllers/spree/orders_controller_spec.rb | 10 +++++----- spec/controllers/spree/paypal_controller_spec.rb | 2 +- spec/performance/orders_controller_spec.rb | 2 +- 19 files changed, 28 insertions(+), 28 deletions(-) diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index 18bc679fbed..36bf72fd9c1 100644 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -37,7 +37,7 @@ def set_order_cycles # And default to the only order cycle if there's only the one if @order_cycles.count == 1 - current_order({ create_order_if_necessary: true }).set_order_cycle! @order_cycles.first + current_order(true).set_order_cycle! @order_cycles.first end end end diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb index 88621ec53c7..2b2a639b87e 100644 --- a/app/controllers/enterprises_controller.rb +++ b/app/controllers/enterprises_controller.rb @@ -49,14 +49,14 @@ def clean_permalink end def check_stock_levels - if current_order({ create_order_if_necessary: true }).insufficient_stock_lines.present? + if current_order(true).insufficient_stock_lines.present? redirect_to spree.cart_path end end def reset_order distributor = Enterprise.is_distributor.find_by_permalink(params[:id]) || Enterprise.is_distributor.find(params[:id]) - order = current_order({ create_order_if_necessary: true }) + order = current_order(true) reset_distributor(order, distributor) diff --git a/app/controllers/shop_controller.rb b/app/controllers/shop_controller.rb index b9136c01bbd..a32d5d0b855 100644 --- a/app/controllers/shop_controller.rb +++ b/app/controllers/shop_controller.rb @@ -26,7 +26,7 @@ def products def order_cycle if request.post? if oc = OrderCycle.with_distributor(@distributor).active.find_by_id(params[:order_cycle_id]) - current_order({ create_order_if_necessary: true }).set_order_cycle! oc + current_order(true).set_order_cycle! oc render partial: "json/order_cycle" else render status: 404, json: "" diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb index 9d22a33b64c..47425bcbf2c 100644 --- a/app/controllers/spree/orders_controller_decorator.rb +++ b/app/controllers/spree/orders_controller_decorator.rb @@ -18,7 +18,7 @@ # Patching to redirect to shop if order is empty def edit - @order = current_order({ create_order_if_necessary: true }) + @order = current_order(true) @insufficient_stock_lines = @order.insufficient_stock_lines if @order.line_items.empty? @@ -78,7 +78,7 @@ def populate # callbacks on Spree::Adjustment and then manually invoke Spree::Order#update! on success. Spree::Adjustment.without_callbacks do - populator = Spree::OrderPopulator.new(current_order({ create_order_if_necessary: true }), current_currency) + populator = Spree::OrderPopulator.new(current_order(true), current_currency) if populator.populate(params.slice(:products, :variants, :quantity), true) fire_event('spree.cart.add') @@ -127,7 +127,7 @@ def li_stock_levels(order) end def update_distribution - @order = current_order({ create_order_if_necessary: true }) + @order = current_order(true) if params[:commit] == 'Choose Hub' distributor = Enterprise.is_distributor.find params[:order][:distributor_id] @@ -159,7 +159,7 @@ def remove_missing_line_items(attrs) end def clear - @order = current_order({ create_order_if_necessary: true }) + @order = current_order(true) @order.empty! @order.set_order_cycle! nil redirect_to main_app.enterprise_path(@order.distributor.id) diff --git a/app/helpers/enterprises_helper.rb b/app/helpers/enterprises_helper.rb index 432ef6777c5..8cef0281b19 100644 --- a/app/helpers/enterprises_helper.rb +++ b/app/helpers/enterprises_helper.rb @@ -2,7 +2,7 @@ module EnterprisesHelper def current_distributor - @current_distributor ||= current_order({ create_order_if_necessary: false }).andand.distributor + @current_distributor ||= current_order(false).andand.distributor end def current_customer diff --git a/app/helpers/order_cycles_helper.rb b/app/helpers/order_cycles_helper.rb index 6c83ca5d099..8afca2b9491 100644 --- a/app/helpers/order_cycles_helper.rb +++ b/app/helpers/order_cycles_helper.rb @@ -1,6 +1,6 @@ module OrderCyclesHelper def current_order_cycle - @current_order_cycle ||= current_order({ create_order_if_necessary: false }).andand.order_cycle + @current_order_cycle ||= current_order(false).andand.order_cycle end def permitted_enterprises_for(order_cycle) diff --git a/app/helpers/shared_helper.rb b/app/helpers/shared_helper.rb index 4ec9f88926e..a1e1f84ec25 100644 --- a/app/helpers/shared_helper.rb +++ b/app/helpers/shared_helper.rb @@ -1,6 +1,6 @@ module SharedHelper def distributor_link_class(distributor) - cart = current_order({ create_order_if_necessary: true }) + cart = current_order(true) @active_distributors ||= Enterprise.distributors_with_active_order_cycles klass = "shop-distributor" diff --git a/app/helpers/spree/orders_helper.rb b/app/helpers/spree/orders_helper.rb index 78d45c34b84..99540f6ed45 100644 --- a/app/helpers/spree/orders_helper.rb +++ b/app/helpers/spree/orders_helper.rb @@ -1,7 +1,7 @@ module Spree module OrdersHelper def cart_is_empty - order = current_order({ create_order_if_necessary: false }) + order = current_order(false) order.nil? || order.line_items.empty? end diff --git a/app/services/reset_order_service.rb b/app/services/reset_order_service.rb index ff369caee99..402c377eb74 100644 --- a/app/services/reset_order_service.rb +++ b/app/services/reset_order_service.rb @@ -23,7 +23,7 @@ def call # Builds an order setting the token and distributor of the one specified def build_new_order - new_order = controller.current_order({ create_order_if_necessary: true }) + new_order = controller.current_order(true) new_order.set_distributor!(distributor) new_order.tokenized_permission.token = token new_order.tokenized_permission.save! diff --git a/app/views/spree/products/_add_to_cart.html.haml b/app/views/spree/products/_add_to_cart.html.haml index c2e967dd6d0..dd406ff50ba 100644 --- a/app/views/spree/products/_add_to_cart.html.haml +++ b/app/views/spree/products/_add_to_cart.html.haml @@ -1,5 +1,5 @@ .add-to-cart - - order = current_order({ create_order_if_necessary: false }) + - order = current_order(false) - if product_out_of_stock = content_tag('strong', t(:out_of_stock)) diff --git a/app/views/spree/products/_distributor_details.html.haml b/app/views/spree/products/_distributor_details.html.haml index e762ed97e10..e91c0ea6e57 100644 --- a/app/views/spree/products/_distributor_details.html.haml +++ b/app/views/spree/products/_distributor_details.html.haml @@ -2,7 +2,7 @@ %legend = t :products_distributor .distributor-details - - order = current_order({ create_order_if_necessary: false }) + - order = current_order(false) - if order.andand.distributor.present? = render 'enterprises/distributor_details', :distributor => order.distributor - else diff --git a/app/views/spree/products/_source.html.haml b/app/views/spree/products/_source.html.haml index ca952bb5171..7751ba36ef0 100644 --- a/app/views/spree/products/_source.html.haml +++ b/app/views/spree/products/_source.html.haml @@ -10,7 +10,7 @@ %h6.product-section-title= t(:distributors) %table#product-source.table-display{:width => "100%"} %tbody - - order = current_order({ create_order_if_necessary: false }) + - order = current_order(false) - validator = DistributionChangeValidator.new(order) - Enterprise.distributing_products(@product).each do |distributor| - if !order.nil? && distributor == order.distributor diff --git a/lib/spree/core/controller_helpers/order_decorator.rb b/lib/spree/core/controller_helpers/order_decorator.rb index d72fc7b22f3..dc38e861e64 100644 --- a/lib/spree/core/controller_helpers/order_decorator.rb +++ b/lib/spree/core/controller_helpers/order_decorator.rb @@ -1,6 +1,6 @@ Spree::Core::ControllerHelpers::Order.class_eval do - def current_order_with_scoped_variants(options = {}) - order = current_order_without_scoped_variants(options) + def current_order_with_scoped_variants(create_order_if_necessary = false) + order = current_order_without_scoped_variants(create_order_if_necessary) if order scoper = OpenFoodNetwork::ScopeVariantToHub.new(order.distributor) diff --git a/spec/controllers/checkout_controller_spec.rb b/spec/controllers/checkout_controller_spec.rb index ed11ad2955c..b373ae64b5f 100644 --- a/spec/controllers/checkout_controller_spec.rb +++ b/spec/controllers/checkout_controller_spec.rb @@ -94,7 +94,7 @@ end it "sets the new order's token to the same as the old order" do - order = controller.current_order({ create_order_if_necessary: true }) + order = controller.current_order(true) spree_post :update, order: {} expect(controller.current_order.token).to eq order.token end diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index 7aef356a8d5..eedcb5ad160 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -2,7 +2,7 @@ describe EnterprisesController, type: :controller do describe "shopping for a distributor" do - let(:order) { controller.current_order({ create_order_if_necessary: true }) } + let(:order) { controller.current_order(true) } let!(:current_distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) } diff --git a/spec/controllers/spree/checkout_controller_spec.rb b/spec/controllers/spree/checkout_controller_spec.rb index bc21a068bd9..b91c19f7444 100644 --- a/spec/controllers/spree/checkout_controller_spec.rb +++ b/spec/controllers/spree/checkout_controller_spec.rb @@ -5,7 +5,7 @@ describe Spree::CheckoutController, type: :controller do context 'rendering edit from within spree for the current checkout state' do - let(:order) { controller.current_order({ create_order_if_necessary: true }) } + let(:order) { controller.current_order(true) } let(:user) { create(:user) } before do diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index 6aa80973b80..fbcd5ec1078 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -30,7 +30,7 @@ it "redirects home with message if hub is not ready for checkout" do VariantOverride.stub(:indexed).and_return({}) - order = subject.current_order({ create_order_if_necessary: true }) + order = subject.current_order(true) distributor.stub(:ready_for_checkout?) { false } order.stub(distributor: distributor, order_cycle: order_cycle) @@ -44,7 +44,7 @@ end describe "when an item has insufficient stock" do - let(:order) { subject.current_order({ create_order_if_necessary: true }) } + let(:order) { subject.current_order(true) } let(:oc) { create(:simple_order_cycle, distributors: [d], variants: [variant]) } let(:d) { create(:distributor_enterprise, shipping_methods: [create(:shipping_method)], payment_methods: [create(:payment_method)]) } let(:variant) { create(:variant, on_demand: false, on_hand: 5) } @@ -129,7 +129,7 @@ distributor_product = create(:distributor_enterprise) p = create(:product, :distributors => [distributor_product], :group_buy => true) - order = subject.current_order({ create_order_if_necessary: true }) + order = subject.current_order(true) order.stub(:distributor) { distributor_product } order.should_receive(:set_variant_attributes).with(p.master, {'max_quantity' => '3'}) controller.stub(:current_order).and_return(order) @@ -164,7 +164,7 @@ describe "removing line items from cart" do describe "when I pass params that includes a line item no longer in our cart" do it "should silently ignore the missing line item" do - order = subject.current_order({ create_order_if_necessary: true }) + order = subject.current_order(true) li = order.add_variant(create(:simple_product, on_hand: 110).variants.first) spree_get :update, order: { line_items_attributes: { "0" => {quantity: "0", id: "9999"}, @@ -176,7 +176,7 @@ end it "filters line items that are missing from params" do - order = subject.current_order({ create_order_if_necessary: true }) + order = subject.current_order(true) li = order.add_variant(create(:simple_product).master) attrs = { diff --git a/spec/controllers/spree/paypal_controller_spec.rb b/spec/controllers/spree/paypal_controller_spec.rb index 6c284858e83..90f97fcb7d7 100644 --- a/spec/controllers/spree/paypal_controller_spec.rb +++ b/spec/controllers/spree/paypal_controller_spec.rb @@ -9,7 +9,7 @@ module Spree end context 'when confirming' do - let(:previous_order) { controller.current_order({ create_order_if_necessary: true }) } + let(:previous_order) { controller.current_order(true) } let(:payment_method) { create(:payment_method) } before do diff --git a/spec/performance/orders_controller_spec.rb b/spec/performance/orders_controller_spec.rb index 5b6fb97e951..e151e4f506f 100644 --- a/spec/performance/orders_controller_spec.rb +++ b/spec/performance/orders_controller_spec.rb @@ -4,7 +4,7 @@ let(:distributor) { create(:distributor_enterprise) } let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], variants: products.map { |p| p.variants.first }) } let(:products) { (0...num_products).map { create(:product) } } - let(:order) { subject.current_order({ create_order_if_necessary: true }) } + let(:order) { subject.current_order(true) } let(:num_products) { 20 } before do From 6e2966d7e83c3a1d478b72abf685509d6042520e Mon Sep 17 00:00:00 2001 From: Hugo Daniel Date: Tue, 12 Jun 2018 15:59:41 +0200 Subject: [PATCH 18/42] Changed require syntax to fit jquery < 5.0 --- app/assets/javascripts/admin/all.js | 2 +- app/assets/javascripts/darkswarm/all.js.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/admin/all.js b/app/assets/javascripts/admin/all.js index 688494f870d..bc5cfea4a3e 100644 --- a/app/assets/javascripts/admin/all.js +++ b/app/assets/javascripts/admin/all.js @@ -8,7 +8,7 @@ //= require jquery //= require jquery-migrate-min //= require jquery_ujs -//= require jquery-ui +//= require jquery.ui.all //= require shared/jquery-ui-timepicker-addon //= require angular //= require angular-resource diff --git a/app/assets/javascripts/darkswarm/all.js.coffee b/app/assets/javascripts/darkswarm/all.js.coffee index 90080f0a772..32ee0b2255b 100644 --- a/app/assets/javascripts/darkswarm/all.js.coffee +++ b/app/assets/javascripts/darkswarm/all.js.coffee @@ -1,6 +1,6 @@ #= require jquery #= require jquery_ujs -#= require jquery-ui +#= require jquery.ui.all #= require spin # #= require angular From c7f7e420eab75bace1106bda18ecfc33e66413a0 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 5 Jul 2018 16:34:11 +1000 Subject: [PATCH 19/42] Skip shipment creation for payment step https://github.com/openfoodfoundation/openfoodnetwork/issues/2007 Spree 2.0.4 creates in-memory shipments for the payment step. That means we don't need to create a shipment in that transition. This change copies the checkout_flow from the Spree code, but leaves one last customisation: removal of the confirm step. https://github.com/openfoodfoundation/openfoodnetwork/commit/75ec77dc31de2c57514948211755a05356eab938 --- app/models/spree/order_decorator.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index c6def73d680..10cabd124ad 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -30,20 +30,14 @@ checkout_flow do go_to_state :address go_to_state :delivery - go_to_state :payment, :if => lambda { |order| - # Fix for #2191 - if order.shipping_method.andand.delivery? - if order.ship_address.andand.valid? - order.create_shipment! - order.update_totals - end - end + go_to_state :payment, if: ->(order) { + order.update_totals order.payment_required? } # NOTE: :confirm step was removed because we were not actually using it # go_to_state :confirm, :if => lambda { |order| order.confirmation_required? } go_to_state :complete - remove_transition :from => :delivery, :to => :confirm + remove_transition from: :delivery, to: :confirm end # -- Scopes From 2334f0854caa1b74fdd28a11e892e3ab7421b0b1 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 11 Jul 2018 10:55:12 +1000 Subject: [PATCH 20/42] Less invasive modifying the checkout state machine --- app/models/spree/order_decorator.rb | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 10cabd124ad..eed4cefd0b2 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -27,18 +27,10 @@ before_save :update_shipping_fees!, if: :complete? before_save :update_payment_fees!, if: :complete? - checkout_flow do - go_to_state :address - go_to_state :delivery - go_to_state :payment, if: ->(order) { - order.update_totals - order.payment_required? - } - # NOTE: :confirm step was removed because we were not actually using it - # go_to_state :confirm, :if => lambda { |order| order.confirmation_required? } - go_to_state :complete - remove_transition from: :delivery, to: :confirm - end + # Orders are confirmed with their payment, we don't use the confirm step. + # Here we remove that step from Spree's checkout state machine. + # See: https://guides.spreecommerce.org/developer/checkout.html#modifying-the-checkout-flow + remove_checkout_step :confirm # -- Scopes scope :managed_by, lambda { |user| From 514fc0a78115fa6e5ad53fcf84b32642986afb8e Mon Sep 17 00:00:00 2001 From: Hugo Daniel Date: Fri, 20 Jul 2018 13:01:13 +0200 Subject: [PATCH 21/42] Remove dependency to Dash and Jirafe --- spec/features/admin/overview_spec.rb | 39 ---------------------------- 1 file changed, 39 deletions(-) diff --git a/spec/features/admin/overview_spec.rb b/spec/features/admin/overview_spec.rb index 530363929cf..47e8d878a79 100644 --- a/spec/features/admin/overview_spec.rb +++ b/spec/features/admin/overview_spec.rb @@ -103,44 +103,5 @@ end end end - - context "with the spree dash configured" do - let(:d1) { create(:distributor_enterprise) } - - before do - stub_jirafe - @enterprise_user.enterprise_roles.build(enterprise: d1).save - end - - around do |example| - with_dash_configured { example.run } - end - - it "has permission to sync analytics" do - visit '/admin' - expect(page).to have_content d1.name - end - end - end - - private - - def stub_jirafe - stub_request(:post, "https://api.jirafe.com/v1/applications/abc123/resources?token="). - to_return(:status => 200, :body => "", :headers => {}) - end - - def with_dash_configured(&block) - Spree::Dash::Config.preferred_app_id = 'abc123' - Spree::Dash::Config.preferred_site_id = 'abc123' - Spree::Dash::Config.preferred_token = 'abc123' - expect(Spree::Dash::Config.configured?).to be true - - block.call - ensure - Spree::Dash::Config.preferred_app_id = nil - Spree::Dash::Config.preferred_site_id = nil - Spree::Dash::Config.preferred_token = nil - expect(Spree::Dash::Config.configured?).to be false end end From ec751c0a78298f9e9a9d9212dd9dcff69aeb2b90 Mon Sep 17 00:00:00 2001 From: Hugo Daniel Date: Tue, 24 Jul 2018 15:27:22 +0200 Subject: [PATCH 22/42] Remove admin analytics ability --- app/models/spree/ability_decorator.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index 385b9be0321..54eb462e740 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -73,7 +73,6 @@ def add_base_abilities(user) def add_group_management_abilities(user) can [:admin, :index], :overview - can [:admin, :sync], :analytic can [:admin, :index], EnterpriseGroup can [:read, :edit, :update], EnterpriseGroup do |group| user.owned_groups.include? group @@ -86,7 +85,6 @@ def add_enterprise_management_abilities(user) can [:create, :search], nil can [:admin, :index], :overview - can [:admin, :sync], :analytic can [:admin, :index, :read, :create, :edit, :update_positions, :destroy], ProducerProperty From eab04e0d86546c4ca49f2bcdf211b8243dcf6f3d Mon Sep 17 00:00:00 2001 From: Hugo Daniel Date: Tue, 24 Jul 2018 16:27:30 +0200 Subject: [PATCH 23/42] Reimplement Spree<2.0 :simple_product factory in OFN --- spec/factories.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/factories.rb b/spec/factories.rb index 215d9e0635c..c5dcb158ed1 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -453,6 +453,10 @@ Spree::Image.create(attachment: image, viewable_id: product.master.id, viewable_type: 'Spree::Variant') end end + + factory :simple_product, parent: :base_product do + on_hand 5 + end end @@ -526,4 +530,5 @@ user.spree_roles << Spree::Role.find_or_create_by_name!('admin') end end + end From 72f02ee1eeb797952cf369bf4f35b067e6e63ad1 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Fri, 8 Jun 2018 11:23:27 +0200 Subject: [PATCH 24/42] RSpec3-ize OrderUpdater spec --- spec/models/spree/order_updater_spec.rb | 58 +++++++++++++++---------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/spec/models/spree/order_updater_spec.rb b/spec/models/spree/order_updater_spec.rb index 50ab49a8c7f..1fc13f11e3c 100644 --- a/spec/models/spree/order_updater_spec.rb +++ b/spec/models/spree/order_updater_spec.rb @@ -1,88 +1,98 @@ require 'spec_helper' describe Spree::OrderUpdater do - # Copied pretty much verbatim from Spree 2.4. Remove this file once we get there, - # assuming the unchanged 2.4 logic still works for us. - # Only changes are stubs of :empty? instead of :size - context "updating payment state" do - let(:order) { Spree::Order.new } - let(:updater) { order.updater } + context "#updating_payment_state" do + let(:order) { build(:order) } + let(:order_updater) { described_class.new(order) } it "is failed if no valid payments" do - order.stub_chain(:payments, :valid, :empty?).and_return(true) + allow(order).to receive_message_chain(:payments, :valid, :empty?) { true } - updater.update_payment_state - order.payment_state.should == 'failed' + order_updater.update_payment_state + expect(order.payment_state).to eq('failed') end context "payment total is greater than order total" do - it "is credit_owed" do + before do order.payment_total = 2 order.total = 1 + end + it "is credit_owed" do expect { - updater.update_payment_state + order_updater.update_payment_state }.to change { order.payment_state }.to 'credit_owed' end end context "order total is greater than payment total" do - it "is credit_owed" do + before do order.payment_total = 1 order.total = 2 + end + it "is credit_owed" do expect { - updater.update_payment_state + order_updater.update_payment_state }.to change { order.payment_state }.to 'balance_due' end end context "order total equals payment total" do - it "is paid" do + before do order.payment_total = 30 order.total = 30 + end + it "is paid" do expect { - updater.update_payment_state + order_updater.update_payment_state }.to change { order.payment_state }.to 'paid' end end context "order is canceled" do - before do - order.state = 'canceled' - end + before { order.state = 'canceled' } context "and is still unpaid" do - it "is void" do + before do order.payment_total = 0 order.total = 30 + end + + it "is void" do expect { - updater.update_payment_state + order_updater.update_payment_state }.to change { order.payment_state }.to 'void' end end context "and is paid" do - it "is credit_owed" do + before do order.payment_total = 30 order.total = 30 order.stub_chain(:payments, :valid, :empty?).and_return(false) order.stub_chain(:payments, :completed, :empty?).and_return(false) + end + + it "is credit_owed" do expect { - updater.update_payment_state + order_updater.update_payment_state }.to change { order.payment_state }.to 'credit_owed' end end context "and payment is refunded" do - it "is void" do + before do order.payment_total = 0 order.total = 30 order.stub_chain(:payments, :valid, :empty?).and_return(false) order.stub_chain(:payments, :completed, :empty?).and_return(false) + end + + it "is void" do expect { - updater.update_payment_state + order_updater.update_payment_state }.to change { order.payment_state }.to 'void' end end From 21d905a0927ac0117639d2a3a4e85a0459c319a4 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Fri, 8 Jun 2018 11:31:57 +0200 Subject: [PATCH 25/42] Refactor OrderUpdater to decorate Spree's one This replaces the nasty class eval and provides some encapsulation --- app/models/order_updater.rb | 41 +++++++++++++++++++ app/models/spree/order_updater_decorator.rb | 41 ------------------- spec/models/{spree => }/order_updater_spec.rb | 4 +- 3 files changed, 43 insertions(+), 43 deletions(-) create mode 100644 app/models/order_updater.rb delete mode 100644 app/models/spree/order_updater_decorator.rb rename spec/models/{spree => }/order_updater_spec.rb (96%) diff --git a/app/models/order_updater.rb b/app/models/order_updater.rb new file mode 100644 index 00000000000..9b41145ea30 --- /dev/null +++ b/app/models/order_updater.rb @@ -0,0 +1,41 @@ +require 'delegate' + +class OrderUpdater < SimpleDelegator + # TODO: This logic adapted from Spree 2.4, remove when we get there + # Handles state updating in a much more logical way than < 2.4 + # Specifically, doesn't depend on payments.last to determine payment state + # Also swapped: == 0 for .zero?, .size == 0 for empty? and .size > 0 for !empty? + # See: + # https://github.com/spree/spree/commit/38b8456183d11fc1e00e395e7c9154c76ef65b85 + # https://github.com/spree/spree/commit/7b264acff7824f5b3dc6651c106631d8f30b147a + def update_payment_state + last_state = order.payment_state + if payments.present? && payments.valid.empty? + order.payment_state = 'failed' + elsif order.state == 'canceled' && order.payment_total.zero? + order.payment_state = 'void' + else + # This part added so that we don't need to override order.outstanding_balance + balance = order.outstanding_balance + balance = -1 * order.payment_total if canceled_and_paid_for? + order.payment_state = 'balance_due' if balance > 0 + order.payment_state = 'credit_owed' if balance < 0 + order.payment_state = 'paid' if balance.zero? + + # Original logic + # order.payment_state = 'balance_due' if order.outstanding_balance > 0 + # order.payment_state = 'credit_owed' if order.outstanding_balance < 0 + # order.payment_state = 'paid' if !order.outstanding_balance? + end + order.state_changed('payment') if last_state != order.payment_state + order.payment_state + end + + private + + # Taken from order.outstanding_balance in Spree 2.4 + # See: https://github.com/spree/spree/commit/7b264acff7824f5b3dc6651c106631d8f30b147a + def canceled_and_paid_for? + order.canceled? && order.payments.present? && !order.payments.completed.empty? + end +end diff --git a/app/models/spree/order_updater_decorator.rb b/app/models/spree/order_updater_decorator.rb deleted file mode 100644 index ab1d4eaf26b..00000000000 --- a/app/models/spree/order_updater_decorator.rb +++ /dev/null @@ -1,41 +0,0 @@ -module Spree - OrderUpdater.class_eval do - # TODO: This logic adapted from Spree 2.4, remove when we get there - # Handles state updating in a much more logical way than < 2.4 - # Specifically, doesn't depend on payments.last to determine payment state - # Also swapped: == 0 for .zero?, .size == 0 for empty? and .size > 0 for !empty? - # See: - # https://github.com/spree/spree/commit/38b8456183d11fc1e00e395e7c9154c76ef65b85 - # https://github.com/spree/spree/commit/7b264acff7824f5b3dc6651c106631d8f30b147a - def update_payment_state - last_state = order.payment_state - if payments.present? && payments.valid.empty? - order.payment_state = 'failed' - elsif order.state == 'canceled' && order.payment_total.zero? - order.payment_state = 'void' - else - # This part added so that we don't need to override order.outstanding_balance - balance = order.outstanding_balance - balance = -1 * order.payment_total if canceled_and_paid_for? - order.payment_state = 'balance_due' if balance > 0 - order.payment_state = 'credit_owed' if balance < 0 - order.payment_state = 'paid' if balance.zero? - - # Original logic - # order.payment_state = 'balance_due' if order.outstanding_balance > 0 - # order.payment_state = 'credit_owed' if order.outstanding_balance < 0 - # order.payment_state = 'paid' if !order.outstanding_balance? - end - order.state_changed('payment') if last_state != order.payment_state - order.payment_state - end - - private - - # Taken from order.outstanding_balance in Spree 2.4 - # See: https://github.com/spree/spree/commit/7b264acff7824f5b3dc6651c106631d8f30b147a - def canceled_and_paid_for? - order.canceled? && order.payments.present? && !order.payments.completed.empty? - end - end -end diff --git a/spec/models/spree/order_updater_spec.rb b/spec/models/order_updater_spec.rb similarity index 96% rename from spec/models/spree/order_updater_spec.rb rename to spec/models/order_updater_spec.rb index 1fc13f11e3c..217a5dd4916 100644 --- a/spec/models/spree/order_updater_spec.rb +++ b/spec/models/order_updater_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' -describe Spree::OrderUpdater do +describe OrderUpdater do context "#updating_payment_state" do let(:order) { build(:order) } - let(:order_updater) { described_class.new(order) } + let(:order_updater) { described_class.new(Spree::OrderUpdater.new(order)) } it "is failed if no valid payments" do allow(order).to receive_message_chain(:payments, :valid, :empty?) { true } From f1896313b3306757fa0c291349f2de108be69547 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Fri, 8 Jun 2018 12:32:38 +0200 Subject: [PATCH 26/42] Move shipping_address_from_distributor to OrderUpdater This is still Spree-1.3 compatible not considering multiple shipments and shipping methods. --- app/models/order_updater.rb | 11 +++++++++ app/models/spree/order_decorator.rb | 13 ---------- spec/models/order_updater_spec.rb | 38 ++++++++++++++++++++++++++--- spec/models/spree/order_spec.rb | 35 -------------------------- 4 files changed, 46 insertions(+), 51 deletions(-) diff --git a/app/models/order_updater.rb b/app/models/order_updater.rb index 9b41145ea30..f27103385ec 100644 --- a/app/models/order_updater.rb +++ b/app/models/order_updater.rb @@ -31,6 +31,10 @@ def update_payment_state order.payment_state end + def before_save_hook + shipping_address_from_distributor + end + private # Taken from order.outstanding_balance in Spree 2.4 @@ -38,4 +42,11 @@ def update_payment_state def canceled_and_paid_for? order.canceled? && order.payments.present? && !order.payments.completed.empty? end + + def shipping_address_from_distributor + shipping_method = order.shipments.first.shipping_methods.first + return if shipping_method.require_ship_address + + order.ship_address = order.distributor.address + end end diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index eed4cefd0b2..e7e208acd1d 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -20,7 +20,6 @@ validate :disallow_guest_order attr_accessible :order_cycle_id, :distributor_id, :customer_id - before_validation :shipping_address_from_distributor before_validation :associate_customer, unless: :customer_id? before_validation :ensure_customer, unless: :customer_is_valid? @@ -337,18 +336,6 @@ def pending_payments private - def shipping_address_from_distributor - if distributor - # This method is confusing to conform to the vagaries of the multi-step checkout - # We copy over the shipping address when we have no shipping method selected - # We can refactor this when we drop the multi-step checkout option - # - if shipping_method.andand.require_ship_address == false - self.ship_address = address_from_distributor - end - end - end - def address_from_distributor address = distributor.address.clone if bill_address diff --git a/spec/models/order_updater_spec.rb b/spec/models/order_updater_spec.rb index 217a5dd4916..bb1e01ea5c8 100644 --- a/spec/models/order_updater_spec.rb +++ b/spec/models/order_updater_spec.rb @@ -1,10 +1,10 @@ require 'spec_helper' describe OrderUpdater do - context "#updating_payment_state" do - let(:order) { build(:order) } - let(:order_updater) { described_class.new(Spree::OrderUpdater.new(order)) } + let(:order) { build(:order) } + let(:order_updater) { described_class.new(Spree::OrderUpdater.new(order)) } + context "#updating_payment_state" do it "is failed if no valid payments" do allow(order).to receive_message_chain(:payments, :valid, :empty?) { true } @@ -98,4 +98,36 @@ end end end + + context '#before_save_hook' do + let(:distributor) { build(:distributor_enterprise) } + let(:shipment) { build(:shipment) } + let(:order) { build(:order, distributor: distributor) } + + before do + shipment.shipping_methods << shipping_method + order.shipments << shipment + end + + context 'when the shipping method doesn\'t require a delivery address' do + let(:shipping_method) { build(:base_shipping_method, require_ship_address: false) } + + it "populates the shipping address" do + order_updater.before_save_hook + expect(order.ship_address.firstname).to eq(distributor.address.firstname) + end + end + + context 'when the shipping method requires a delivery address' do + let(:shipping_method) { build(:base_shipping_method, require_ship_address: true) } + let(:address) { build(:address, firstname: 'will') } + + before { order.ship_address = address } + + it "does not populate the shipping address" do + order_updater.before_save_hook + expect(order.ship_address.firstname).to eq("will") + end + end + end end diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 345cbb661f4..4e23a102efc 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -509,41 +509,6 @@ end end - describe "shipping address prepopulation" do - let(:distributor) { create(:distributor_enterprise) } - let(:order) { build(:order, distributor: distributor) } - - before do - order.ship_address = distributor.address.clone - order.save # just to trigger our autopopulate the first time ;) - end - - it "autopopulates the shipping address on save" do - order.should_receive(:shipping_address_from_distributor).and_return true - order.save - end - - it "populates the shipping address if the shipping method doesn't require a delivery address" do - order.shipping_method = create(:shipping_method, require_ship_address: false) - order.ship_address.update_attribute :firstname, "will" - order.save - order.ship_address.firstname.should == distributor.address.firstname - end - - it "does not populate the shipping address if the shipping method requires a delivery address" do - order.shipping_method = create(:shipping_method, require_ship_address: true) - order.ship_address.update_attribute :firstname, "will" - order.save - order.ship_address.firstname.should == "will" - end - - it "doesn't attempt to create a shipment if the order is not yet valid" do - order.shipping_method = create(:shipping_method, require_ship_address: false) - #Shipment.should_not_r - order.create_shipment! - end - end - describe "checking if an order is an account invoice" do let(:accounts_distributor) { create(:distributor_enterprise) } let(:order_account_invoice) { create(:order, distributor: accounts_distributor) } From d1e65691cfe4c06349667984a4e6358df01be024 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Fri, 8 Jun 2018 12:57:17 +0200 Subject: [PATCH 27/42] Copy distributor addr. when using a pick up method This copies the distributor's address when at least one of the order shipments uses a shipping method that requires shipping address. --- app/models/order_updater.rb | 8 +++++--- spec/models/order_updater_spec.rb | 27 +++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/app/models/order_updater.rb b/app/models/order_updater.rb index f27103385ec..5534e8d2a4d 100644 --- a/app/models/order_updater.rb +++ b/app/models/order_updater.rb @@ -44,9 +44,11 @@ def canceled_and_paid_for? end def shipping_address_from_distributor - shipping_method = order.shipments.first.shipping_methods.first - return if shipping_method.require_ship_address + shipments.each do |shipment| + shipping_method = shipment.shipping_method + next if shipping_method.require_ship_address - order.ship_address = order.distributor.address + order.ship_address = order.distributor.address + end end end diff --git a/spec/models/order_updater_spec.rb b/spec/models/order_updater_spec.rb index bb1e01ea5c8..054154aadd6 100644 --- a/spec/models/order_updater_spec.rb +++ b/spec/models/order_updater_spec.rb @@ -101,24 +101,43 @@ context '#before_save_hook' do let(:distributor) { build(:distributor_enterprise) } - let(:shipment) { build(:shipment) } let(:order) { build(:order, distributor: distributor) } + let(:shipment) { build(:shipment) } + let(:shipping_rate) do + Spree::ShippingRate.new( + shipping_method: shipping_method, + selected: true + ) + end before do - shipment.shipping_methods << shipping_method + shipment.shipping_rates << shipping_rate order.shipments << shipment end - context 'when the shipping method doesn\'t require a delivery address' do + context 'when any of the shipping methods doesn\'t require a delivery address' do let(:shipping_method) { build(:base_shipping_method, require_ship_address: false) } + let(:delivery_shipment) { build(:shipment) } + let(:delivery_shipping_rate) do + Spree::ShippingRate.new( + shipping_method: build(:base_shipping_method, require_ship_address: true), + selected: true + ) + end + + before do + delivery_shipment.shipping_rates << delivery_shipping_rate + order.shipments << delivery_shipment + end + it "populates the shipping address" do order_updater.before_save_hook expect(order.ship_address.firstname).to eq(distributor.address.firstname) end end - context 'when the shipping method requires a delivery address' do + context 'when any of the shipping methods requires a delivery address' do let(:shipping_method) { build(:base_shipping_method, require_ship_address: true) } let(:address) { build(:address, firstname: 'will') } From a0d2ec5666a97198ccfb3534e0d33d29f8ea6142 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Wed, 25 Jul 2018 13:51:01 +0200 Subject: [PATCH 28/42] Enable OFN's custom OrderUpdater --- config/initializers/spree.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/initializers/spree.rb b/config/initializers/spree.rb index 77243c8ebbd..83e854a08fb 100644 --- a/config/initializers/spree.rb +++ b/config/initializers/spree.rb @@ -22,6 +22,7 @@ #config.override_actionmailer_config = false config.package_factory = Stock::Package + config.order_updater_decorator = OrderUpdater end # TODO Work out why this is necessary From eaf108718c8b946646ffb0f0b974b95d4a3db563 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Wed, 25 Jul 2018 13:52:05 +0200 Subject: [PATCH 29/42] Add doc to method --- app/models/order_updater.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/models/order_updater.rb b/app/models/order_updater.rb index 5534e8d2a4d..c798da087b1 100644 --- a/app/models/order_updater.rb +++ b/app/models/order_updater.rb @@ -43,6 +43,9 @@ def canceled_and_paid_for? order.canceled? && order.payments.present? && !order.payments.completed.empty? end + # Sets the distributor's address as shipping address of the order for those + # shipments using a shipping method that doesn't require address, such us + # a pickup. def shipping_address_from_distributor shipments.each do |shipment| shipping_method = shipment.shipping_method From 6fb95d30c36a0fb554d6ee3796e5922e0aa983aa Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Thu, 26 Jul 2018 12:17:05 +0200 Subject: [PATCH 30/42] Update Gemfile.lock to fetch the latest revision Since https://github.com/openfoodfoundation/spree/pull/6 got merged, we need the app to use the latest Spree fork revision to pick up those changes. --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 4ca060e0b05..14055c1a51d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -22,7 +22,7 @@ GIT GIT remote: https://github.com/openfoodfoundation/spree.git - revision: 1c3dfc7fb48cde32f7dc49a59c1daf65a3ee6974 + revision: 94b1f395bbf2cffbb1e33cdab5809511150da814 branch: 2-0-4-stable specs: spree (2.0.4) From ce46f3de395784b8446426dcb97afef0d1d60cb7 Mon Sep 17 00:00:00 2001 From: Hugo Daniel Date: Mon, 30 Jul 2018 12:11:02 +0200 Subject: [PATCH 31/42] Removed empty line --- spec/factories.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/factories.rb b/spec/factories.rb index c5dcb158ed1..e387f519e8b 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -530,5 +530,4 @@ user.spree_roles << Spree::Role.find_or_create_by_name!('admin') end end - end From 898e41acfb6ab7dada1eaa381a89910f3e94520b Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sun, 19 Aug 2018 20:23:31 +0100 Subject: [PATCH 32/42] Removed monkeypatchs to scope variants on inventory_unit and line_item decorators. We need to make the scoping somewhere else in spree2, see #2559 --- app/models/spree/inventory_unit_decorator.rb | 16 ----------- app/models/spree/line_item_decorator.rb | 28 -------------------- 2 files changed, 44 deletions(-) delete mode 100644 app/models/spree/inventory_unit_decorator.rb diff --git a/app/models/spree/inventory_unit_decorator.rb b/app/models/spree/inventory_unit_decorator.rb deleted file mode 100644 index 9868596b41f..00000000000 --- a/app/models/spree/inventory_unit_decorator.rb +++ /dev/null @@ -1,16 +0,0 @@ -module Spree - InventoryUnit.class_eval do - def self.assign_opening_inventory(order) - return [] unless order.completed? - - #increase inventory to meet initial requirements - scoper = OpenFoodNetwork::ScopeVariantToHub.new(order.distributor) - order.line_items.each do |line_item| - # Scope variant to hub so that stock levels may be subtracted from VariantOverride. - scoper.scope(line_item.variant) - - increase(order, line_item.variant, line_item.quantity) - end - end - end -end diff --git a/app/models/spree/line_item_decorator.rb b/app/models/spree/line_item_decorator.rb index 6f74e195304..7af42821f6c 100644 --- a/app/models/spree/line_item_decorator.rb +++ b/app/models/spree/line_item_decorator.rb @@ -110,34 +110,6 @@ def unit_value final_weight_volume / quantity end - # MONKEYPATCH of Spree method - # Enables scoping of variant to hub/shop, stock drawn down from inventory - def update_inventory - return true unless order.completed? - - scoper.scope(variant) # this line added - - if new_record? - Spree::InventoryUnit.increase(order, variant, quantity) - elsif old_quantity = self.changed_attributes['quantity'] - if old_quantity < quantity - Spree::InventoryUnit.increase(order, variant, (quantity - old_quantity)) - elsif old_quantity > quantity - Spree::InventoryUnit.decrease(order, variant, (old_quantity - quantity)) - end - end - end - - # MONKEYPATCH of Spree method - # Enables scoping of variant to hub/shop, stock replaced to inventory - def remove_inventory - return true unless order.completed? - - scoper.scope(variant) # this line added - - Spree::InventoryUnit.decrease(order, variant, quantity) - end - # MONKEYPATCH of Spree method # Enables scoping of variant to hub/shop, so we check stock against relevant overrides if they exist # Also skips stock check if requested quantity is zero From a97138dd58245a37321d9ac4cac9e0340df87d26 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Wed, 22 Aug 2018 23:20:30 +0100 Subject: [PATCH 33/42] Fixed bulk_line_items_controller_spec by setting shipment on test line_items and by allowing shipment decorator to allow no adjustments in the shipment --- app/models/spree/shipment_decorator.rb | 1 + .../admin/bulk_line_items_controller_spec.rb | 29 +++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/app/models/spree/shipment_decorator.rb b/app/models/spree/shipment_decorator.rb index f544d955172..625cf06decd 100644 --- a/app/models/spree/shipment_decorator.rb +++ b/app/models/spree/shipment_decorator.rb @@ -2,6 +2,7 @@ module Spree Shipment.class_eval do def ensure_correct_adjustment_with_included_tax ensure_correct_adjustment_without_included_tax + return unless adjustment if Config.shipment_inc_vat && (order.distributor.nil? || order.distributor.charges_sales_tax) adjustment.set_included_tax! Config.shipping_tax_rate diff --git a/spec/controllers/admin/bulk_line_items_controller_spec.rb b/spec/controllers/admin/bulk_line_items_controller_spec.rb index dd5c1c63268..cc4201d0ce8 100644 --- a/spec/controllers/admin/bulk_line_items_controller_spec.rb +++ b/spec/controllers/admin/bulk_line_items_controller_spec.rb @@ -11,10 +11,13 @@ let!(:order1) { FactoryBot.create(:order, state: 'complete', completed_at: 1.day.ago, distributor: dist1, billing_address: FactoryBot.create(:address) ) } let!(:order2) { FactoryBot.create(:order, state: 'complete', completed_at: Time.zone.now, distributor: dist1, billing_address: FactoryBot.create(:address) ) } let!(:order3) { FactoryBot.create(:order, state: 'complete', completed_at: Time.zone.now, distributor: dist1, billing_address: FactoryBot.create(:address) ) } - let!(:line_item1) { FactoryBot.create(:line_item, order: order1) } - let!(:line_item2) { FactoryBot.create(:line_item, order: order2) } - let!(:line_item3) { FactoryBot.create(:line_item, order: order2) } - let!(:line_item4) { FactoryBot.create(:line_item, order: order3) } + let(:shipment1) { FactoryBot.create(:shipment, order:order1) } + let(:shipment2) { FactoryBot.create(:shipment, order:order2) } + let(:shipment3) { FactoryBot.create(:shipment, order:order3) } + let!(:line_item1) { FactoryBot.create(:line_item, order: order1, target_shipment: shipment1) } + let!(:line_item2) { FactoryBot.create(:line_item, order: order2, target_shipment: shipment2) } + let!(:line_item3) { FactoryBot.create(:line_item, order: order2, target_shipment: shipment2) } + let!(:line_item4) { FactoryBot.create(:line_item, order: order3, target_shipment: shipment3) } context "as a normal user" do before { controller.stub spree_current_user: create_enterprise_user } @@ -83,10 +86,12 @@ let(:coordinator) { create(:distributor_enterprise) } let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator) } let!(:order1) { FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now, distributor: distributor1, billing_address: FactoryBot.create(:address) ) } - let!(:line_item1) { FactoryBot.create(:line_item, order: order1, product: FactoryBot.create(:product, supplier: supplier)) } - let!(:line_item2) { FactoryBot.create(:line_item, order: order1, product: FactoryBot.create(:product, supplier: supplier)) } + let(:shipment1) { FactoryBot.create(:shipment, order:order1) } + let(:shipment2) { FactoryBot.create(:shipment, order:order2) } + let!(:line_item1) { FactoryBot.create(:line_item, order: order1, target_shipment: shipment1, product: FactoryBot.create(:product, supplier: supplier)) } + let!(:line_item2) { FactoryBot.create(:line_item, order: order1, target_shipment: shipment1, product: FactoryBot.create(:product, supplier: supplier)) } let!(:order2) { FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now, distributor: distributor2, billing_address: FactoryBot.create(:address) ) } - let!(:line_item3) { FactoryBot.create(:line_item, order: order2, product: FactoryBot.create(:product, supplier: supplier)) } + let!(:line_item3) { FactoryBot.create(:line_item, order: order2, target_shipment: shipment2, product: FactoryBot.create(:product, supplier: supplier)) } context "producer enterprise" do before do @@ -131,7 +136,12 @@ let(:coordinator) { create(:distributor_enterprise) } let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator) } let!(:order1) { FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now, distributor: distributor1, billing_address: FactoryBot.create(:address) ) } - let!(:line_item1) { FactoryBot.create(:line_item, order: order1, product: FactoryBot.create(:product, supplier: supplier)) } + let(:shipment1) { FactoryBot.create(:shipment, order:order1) } + let!(:line_item1) { + line_item1 = FactoryBot.create(:line_item, order: order1, target_shipment: shipment1, product: FactoryBot.create(:product, supplier: supplier)) + # make sure target_shipment is available through db reloads of this line_item + line_item1.tap(&:save!) + } let(:line_item_params) { { quantity: 3, final_weight_volume: 3000, price: 3.00 } } let(:params) { { id: line_item1.id, order_id: order1.number, line_item: line_item_params } } @@ -227,7 +237,8 @@ let(:coordinator) { create(:distributor_enterprise) } let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator) } let!(:order1) { FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now, distributor: distributor1, billing_address: FactoryBot.create(:address) ) } - let!(:line_item1) { FactoryBot.create(:line_item, order: order1, product: FactoryBot.create(:product, supplier: supplier)) } + let(:shipment1) { FactoryBot.create(:shipment, order:order1) } + let!(:line_item1) { FactoryBot.create(:line_item, order: order1, target_shipment: shipment1, product: FactoryBot.create(:product, supplier: supplier)) } let(:params) { { id: line_item1.id, order_id: order1.number } } before do From 27f5e6db8a123b2a4c5777859d95f8daca4430fd Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sat, 25 Aug 2018 12:50:36 +0100 Subject: [PATCH 34/42] Fixed bug on order_mailer_decorator. When cancel_email is called with order id in paramater order, order.number will fail. This is only seen in spree 2 because only spree 2 calls this method with order id. Bug introduced here: https://github.com/openfoodfoundation/openfoodnetwork/commit/32d2adc8a24f4352e8c6a0b179fe9ef351295f6d#diff-aa82d768109073ea8ad7858146630be4R9. Spree change introduced here: https://github.com/spree/spree/commit/8d90ae15f807467ffbcc20e779c9ffead577df2a#diff-1e2ba31309f1f1abd2a4b626036d316fR94 --- app/mailers/spree/order_mailer_decorator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/mailers/spree/order_mailer_decorator.rb b/app/mailers/spree/order_mailer_decorator.rb index a4b2db8b70f..d284a704aac 100644 --- a/app/mailers/spree/order_mailer_decorator.rb +++ b/app/mailers/spree/order_mailer_decorator.rb @@ -6,8 +6,8 @@ def cancel_email(order, resend = false) @order = find_order(order) subject = (resend ? "[#{t(:resend).upcase}] " : '') - subject += "#{Spree::Config[:site_name]} #{t('order_mailer.cancel_email.subject')} ##{order.number}" - mail(to: order.email, from: from_address, subject: subject) + subject += "#{Spree::Config[:site_name]} #{t('order_mailer.cancel_email.subject')} ##{@order.number}" + mail(to: @order.email, from: from_address, subject: subject) end def confirm_email_for_customer(order, resend = false) From 0de691b8216f5ec183c7098021b6d37cecd2b6ad Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sat, 25 Aug 2018 13:47:05 +0100 Subject: [PATCH 35/42] Delete outdated base_mailer_decorator.from_address (it used old MailMethod). This way we rely on the correct spree base_mailer.from_address (that gets it from Spree::Config --- app/mailers/spree/base_mailer_decorator.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/mailers/spree/base_mailer_decorator.rb b/app/mailers/spree/base_mailer_decorator.rb index 863f97033a0..44e2b536148 100644 --- a/app/mailers/spree/base_mailer_decorator.rb +++ b/app/mailers/spree/base_mailer_decorator.rb @@ -7,13 +7,6 @@ protected - # This method copies the one defined in Spree's mailers. It should be removed - # once in Spree v2.0 and Spree's BaseMailer class lands in our codebase. - # Then, we'll be able to rely on its #from_address. - def from_address - Spree::MailMethod.current.preferred_mails_from - end - def roadie_options # This lets us specify assets using relative paths in email templates super.merge(url_options: {host: URI(spree.root_url).host }) From efcf6800949e932dea3ada2fe86045e62b579b8b Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Wed, 22 Aug 2018 23:20:30 +0100 Subject: [PATCH 36/42] =?UTF-8?q?Fixed=20bulk=5Fline=5Fitems=5Fcontroller?= =?UTF-8?q?=5Fspec=20by=20setting=20shipment=20on=20test=20line=5Fitems=20?= =?UTF-8?q?and=20by=20allowing=20shipment=20decorator=20to=20allow=20no=20?= =?UTF-8?q?adjustments=20in=20the=20shipment=20Fixed=205=20out=20of=207=20?= =?UTF-8?q?tests=20in=20orders=5Fand=5Ffulfillments=5Freport=5Fspec=20by?= =?UTF-8?q?=20providing=20target=5Fshipment=20in=20test=20line=5Fitems=20F?= =?UTF-8?q?ixed=2012=20out=20of=2044=20broken=20tests=20in=20bulk=5Forder?= =?UTF-8?q?=5Fmanagement=5Fspec.rb=20by=20providing=20target=5Fshipment=20?= =?UTF-8?q?in=20test=20line=5Fitems.=E2=80=9D=20=E2=80=9CThe=20remaining?= =?UTF-8?q?=2032=20failing=20tests=20are=20now=20failing=20with=20the=20ve?= =?UTF-8?q?ry=20common:=20undefined=20method=20on=5Fhand=3D=20on=20Spree::?= =?UTF-8?q?Variant=20Improved=201=20test=20in=20reports=5Fspec.rb=20by=20p?= =?UTF-8?q?roviding=20target=5Fshipment=20in=20test=20line=5Fitems.=20Test?= =?UTF-8?q?=20now=20fails=20with=20undefined=20method=20Spree::Order.shipp?= =?UTF-8?q?ing=5Fmethod=20Fixed=209=20tests=20in=20orders=5Fcontroller=5Fs?= =?UTF-8?q?pec=20by=20providing=20target=5Fshipment=20in=20test=20line=5Fi?= =?UTF-8?q?tems=20Fixed=204=20tests=20in=20packing=5Freport=5Fspec.rb=20by?= =?UTF-8?q?=20providing=20target=5Fshipment=20in=20test=20line=5Fitems.=20?= =?UTF-8?q?Failing=20tests=20are=20now=20failing=20with=20undefined=20prod?= =?UTF-8?q?uct.on=5Fhand=3F=20method=20Fixed=208=20tests=20in=20line=5Fite?= =?UTF-8?q?ms=5Fcontroller=5Fspec=20by=20providing=20target=5Fshipment=20i?= =?UTF-8?q?n=20test=20line=5Fitems=20Fixed=201=20test=20in=20update=5Fbill?= =?UTF-8?q?able=5Fperiods=5Fspec=20by=20providing=20target=5Fshipment=20in?= =?UTF-8?q?=20test=20line=5Fitems=20Fixed=204=20tests=20in=20bulk=5Fcoop?= =?UTF-8?q?=5Freport=5Fspec=20by=20providing=20target=5Fshipment=20in=20te?= =?UTF-8?q?st=20line=5Fitems.=20The=202=20failing=20tests=20are=20now=20fa?= =?UTF-8?q?iling=20with=20undefined=20product.on=5Fhand=3F=20method=20Impr?= =?UTF-8?q?oved=201=20test=20in=20line=5Fitems=5Fcontroller=5Fspec=20by=20?= =?UTF-8?q?providing=20target=5Fshipment=20in=20test=20line=5Fitems.=20Tes?= =?UTF-8?q?t=20is=20still=20failing=20with=20an=20unexpected=20method=20ca?= =?UTF-8?q?ll=20Fixed=201=20test=20in=20order=5Fand=5Fdistributor=5Freport?= =?UTF-8?q?=5Fspec=20by=20providing=20target=5Fshipment=20in=20test=20line?= =?UTF-8?q?=5Fitems?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/bulk_line_items_controller_spec.rb | 27 +++++------- .../spree/admin/line_items_controller_spec.rb | 2 +- .../spree/admin/orders_controller_spec.rb | 14 +++---- .../spree/api/line_items_controller_spec.rb | 2 +- spec/factories.rb | 4 ++ .../admin/bulk_order_management_spec.rb | 42 +++++++++---------- spec/features/admin/reports_spec.rb | 4 +- spec/jobs/update_billable_periods_spec.rb | 20 ++++----- .../bulk_coop_report_spec.rb | 6 +-- .../order_and_distributor_report_spec.rb | 2 +- .../orders_and_fulfillments_report_spec.rb | 8 ++-- .../open_food_network/packing_report_spec.rb | 8 ++-- 12 files changed, 68 insertions(+), 71 deletions(-) diff --git a/spec/controllers/admin/bulk_line_items_controller_spec.rb b/spec/controllers/admin/bulk_line_items_controller_spec.rb index cc4201d0ce8..d6463d5c529 100644 --- a/spec/controllers/admin/bulk_line_items_controller_spec.rb +++ b/spec/controllers/admin/bulk_line_items_controller_spec.rb @@ -11,13 +11,10 @@ let!(:order1) { FactoryBot.create(:order, state: 'complete', completed_at: 1.day.ago, distributor: dist1, billing_address: FactoryBot.create(:address) ) } let!(:order2) { FactoryBot.create(:order, state: 'complete', completed_at: Time.zone.now, distributor: dist1, billing_address: FactoryBot.create(:address) ) } let!(:order3) { FactoryBot.create(:order, state: 'complete', completed_at: Time.zone.now, distributor: dist1, billing_address: FactoryBot.create(:address) ) } - let(:shipment1) { FactoryBot.create(:shipment, order:order1) } - let(:shipment2) { FactoryBot.create(:shipment, order:order2) } - let(:shipment3) { FactoryBot.create(:shipment, order:order3) } - let!(:line_item1) { FactoryBot.create(:line_item, order: order1, target_shipment: shipment1) } - let!(:line_item2) { FactoryBot.create(:line_item, order: order2, target_shipment: shipment2) } - let!(:line_item3) { FactoryBot.create(:line_item, order: order2, target_shipment: shipment2) } - let!(:line_item4) { FactoryBot.create(:line_item, order: order3, target_shipment: shipment3) } + let!(:line_item1) { FactoryBot.create(:line_item_with_shipment, order: order1) } + let!(:line_item2) { FactoryBot.create(:line_item_with_shipment, order: order2) } + let!(:line_item3) { FactoryBot.create(:line_item_with_shipment, order: order2) } + let!(:line_item4) { FactoryBot.create(:line_item_with_shipment, order: order3) } context "as a normal user" do before { controller.stub spree_current_user: create_enterprise_user } @@ -86,12 +83,10 @@ let(:coordinator) { create(:distributor_enterprise) } let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator) } let!(:order1) { FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now, distributor: distributor1, billing_address: FactoryBot.create(:address) ) } - let(:shipment1) { FactoryBot.create(:shipment, order:order1) } - let(:shipment2) { FactoryBot.create(:shipment, order:order2) } - let!(:line_item1) { FactoryBot.create(:line_item, order: order1, target_shipment: shipment1, product: FactoryBot.create(:product, supplier: supplier)) } - let!(:line_item2) { FactoryBot.create(:line_item, order: order1, target_shipment: shipment1, product: FactoryBot.create(:product, supplier: supplier)) } + let!(:line_item1) { FactoryBot.create(:line_item_with_shipment, order: order1, product: FactoryBot.create(:product, supplier: supplier)) } + let!(:line_item2) { FactoryBot.create(:line_item_with_shipment, order: order1, product: FactoryBot.create(:product, supplier: supplier)) } let!(:order2) { FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now, distributor: distributor2, billing_address: FactoryBot.create(:address) ) } - let!(:line_item3) { FactoryBot.create(:line_item, order: order2, target_shipment: shipment2, product: FactoryBot.create(:product, supplier: supplier)) } + let!(:line_item3) { FactoryBot.create(:line_item_with_shipment, order: order2, product: FactoryBot.create(:product, supplier: supplier)) } context "producer enterprise" do before do @@ -136,10 +131,9 @@ let(:coordinator) { create(:distributor_enterprise) } let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator) } let!(:order1) { FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now, distributor: distributor1, billing_address: FactoryBot.create(:address) ) } - let(:shipment1) { FactoryBot.create(:shipment, order:order1) } let!(:line_item1) { - line_item1 = FactoryBot.create(:line_item, order: order1, target_shipment: shipment1, product: FactoryBot.create(:product, supplier: supplier)) - # make sure target_shipment is available through db reloads of this line_item + line_item1 = FactoryBot.create(:line_item_with_shipment, order: order1, product: FactoryBot.create(:product, supplier: supplier)) + # make sure shipment is available through db reloads of this line_item line_item1.tap(&:save!) } let(:line_item_params) { { quantity: 3, final_weight_volume: 3000, price: 3.00 } } @@ -237,8 +231,7 @@ let(:coordinator) { create(:distributor_enterprise) } let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator) } let!(:order1) { FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now, distributor: distributor1, billing_address: FactoryBot.create(:address) ) } - let(:shipment1) { FactoryBot.create(:shipment, order:order1) } - let!(:line_item1) { FactoryBot.create(:line_item, order: order1, target_shipment: shipment1, product: FactoryBot.create(:product, supplier: supplier)) } + let!(:line_item1) { FactoryBot.create(:line_item_with_shipment, order: order1, product: FactoryBot.create(:product, supplier: supplier)) } let(:params) { { id: line_item1.id, order_id: order1.number } } before do diff --git a/spec/controllers/spree/admin/line_items_controller_spec.rb b/spec/controllers/spree/admin/line_items_controller_spec.rb index 5b7575e7e5a..64cf29903e8 100644 --- a/spec/controllers/spree/admin/line_items_controller_spec.rb +++ b/spec/controllers/spree/admin/line_items_controller_spec.rb @@ -26,7 +26,7 @@ let(:coordinator) { create(:distributor_enterprise) } let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator) } let!(:order1) { FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now, distributor: distributor1, billing_address: FactoryBot.create(:address) ) } - let!(:line_item1) { FactoryBot.create(:line_item, order: order1, product: FactoryBot.create(:product, supplier: supplier)) } + let!(:line_item1) { FactoryBot.create(:line_item_with_shipment, order: order1, product: FactoryBot.create(:product, supplier: supplier)) } let(:line_item_params) { { quantity: 3, final_weight_volume: 3000, price: 3.00 } } let(:params) { { id: line_item1.id, order_id: order1.number, line_item: line_item_params } } diff --git a/spec/controllers/spree/admin/orders_controller_spec.rb b/spec/controllers/spree/admin/orders_controller_spec.rb index 25c2683d4d6..184a77cb11e 100644 --- a/spec/controllers/spree/admin/orders_controller_spec.rb +++ b/spec/controllers/spree/admin/orders_controller_spec.rb @@ -39,10 +39,10 @@ def self.make_simple_data! let!(:order1) { FactoryBot.create(:order, state: 'complete', completed_at: Time.zone.now, distributor: dist1, billing_address: FactoryBot.create(:address) ) } let!(:order2) { FactoryBot.create(:order, state: 'complete', completed_at: Time.zone.now, distributor: dist1, billing_address: FactoryBot.create(:address) ) } let!(:order3) { FactoryBot.create(:order, state: 'complete', completed_at: Time.zone.now, distributor: dist1, billing_address: FactoryBot.create(:address) ) } - let!(:line_item1) { FactoryBot.create(:line_item, order: order1) } - let!(:line_item2) { FactoryBot.create(:line_item, order: order2) } - let!(:line_item3) { FactoryBot.create(:line_item, order: order2) } - let!(:line_item4) { FactoryBot.create(:line_item, order: order3) } + let!(:line_item1) { FactoryBot.create(:line_item_with_shipment, order: order1) } + let!(:line_item2) { FactoryBot.create(:line_item_with_shipment, order: order2) } + let!(:line_item3) { FactoryBot.create(:line_item_with_shipment, order: order2) } + let!(:line_item4) { FactoryBot.create(:line_item_with_shipment, order: order3) } let(:line_item_attributes) { [:id, :quantity, :max_quantity, :supplier, :units_product, :units_variant] } end @@ -96,10 +96,10 @@ def self.make_simple_data! let(:coordinator) { create(:distributor_enterprise) } let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator) } let!(:order1) { FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now, distributor: distributor1, billing_address: FactoryBot.create(:address) ) } - let!(:line_item1) { FactoryBot.create(:line_item, order: order1, product: FactoryBot.create(:product, supplier: supplier)) } - let!(:line_item2) { FactoryBot.create(:line_item, order: order1, product: FactoryBot.create(:product, supplier: supplier)) } + let!(:line_item1) { FactoryBot.create(:line_item_with_shipment, order: order1, product: FactoryBot.create(:product, supplier: supplier)) } + let!(:line_item2) { FactoryBot.create(:line_item_with_shipment, order: order1, product: FactoryBot.create(:product, supplier: supplier)) } let!(:order2) { FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now, distributor: distributor2, billing_address: FactoryBot.create(:address) ) } - let!(:line_item3) { FactoryBot.create(:line_item, order: order2, product: FactoryBot.create(:product, supplier: supplier)) } + let!(:line_item3) { FactoryBot.create(:line_item_with_shipment, order: order2, product: FactoryBot.create(:product, supplier: supplier)) } context "producer enterprise" do diff --git a/spec/controllers/spree/api/line_items_controller_spec.rb b/spec/controllers/spree/api/line_items_controller_spec.rb index 47c09f36b60..6a63fe617f1 100644 --- a/spec/controllers/spree/api/line_items_controller_spec.rb +++ b/spec/controllers/spree/api/line_items_controller_spec.rb @@ -13,7 +13,7 @@ module Spree sign_in_as_admin! let(:order) { FactoryBot.create(:order, state: 'complete', completed_at: Time.zone.now) } - let(:line_item) { FactoryBot.create(:line_item, order: order, final_weight_volume: 500) } + let(:line_item) { FactoryBot.create(:line_item_with_shipment, order: order,final_weight_volume: 500) } context "as a line item is updated" do before { allow(controller).to receive(:order) { order } } diff --git a/spec/factories.rb b/spec/factories.rb index e387f519e8b..f8f66b699a7 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -356,6 +356,10 @@ end end + factory :line_item_with_shipment, parent: :line_item do + target_shipment { create(:shipment, order: order) } + end + factory :zone_with_member, :parent => :zone do default_tax true diff --git a/spec/features/admin/bulk_order_management_spec.rb b/spec/features/admin/bulk_order_management_spec.rb index f028776121e..33e288a4879 100644 --- a/spec/features/admin/bulk_order_management_spec.rb +++ b/spec/features/admin/bulk_order_management_spec.rb @@ -21,8 +21,8 @@ let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) } let!(:o2) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) } let!(:o3) { create(:order_with_distributor, state: 'address', completed_at: nil ) } - let!(:li1) { create(:line_item, order: o1 ) } - let!(:li2) { create(:line_item, order: o2 ) } + let!(:li1) { create(:line_item_with_shipment, order: o1) } + let!(:li2) { create(:line_item_with_shipment, order: o2) } let!(:li3) { create(:line_item, order: o3 ) } before :each do @@ -39,8 +39,8 @@ context "displaying individual columns" do let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, bill_address: create(:address) ) } let!(:o2) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, bill_address: nil ) } - let!(:li1) { create(:line_item, order: o1 ) } - let!(:li2) { create(:line_item, order: o2, product: create(:product_with_option_types) ) } + let!(:li1) { create(:line_item_with_shipment, order: o1) } + let!(:li2) { create(:line_item_with_shipment, order: o2, product: create(:product_with_option_types) ) } before :each do visit '/admin/orders/bulk_management' @@ -86,8 +86,8 @@ describe "sorting of line items" do let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now) } let!(:o2) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now) } - let!(:li1) { create(:line_item, order: o1) } - let!(:li2) { create(:line_item, order: o2) } + let!(:li1) { create(:line_item_with_shipment, order: o1) } + let!(:li2) { create(:line_item_with_shipment, order: o2) } before do visit spree.admin_bulk_order_management_path @@ -125,7 +125,7 @@ context "tracking changes" do let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) } - let!(:li1) { create(:line_item, order: o1, :quantity => 5 ) } + let!(:li1) { create(:line_item_with_shipment, order: o1, :quantity => 5 ) } before :each do visit '/admin/orders/bulk_management' @@ -140,7 +140,7 @@ context "submitting data to the server" do let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) } - let!(:li1) { create(:line_item, order: o1, :quantity => 5 ) } + let!(:li1) { create(:line_item_with_shipment, order: o1, :quantity => 5 ) } before :each do li1.variant.update_attributes(on_hand: 1, on_demand: false) @@ -182,7 +182,7 @@ let!(:p1) { create(:product_with_option_types, group_buy: true, group_buy_unit_size: 5000, variant_unit: "weight", variants: [create(:variant, unit_value: 1000)] ) } let!(:v1) { p1.variants.first } let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) } - let!(:li1) { create(:line_item, order: o1, variant: v1, :quantity => 5, :final_weight_volume => 1000, price: 10.00 ) } + let!(:li1) { create(:line_item_with_shipment, order: o1, variant: v1, :quantity => 5, :final_weight_volume => 1000, price: 10.00 ) } before { v1.update_attribute(:on_hand, 100)} @@ -264,7 +264,7 @@ let!(:s1) { create(:supplier_enterprise) } let!(:s2) { create(:supplier_enterprise) } let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, order_cycle: create(:simple_order_cycle) ) } - let!(:li1) { create(:line_item, order: o1, product: create(:product, supplier: s1) ) } + let!(:li1) { create(:line_item_with_shipment, order: o1, product: create(:product, supplier: s1) ) } let!(:li2) { create(:line_item, order: o1, product: create(:product, supplier: s2) ) } before :each do @@ -302,7 +302,7 @@ let!(:d2) { create(:distributor_enterprise) } let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, distributor: d1, order_cycle: create(:simple_order_cycle) ) } let!(:o2) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, distributor: d2, order_cycle: create(:simple_order_cycle) ) } - let!(:li1) { create(:line_item, order: o1 ) } + let!(:li1) { create(:line_item_with_shipment, order: o1 ) } let!(:li2) { create(:line_item, order: o2 ) } before :each do @@ -341,7 +341,7 @@ let!(:oc2) { create(:simple_order_cycle, distributors: [distributor]) } let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, order_cycle: oc1 ) } let!(:o2) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, order_cycle: oc2 ) } - let!(:li1) { create(:line_item, order: o1 ) } + let!(:li1) { create(:line_item_with_shipment, order: o1 ) } let!(:li2) { create(:line_item, order: o2 ) } before do @@ -381,7 +381,7 @@ let!(:p2) { create(:product, supplier: s2) } let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, distributor: d1, order_cycle: oc1 ) } let!(:o2) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, distributor: d2, order_cycle: oc2 ) } - let!(:li1) { create(:line_item, order: o1, product: p1 ) } + let!(:li1) { create(:line_item_with_shipment, order: o1, product: p1 ) } let!(:li2) { create(:line_item, order: o2, product: p2 ) } before :each do @@ -430,7 +430,7 @@ let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) } let!(:o2) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) } let!(:o3) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) } - let!(:li1) { create(:line_item, order: o1 ) } + let!(:li1) { create(:line_item_with_shipment, order: o1 ) } let!(:li2) { create(:line_item, order: o2 ) } let!(:li3) { create(:line_item, order: o3 ) } @@ -458,7 +458,7 @@ let!(:o2) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.today - 7.days) } let!(:o3) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now.end_of_day) } let!(:o4) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now.end_of_day + 1.second) } - let!(:li1) { create(:line_item, order: o1, :quantity => 1 ) } + let!(:li1) { create(:line_item_with_shipment, order: o1, :quantity => 1 ) } let!(:li2) { create(:line_item, order: o2, :quantity => 2 ) } let!(:li3) { create(:line_item, order: o3, :quantity => 3 ) } let!(:li4) { create(:line_item, order: o4, :quantity => 4 ) } @@ -528,7 +528,7 @@ context "bulk action controls" do let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) } let!(:o2) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) } - let!(:li1) { create(:line_item, order: o1 ) } + let!(:li1) { create(:line_item_with_shipment, order: o1 ) } let!(:li2) { create(:line_item, order: o2 ) } before :each do @@ -595,7 +595,7 @@ context "using edit buttons" do let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) } let!(:o2) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) } - let!(:li1) { create(:line_item, order: o1 ) } + let!(:li1) { create(:line_item_with_shipment, order: o1 ) } let!(:li2) { create(:line_item, order: o2 ) } before :each do @@ -629,7 +629,7 @@ context "using delete buttons" do let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) } let!(:o2) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) } - let!(:li1) { create(:line_item, order: o1 ) } + let!(:li1) { create(:line_item_with_shipment, order: o1 ) } let!(:li2) { create(:line_item, order: o2 ) } before :each do @@ -650,7 +650,7 @@ context "clicking the link on variant name" do let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) } let!(:o2) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) } - let!(:li1) { create(:line_item, order: o1 ) } + let!(:li1) { create(:line_item_with_shipment, order: o1 ) } let!(:li2) { create(:line_item, order: o2 ) } let!(:p3) { create(:product_with_option_types, group_buy: true, group_buy_unit_size: 5000, variant_unit: "weight", variants: [create(:variant, unit_value: 1000)] ) } let!(:v3) { p3.variants.first } @@ -716,8 +716,8 @@ let(:d2) { create(:distributor_enterprise, name: 'Another Distributor') } let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, distributor: d1 ) } let!(:o2) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, distributor: d2 ) } - let!(:line_item_distributed) { create(:line_item, order: o1, product: create(:product, supplier: s1) ) } - let!(:line_item_not_distributed) { create(:line_item, order: o2, product: create(:product, supplier: s1) ) } + let!(:line_item_distributed) { create(:line_item_with_shipment, order: o1, product: create(:product, supplier: s1) ) } + let!(:line_item_not_distributed) { create(:line_item_with_shipment, order: o2, product: create(:product, supplier: s1) ) } before(:each) do @enterprise_user = create_enterprise_user diff --git a/spec/features/admin/reports_spec.rb b/spec/features/admin/reports_spec.rb index 3435d487e6e..52e89502703 100644 --- a/spec/features/admin/reports_spec.rb +++ b/spec/features/admin/reports_spec.rb @@ -260,8 +260,8 @@ Timecop.travel(Time.zone.local(2013, 4, 25, 14, 0, 0)) { order1.finalize! } Timecop.travel(Time.zone.local(2013, 4, 25, 16, 0, 0)) { order2.finalize! } - create(:line_item, :product => product, :order => order1) - create(:line_item, :product => product, :order => order2) + create(:line_item_with_shipment, :product => product, :order => order1) + create(:line_item_with_shipment, :product => product, :order => order2) end it "is precise to time of day, not just date" do diff --git a/spec/jobs/update_billable_periods_spec.rb b/spec/jobs/update_billable_periods_spec.rb index 5024fd6dac1..1b461e7f2a2 100644 --- a/spec/jobs/update_billable_periods_spec.rb +++ b/spec/jobs/update_billable_periods_spec.rb @@ -586,16 +586,16 @@ def travel_to(time) let!(:order10) { create(:order, completed_at: start_of_july + 19.days, distributor: enterprise) } before do - order1.line_items = [ create(:line_item, price: 12.56, order: order1) ] - order2.line_items = [ create(:line_item, price: 87.44, order: order2) ] - order3.line_items = [ create(:line_item, price: 50.00, order: order3) ] - order4.line_items = [ create(:line_item, price: 73.37, order: order4) ] - order5.line_items = [ create(:line_item, price: 22.46, order: order5) ] - order6.line_items = [ create(:line_item, price: 44.85, order: order6) ] - order7.line_items = [ create(:line_item, price: 93.45, order: order7) ] - order8.line_items = [ create(:line_item, price: 59.38, order: order8) ] - order9.line_items = [ create(:line_item, price: 47.23, order: order9) ] - order10.line_items = [ create(:line_item, price: 2.35, order: order10) ] + order1.line_items = [ create(:line_item_with_shipment, price: 12.56, order: order1) ] + order2.line_items = [ create(:line_item_with_shipment, price: 87.44, order: order2) ] + order3.line_items = [ create(:line_item_with_shipment, price: 50.00, order: order3) ] + order4.line_items = [ create(:line_item_with_shipment, price: 73.37, order: order4) ] + order5.line_items = [ create(:line_item_with_shipment, price: 22.46, order: order5) ] + order6.line_items = [ create(:line_item_with_shipment, price: 44.85, order: order6) ] + order7.line_items = [ create(:line_item_with_shipment, price: 93.45, order: order7) ] + order8.line_items = [ create(:line_item_with_shipment, price: 59.38, order: order8) ] + order9.line_items = [ create(:line_item_with_shipment, price: 47.23, order: order9) ] + order10.line_items = [ create(:line_item_with_shipment, price: 2.35, order: order10) ] [order1, order2, order3, order4, order5, order6, order7, order8, order9, order10].each(&:update!) allow(Enterprise).to receive(:where) { double(:enterprises, select: [enterprise]) } diff --git a/spec/lib/open_food_network/bulk_coop_report_spec.rb b/spec/lib/open_food_network/bulk_coop_report_spec.rb index 7ee263fc55f..695f98359e3 100644 --- a/spec/lib/open_food_network/bulk_coop_report_spec.rb +++ b/spec/lib/open_food_network/bulk_coop_report_spec.rb @@ -8,7 +8,7 @@ module OpenFoodNetwork let(:d1) { create(:distributor_enterprise) } let(:oc1) { create(:simple_order_cycle) } let(:o1) { create(:order, completed_at: 1.day.ago, order_cycle: oc1, distributor: d1) } - let(:li1) { build(:line_item) } + let(:li1) { build(:line_item_with_shipment) } before { o1.line_items << li1 } @@ -24,7 +24,7 @@ module OpenFoodNetwork it "does not show cancelled orders" do o2 = create(:order, state: "canceled", completed_at: 1.day.ago) - o2.line_items << build(:line_item) + o2.line_items << build(:line_item_with_shipment) subject.table_items.should == [li1] end end @@ -80,7 +80,7 @@ module OpenFoodNetwork d2 = create(:distributor_enterprise) d2.enterprise_roles.create!(user: create(:user)) o2 = create(:order, distributor: d2, completed_at: 1.day.ago) - o2.line_items << build(:line_item) + o2.line_items << build(:line_item_with_shipment) subject.table_items.should == [li1] end diff --git a/spec/lib/open_food_network/order_and_distributor_report_spec.rb b/spec/lib/open_food_network/order_and_distributor_report_spec.rb index 4cd03de91c4..f943aabdd0e 100644 --- a/spec/lib/open_food_network/order_and_distributor_report_spec.rb +++ b/spec/lib/open_food_network/order_and_distributor_report_spec.rb @@ -22,7 +22,7 @@ module OpenFoodNetwork let(:order) { create(:order, state: 'complete', completed_at: Time.zone.now, distributor: distributor, bill_address: bill_address, special_instructions: shipping_instructions) } let(:payment_method) { create(:payment_method, distributors: [distributor]) } let(:payment) { create(:payment, payment_method: payment_method, order: order) } - let(:line_item) { create(:line_item, product: product, order: order) } + let(:line_item) { create(:line_item_with_shipment, product: product, order: order) } before do order.payments << payment diff --git a/spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb b/spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb index a33722859cd..949721afbd3 100644 --- a/spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb +++ b/spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb @@ -8,7 +8,7 @@ module OpenFoodNetwork let(:d1) { create(:distributor_enterprise) } let(:oc1) { create(:simple_order_cycle) } let(:o1) { create(:order, completed_at: 1.day.ago, order_cycle: oc1, distributor: d1) } - let(:li1) { build(:line_item) } + let(:li1) { build(:line_item_with_shipment) } before { o1.line_items << li1 } @@ -24,7 +24,7 @@ module OpenFoodNetwork it "does not show cancelled orders" do o2 = create(:order, state: "canceled", completed_at: 1.day.ago) - o2.line_items << build(:line_item) + o2.line_items << build(:line_item_with_shipment) subject.table_items.should == [li1] end end @@ -80,7 +80,7 @@ module OpenFoodNetwork d2 = create(:distributor_enterprise) d2.enterprise_roles.create!(user: create(:user)) o2 = create(:order, distributor: d2, completed_at: 1.day.ago) - o2.line_items << build(:line_item) + o2.line_items << build(:line_item_with_shipment) subject.table_items.should == [li1] end @@ -98,7 +98,7 @@ module OpenFoodNetwork let(:d1) { create(:distributor_enterprise) } let(:oc1) { create(:simple_order_cycle) } let(:o1) { create(:order, completed_at: 1.day.ago, order_cycle: oc1, distributor: d1) } - let(:li1) { build(:line_item) } + let(:li1) { build(:line_item_with_shipment) } let(:user) { create(:admin_user)} before { o1.line_items << li1 } diff --git a/spec/lib/open_food_network/packing_report_spec.rb b/spec/lib/open_food_network/packing_report_spec.rb index b9074a92bfa..f6c32264b40 100644 --- a/spec/lib/open_food_network/packing_report_spec.rb +++ b/spec/lib/open_food_network/packing_report_spec.rb @@ -8,7 +8,7 @@ module OpenFoodNetwork let(:d1) { create(:distributor_enterprise) } let(:oc1) { create(:simple_order_cycle) } let(:o1) { create(:order, completed_at: 1.day.ago, order_cycle: oc1, distributor: d1) } - let(:li1) { build(:line_item) } + let(:li1) { build(:line_item_with_shipment) } before { o1.line_items << li1 } @@ -24,7 +24,7 @@ module OpenFoodNetwork it "does not show cancelled orders" do o2 = create(:order, state: "canceled", completed_at: 1.day.ago) - o2.line_items << build(:line_item) + o2.line_items << build(:line_item_with_shipment) subject.table_items.should == [li1] end end @@ -41,7 +41,7 @@ module OpenFoodNetwork context "that has granted P-OC to the distributor" do let(:o2) { create(:order, distributor: d1, completed_at: 1.day.ago, bill_address: create(:address), ship_address: create(:address)) } - let(:li2) { build(:line_item, product: create(:simple_product, supplier: s1)) } + let(:li2) { build(:line_item_with_shipment, product: create(:simple_product, supplier: s1)) } before do o2.line_items << li2 @@ -80,7 +80,7 @@ module OpenFoodNetwork d2 = create(:distributor_enterprise) d2.enterprise_roles.create!(user: create(:user)) o2 = create(:order, distributor: d2, completed_at: 1.day.ago) - o2.line_items << build(:line_item) + o2.line_items << build(:line_item_with_shipment) subject.table_items.should == [li1] end From c7648d67bd4318245a6c8f1b2e82cb694bd59e5a Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Tue, 28 Aug 2018 14:58:57 +1000 Subject: [PATCH 37/42] Add Variant stock API of Spree 1 --- app/models/spree/variant_decorator.rb | 2 + lib/open_food_network/variant_stock.rb | 80 ++++++++++++++++++++++++++ spec/factories.rb | 11 ++++ 3 files changed, 93 insertions(+) create mode 100644 lib/open_food_network/variant_stock.rb diff --git a/app/models/spree/variant_decorator.rb b/app/models/spree/variant_decorator.rb index 2947efc2826..3a97048c7c0 100644 --- a/app/models/spree/variant_decorator.rb +++ b/app/models/spree/variant_decorator.rb @@ -1,5 +1,6 @@ require 'open_food_network/enterprise_fee_calculator' require 'open_food_network/variant_and_line_item_naming' +require 'open_food_network/variant_stock' require 'open_food_network/products_cache' Spree::Variant.class_eval do @@ -9,6 +10,7 @@ # removing the Spree method to prevent error. remove_method :options_text if instance_methods(false).include? :options_text include OpenFoodNetwork::VariantAndLineItemNaming + include OpenFoodNetwork::VariantStock has_many :exchange_variants has_many :exchanges, through: :exchange_variants diff --git a/lib/open_food_network/variant_stock.rb b/lib/open_food_network/variant_stock.rb new file mode 100644 index 00000000000..fba38ebd57a --- /dev/null +++ b/lib/open_food_network/variant_stock.rb @@ -0,0 +1,80 @@ +require 'active_support/concern' + +# These methods were available in Spree 1, but were removed in Spree 2. +# We would still like to use them. Therefore we use only a single stock location +# (default stock location) and use it to track the `count_on_hand` value that +# was previously a database column on variants. +# +# We may decide to deprecate these methods after we designed the Network feature. +module OpenFoodNetwork + module VariantStock + extend ActiveSupport::Concern + + included do + after_save :save_stock + end + + def on_hand + if on_demand + Float::INFINITY + else + total_on_hand + end + end + + def count_on_hand + total_on_hand + end + + def on_hand=(new_level) + 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 + + def count_on_hand=(new_level) + raise_error_if_no_stock_item_available + overwrite_stock_levels new_level + end + + def on_demand + stock_items.any?(&:backorderable?) + end + + def on_demand=(new_value) + raise_error_if_no_stock_item_available + + # There should be only one at the default stock location. + stock_items.each do |item| + item.backorderable = new_value + end + end + + private + + def save_stock + stock_items.each(&:save) + end + + def raise_error_if_no_stock_item_available + message = 'You need to save the variant to create a stock item before you can set stock levels.' + raise message if stock_items.empty? + end + + # Backwards compatible setting of stock levels in Spree 2.0. + # It would be better to use `Spree::StockItem.adjust_count_on_hand` which + # takes a value to add to the current stock level and uses proper locking. + # But this should work the same as in Spree 1.3. + def overwrite_stock_levels(new_level) + stock_items.first.send :count_on_hand=, new_level + + # There shouldn't be any other stock items, because we should have only one + # stock location. But in case there are, the total should be new_level, + # so all others need to be zero. + stock_items[1..-1].each do |item| + item.send :count_on_hand=, 0 + end + end + end +end diff --git a/spec/factories.rb b/spec/factories.rb index e387f519e8b..71dbc0dcded 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -483,8 +483,19 @@ end factory :variant do + transient do + on_demand { false } + on_hand { 5 } + end + unit_value 1 unit_description '' + + after(:create) do |variant, evaluator| + variant.on_demand = evaluator.on_demand + variant.count_on_hand = evaluator.on_hand + variant.save + end end factory :shipping_method do From e9c18687595922ea6d95e27535081a771561cc28 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Tue, 28 Aug 2018 17:22:33 +1000 Subject: [PATCH 38/42] Update factory to fix tests In Spree 2, products don't have `on_hand` or `on_demand` any more. But we always create a standard variant in an after-save hook which accepts these values due to our backwards compatibility patch. --- spec/factories.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/spec/factories.rb b/spec/factories.rb index 71dbc0dcded..18b2de7179b 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -455,7 +455,17 @@ end factory :simple_product, parent: :base_product do - on_hand 5 + transient do + on_demand { false } + on_hand { 5 } + end + after(:create) do |product, evaluator| + product.variants.first.tap do |variant| + variant.on_demand = evaluator.on_demand + variant.count_on_hand = evaluator.on_hand + variant.save + end + end end end From cebcdea40cdf0584e59af9af38f634a685e93a60 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 30 Aug 2018 10:14:35 +1000 Subject: [PATCH 39/42] Replace obsolete `count_on_hand` call for variant The variant factory supports only `on_hand` now. --- spec/controllers/spree/orders_controller_spec.rb | 6 +++--- spec/jobs/subscription_placement_job_spec.rb | 6 +++--- spec/lib/open_food_network/lettuce_share_report_spec.rb | 2 +- spec/lib/open_food_network/scope_variant_to_hub_spec.rb | 2 +- spec/models/variant_override_spec.rb | 2 +- spec/services/subscription_form_spec.rb | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index fbcd5ec1078..4d96ae051c3 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -82,8 +82,8 @@ describe "generating stock levels" do let!(:order) { create(:order) } let!(:li) { create(:line_item, order: order, variant: v, quantity: 2, max_quantity: 3) } - let!(:v) { create(:variant, count_on_hand: 4) } - let!(:v2) { create(:variant, count_on_hand: 2) } + let!(:v) { create(:variant, on_hand: 4) } + let!(:v2) { create(:variant, on_hand: 2) } before do order.reload @@ -107,7 +107,7 @@ end describe "encoding Infinity" do - let!(:v) { create(:variant, on_demand: true, count_on_hand: 0) } + let!(:v) { create(:variant, on_demand: true, on_hand: 0) } it "encodes Infinity as a large, finite integer" do controller.stock_levels(order, [v.id]).should == diff --git a/spec/jobs/subscription_placement_job_spec.rb b/spec/jobs/subscription_placement_job_spec.rb index b1013081d64..453b155962b 100644 --- a/spec/jobs/subscription_placement_job_spec.rb +++ b/spec/jobs/subscription_placement_job_spec.rb @@ -64,9 +64,9 @@ let(:shop) { order_cycle.coordinator } let(:order) { create(:order, order_cycle: order_cycle, distributor: shop) } let(:ex) { create(:exchange, :order_cycle => order_cycle, :sender => shop, :receiver => shop, :incoming => false) } - let(:variant1) { create(:variant, count_on_hand: 5) } - let(:variant2) { create(:variant, count_on_hand: 5) } - let(:variant3) { create(:variant, count_on_hand: 5) } + let(:variant1) { create(:variant, on_hand: 5) } + let(:variant2) { create(:variant, on_hand: 5) } + let(:variant3) { create(:variant, on_hand: 5) } let!(:line_item1) { create(:line_item, order: order, variant: variant1, quantity: 3) } let!(:line_item2) { create(:line_item, order: order, variant: variant2, quantity: 3) } let!(:line_item3) { create(:line_item, order: order, variant: variant3, quantity: 3) } diff --git a/spec/lib/open_food_network/lettuce_share_report_spec.rb b/spec/lib/open_food_network/lettuce_share_report_spec.rb index 5a871cfbbb5..99a9254abd8 100644 --- a/spec/lib/open_food_network/lettuce_share_report_spec.rb +++ b/spec/lib/open_food_network/lettuce_share_report_spec.rb @@ -36,7 +36,7 @@ module OpenFoodNetwork describe "lists" do let(:v2) { create(:variant) } let(:v3) { create(:variant) } - let(:v4) { create(:variant, count_on_hand: 0, on_demand: true) } + let(:v4) { create(:variant, on_hand: 0, on_demand: true) } let(:hub_address) { create(:address, :address1 => "distributor address", :city => 'The Shire', :zipcode => "1234") } let(:hub) { create(:distributor_enterprise, :address => hub_address) } let(:v2o) { create(:variant_override, hub: hub, variant: v2) } diff --git a/spec/lib/open_food_network/scope_variant_to_hub_spec.rb b/spec/lib/open_food_network/scope_variant_to_hub_spec.rb index c3b2f2f8ec6..ac79d943ac8 100644 --- a/spec/lib/open_food_network/scope_variant_to_hub_spec.rb +++ b/spec/lib/open_food_network/scope_variant_to_hub_spec.rb @@ -3,7 +3,7 @@ module OpenFoodNetwork describe ScopeVariantToHub do let(:hub) { create(:distributor_enterprise) } - let(:v) { create(:variant, price: 11.11, count_on_hand: 1, on_demand: true, sku: "VARIANTSKU") } + let(:v) { create(:variant, price: 11.11, on_hand: 1, on_demand: true, sku: "VARIANTSKU") } let(:vo) { create(:variant_override, hub: hub, variant: v, price: 22.22, count_on_hand: 2, on_demand: false, sku: "VOSKU") } let(:vo_price_only) { create(:variant_override, hub: hub, variant: v, price: 22.22, count_on_hand: nil) } let(:scoper) { ScopeVariantToHub.new(hub) } diff --git a/spec/models/variant_override_spec.rb b/spec/models/variant_override_spec.rb index 0a07fdd1af6..8275e820135 100644 --- a/spec/models/variant_override_spec.rb +++ b/spec/models/variant_override_spec.rb @@ -59,7 +59,7 @@ describe "looking up count on hand" do it "returns the numeric stock level when present" do - VariantOverride.create!(variant: variant, hub: hub, count_on_hand: 12) + VariantOverride.create!(variant: variant, hub: hub, on_hand: 12) VariantOverride.count_on_hand_for(hub, variant).should == 12 end diff --git a/spec/services/subscription_form_spec.rb b/spec/services/subscription_form_spec.rb index 2f4a19953e2..3e2e8f5842a 100644 --- a/spec/services/subscription_form_spec.rb +++ b/spec/services/subscription_form_spec.rb @@ -7,7 +7,7 @@ let!(:product3) { create(:product, supplier: shop) } let!(:variant1) { create(:variant, product: product1, unit_value: '100', price: 12.00, option_values: []) } let!(:variant2) { create(:variant, product: product2, unit_value: '1000', price: 6.00, option_values: []) } - let!(:variant3) { create(:variant, product: product2, unit_value: '1000', price: 2.50, option_values: [], count_on_hand: 1) } + let!(:variant3) { create(:variant, product: product2, unit_value: '1000', price: 2.50, option_values: [], on_hand: 1) } let!(:enterprise_fee) { create(:enterprise_fee, amount: 1.75) } let!(:order_cycle1) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 9.days.ago, orders_close_at: 2.days.ago) } let!(:order_cycle2) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 2.days.ago, orders_close_at: 5.days.from_now) } From 921c8dfdf45c0ae74f3456969e4fa05560e628d2 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Fri, 31 Aug 2018 19:41:30 +0100 Subject: [PATCH 40/42] Removed unnecessary cancel_email from order_email_decorator (spree one is equivalent after ofn PR#2589). Also refactored remaining order_mailer_decorator methods by extracting duplicated code. --- app/mailers/spree/order_mailer_decorator.rb | 39 ++++++++++----------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/app/mailers/spree/order_mailer_decorator.rb b/app/mailers/spree/order_mailer_decorator.rb index d284a704aac..0ff7e215589 100644 --- a/app/mailers/spree/order_mailer_decorator.rb +++ b/app/mailers/spree/order_mailer_decorator.rb @@ -3,43 +3,42 @@ helper CheckoutHelper helper SpreeCurrencyHelper - def cancel_email(order, resend = false) - @order = find_order(order) - subject = (resend ? "[#{t(:resend).upcase}] " : '') - subject += "#{Spree::Config[:site_name]} #{t('order_mailer.cancel_email.subject')} ##{@order.number}" - mail(to: @order.email, from: from_address, subject: subject) - end - - def confirm_email_for_customer(order, resend = false) - find_order(order) # Finds an order instance from an id - subject = (resend ? "[#{t(:resend).upcase}] " : '') - subject += "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{@order.number}" + def confirm_email_for_customer(order_or_order_id, resend = false) + @order = find_order(order_or_order_id) + subject = build_subject(t('order_mailer.confirm_email.subject'), resend) mail(:to => @order.email, :from => from_address, :subject => subject, :reply_to => @order.distributor.contact.email) end - def confirm_email_for_shop(order, resend = false) - find_order(order) # Finds an order instance from an id - subject = (resend ? "[#{t(:resend).upcase}] " : '') - subject += "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{@order.number}" + def confirm_email_for_shop(order_or_order_id, resend = false) + @order = find_order(order_or_order_id) + subject = build_subject(t('order_mailer.confirm_email.subject'), resend) mail(:to => @order.distributor.contact.email, :from => from_address, :subject => subject) end - def invoice_email(order, pdf) - find_order(order) # Finds an order instance from an id + def invoice_email(order_or_order_id, pdf) + @order = find_order(order_or_order_id) + subject = build_subject(t(:invoice)) attachments["invoice-#{@order.number}.pdf"] = pdf if pdf.present? - subject = "#{Spree::Config[:site_name]} #{t(:invoice)} ##{@order.number}" mail(:to => @order.email, :from => from_address, :subject => subject, :reply_to => @order.distributor.contact.email) end - def find_order(order) - @order = order.respond_to?(:id) ? order : Spree::Order.find(order) + private + + # Finds an order instance from an order or from an order id + def find_order(order_or_order_id) + order_or_order_id.respond_to?(:id) ? order_or_order_id : Spree::Order.find(order_or_order_id) + end + + def build_subject( subject_text, resend = false ) + subject = (resend ? "[#{t(:resend).upcase}] " : "") + subject += "#{Spree::Config[:site_name]} #{subject_text} ##{@order.number}" end end From 8004abbb9f530072e6abbed7e756ec49e5431adc Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Fri, 31 Aug 2018 19:42:30 +0100 Subject: [PATCH 41/42] Improved Order mailer and Subscriptions mailer specs by removing dependency to old mail method --- spec/mailers/order_mailer_spec.rb | 2 -- spec/mailers/subscription_mailer_spec.rb | 2 -- 2 files changed, 4 deletions(-) diff --git a/spec/mailers/order_mailer_spec.rb b/spec/mailers/order_mailer_spec.rb index 49de9853254..55e4b6b3608 100644 --- a/spec/mailers/order_mailer_spec.rb +++ b/spec/mailers/order_mailer_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' describe Spree::OrderMailer do - let!(:mail_method) { create(:mail_method, preferred_mails_from: 'spree@example.com') } - describe "order confimation" do after do ActionMailer::Base.deliveries.clear diff --git a/spec/mailers/subscription_mailer_spec.rb b/spec/mailers/subscription_mailer_spec.rb index cca7e5258d2..5b1dec69ae3 100644 --- a/spec/mailers/subscription_mailer_spec.rb +++ b/spec/mailers/subscription_mailer_spec.rb @@ -3,8 +3,6 @@ describe SubscriptionMailer do include ActionView::Helpers::SanitizeHelper - let!(:mail_method) { create(:mail_method, preferred_mails_from: 'spree@example.com') } - describe "order placement" do let(:subscription) { create(:subscription, with_items: true) } let(:proxy_order) { create(:proxy_order, subscription: subscription) } From 5df04ad6888634717ed3ec2f5f894def840d3938 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Thu, 6 Sep 2018 22:45:22 +0100 Subject: [PATCH 42/42] Added adapted implementation of order.shipping_method to order_decorator --- app/models/spree/order_decorator.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 458742ebf4a..779162b9b2d 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -333,6 +333,13 @@ def pending_payments payments.select {|p| p.state == "checkout"} # Original definition end + # Although Spree 2 supports multi shipments per order, in OFN we keep the rule one shipment per order + # Thus, this method returns the shipping method of the first and only shipment in the order + def shipping_method + return if shipments.empty? + shipments.first.shipping_method + end + private def address_from_distributor