From 1eba17f048e06a2806df4b58c37d31af557e8d21 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 18 Feb 2020 15:13:44 +0000 Subject: [PATCH 01/23] Make select column explicit to avoid too many columns sql error --- app/models/enterprise.rb | 4 ++-- app/models/enterprise_fee.rb | 2 +- app/models/enterprise_relationship.rb | 2 +- app/models/exchange.rb | 2 +- app/models/spree/order_decorator.rb | 6 ++++-- app/models/spree/payment_method_decorator.rb | 2 +- app/models/spree/shipping_method_decorator.rb | 2 +- app/models/spree/variant_decorator.rb | 2 +- lib/open_food_network/order_and_distributor_report.rb | 2 +- 9 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 1deee05a40..8211a17157 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -321,7 +321,7 @@ class Enterprise < ActiveRecord::Base def distributed_taxons Spree::Taxon. joins(:products). - where('spree_products.id IN (?)', Spree::Product.in_distributor(self)). + where('spree_products.id IN (?)', Spree::Product.in_distributor(self).select(&:id)). select('DISTINCT spree_taxons.*') end @@ -337,7 +337,7 @@ class Enterprise < ActiveRecord::Base def supplied_taxons Spree::Taxon. joins(:products). - where('spree_products.id IN (?)', Spree::Product.in_supplier(self)). + where('spree_products.id IN (?)', Spree::Product.in_supplier(self).select(&:id)). select('DISTINCT spree_taxons.*') end diff --git a/app/models/enterprise_fee.rb b/app/models/enterprise_fee.rb index 64c362b0fe..f26fee44eb 100644 --- a/app/models/enterprise_fee.rb +++ b/app/models/enterprise_fee.rb @@ -27,7 +27,7 @@ class EnterpriseFee < ActiveRecord::Base if user.has_spree_role?('admin') scoped else - where('enterprise_id IN (?)', user.enterprises) + where('enterprise_id IN (?)', user.enterprises.select(&:id)) end } diff --git a/app/models/enterprise_relationship.rb b/app/models/enterprise_relationship.rb index 6acd672f2f..e0b9c62c03 100644 --- a/app/models/enterprise_relationship.rb +++ b/app/models/enterprise_relationship.rb @@ -22,7 +22,7 @@ class EnterpriseRelationship < ActiveRecord::Base } scope :involving_enterprises, ->(enterprises) { - where('parent_id IN (?) OR child_id IN (?)', enterprises, enterprises) + where('parent_id IN (?) OR child_id IN (?)', enterprises.select(&:id), enterprises.select(&:id)) } scope :permitting, ->(enterprise_ids) { where('child_id IN (?)', enterprise_ids) } diff --git a/app/models/exchange.rb b/app/models/exchange.rb index ce28a7255d..4531ec042b 100644 --- a/app/models/exchange.rb +++ b/app/models/exchange.rb @@ -49,7 +49,7 @@ class Exchange < ActiveRecord::Base } scope :with_product, lambda { |product| joins(:exchange_variants). - where('exchange_variants.variant_id IN (?)', product.variants_including_master) + where('exchange_variants.variant_id IN (?)', product.variants_including_master.select(&:id)) } scope :by_enterprise_name, -> { joins('INNER JOIN enterprises AS sender ON (sender.id = exchanges.sender_id)'). diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 28d487d6fd..f0085d25e6 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -56,7 +56,9 @@ Spree::Order.class_eval do # Find orders that are distributed by the user or have products supplied by the user # WARNING: This only filters orders, you'll need to filter line items separately using LineItem.managed_by with_line_items_variants_and_products_outer. - where('spree_orders.distributor_id IN (?) OR spree_products.supplier_id IN (?)', user.enterprises, user.enterprises). + where('spree_orders.distributor_id IN (?) OR spree_products.supplier_id IN (?)', + user.enterprises.select(&:id), + user.enterprises.select(&:id)). select('DISTINCT spree_orders.*') end } @@ -65,7 +67,7 @@ Spree::Order.class_eval do if user.has_spree_role?('admin') scoped else - where('spree_orders.distributor_id IN (?)', user.enterprises) + where('spree_orders.distributor_id IN (?)', user.enterprises.select(&:id)) end } diff --git a/app/models/spree/payment_method_decorator.rb b/app/models/spree/payment_method_decorator.rb index f32944fdcb..6b917fcb4e 100644 --- a/app/models/spree/payment_method_decorator.rb +++ b/app/models/spree/payment_method_decorator.rb @@ -20,7 +20,7 @@ Spree::PaymentMethod.class_eval do scoped else joins(:distributors). - where('distributors_payment_methods.distributor_id IN (?)', user.enterprises). + where('distributors_payment_methods.distributor_id IN (?)', user.enterprises.select(&:id)). select('DISTINCT spree_payment_methods.*') end } diff --git a/app/models/spree/shipping_method_decorator.rb b/app/models/spree/shipping_method_decorator.rb index 813c947f38..ba7836899d 100644 --- a/app/models/spree/shipping_method_decorator.rb +++ b/app/models/spree/shipping_method_decorator.rb @@ -15,7 +15,7 @@ Spree::ShippingMethod.class_eval do scoped else joins(:distributors). - where('distributors_shipping_methods.distributor_id IN (?)', user.enterprises). + where('distributors_shipping_methods.distributor_id IN (?)', user.enterprises.select(&:id)). select('DISTINCT spree_shipping_methods.*') end } diff --git a/app/models/spree/variant_decorator.rb b/app/models/spree/variant_decorator.rb index 84750cbe94..566394d946 100644 --- a/app/models/spree/variant_decorator.rb +++ b/app/models/spree/variant_decorator.rb @@ -49,7 +49,7 @@ Spree::Variant.class_eval do } scope :for_distribution, lambda { |order_cycle, distributor| - where('spree_variants.id IN (?)', order_cycle.variants_distributed_by(distributor)) + where('spree_variants.id IN (?)', order_cycle.variants_distributed_by(distributor).select(&:id)) } scope :visible_for, lambda { |enterprise| diff --git a/lib/open_food_network/order_and_distributor_report.rb b/lib/open_food_network/order_and_distributor_report.rb index b32ab803cc..64f46f41d1 100644 --- a/lib/open_food_network/order_and_distributor_report.rb +++ b/lib/open_food_network/order_and_distributor_report.rb @@ -68,7 +68,7 @@ module OpenFoodNetwork else orders. where('spree_orders.id NOT IN (?)', - @permissions.editable_orders) + @permissions.editable_orders.select(&:id)) end end From 03fac6f2859999ac54454d5eb5e4d257e9e0c8f0 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sun, 23 Feb 2020 20:02:20 +0000 Subject: [PATCH 02/23] Avoid subquery with too many columns error by specifying the selected column --- app/jobs/subscription_placement_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/subscription_placement_job.rb b/app/jobs/subscription_placement_job.rb index 26c67997ba..2ef5cc9716 100644 --- a/app/jobs/subscription_placement_job.rb +++ b/app/jobs/subscription_placement_job.rb @@ -63,7 +63,7 @@ class SubscriptionPlacementJob end def unavailable_stock_lines_for(order) - order.line_items.where('variant_id NOT IN (?)', available_variants_for(order)) + order.line_items.where('variant_id NOT IN (?)', available_variants_for(order).select(&:id)) end def available_variants_for(order) From b528903aa80efad95684b1cae9e69c2a78d3147e Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 27 Feb 2020 19:05:36 +0000 Subject: [PATCH 03/23] Remove spec covering html format in SchedulesController#index, this is not used anywhere --- spec/controllers/admin/schedules_controller_spec.rb | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/spec/controllers/admin/schedules_controller_spec.rb b/spec/controllers/admin/schedules_controller_spec.rb index db974df917..19f2e4b032 100644 --- a/spec/controllers/admin/schedules_controller_spec.rb +++ b/spec/controllers/admin/schedules_controller_spec.rb @@ -10,19 +10,6 @@ describe Admin::SchedulesController, type: :controller do let!(:coordinated_schedule) { create(:schedule, order_cycles: [coordinated_order_cycle] ) } let!(:uncoordinated_schedule) { create(:schedule, order_cycles: [other_order_cycle] ) } - context "html" do - context "where I manage an order cycle coordinator" do - before do - allow(controller).to receive_messages spree_current_user: managed_coordinator.owner - end - - it "returns an empty @collection" do - spree_get :index, format: :html - expect(assigns(:collection)).to eq [] - end - end - end - context "json" do context "where I manage an order cycle coordinator" do before do From af8369ae1b91406a8fcf4210d983d86f1b69c13c Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 3 Mar 2020 10:56:57 +0000 Subject: [PATCH 04/23] Remove 5 years old debug code This reverts ab9bc7b1dcd0c3f0027ecb788ed43f91984cb744, it can be added if the issue happens again --- app/controllers/admin/enterprises_controller.rb | 10 +--------- app/views/admin/enterprises/_admin_index.html.haml | 4 ---- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 970c09a7ee..8369c5283f 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -23,7 +23,6 @@ module Admin before_filter :setup_property, only: [:edit] helper 'spree/products' - include ActionView::Helpers::TextHelper include OrderCyclesHelper def index @@ -77,19 +76,12 @@ module Admin def bulk_update @enterprise_set = EnterpriseSet.new(collection, params[:enterprise_set]) - touched_enterprises = @enterprise_set.collection.select(&:changed?) if @enterprise_set.save flash[:success] = I18n.t(:enterprise_bulk_update_success_notice) - # 18-3-2015: It seems that the form for this action sometimes loads bogus values for - # the 'sells' field, and submitting that form results in a bunch of enterprises with - # values that have mysteriously changed. This statement is here to help debug that - # issue, and should be removed (along with its display in index.html.haml) when the - # issue has been resolved. - flash[:action] = "#{I18n.t(:updated)} #{pluralize(touched_enterprises.count, 'enterprise')}: #{touched_enterprises.map(&:name).join(', ')}" - redirect_to main_app.admin_enterprises_path else + touched_enterprises = @enterprise_set.collection.select(&:changed?) @enterprise_set.collection.select! { |e| touched_enterprises.include? e } flash[:error] = I18n.t(:enterprise_bulk_update_error) render :index diff --git a/app/views/admin/enterprises/_admin_index.html.haml b/app/views/admin/enterprises/_admin_index.html.haml index 3376601aaa..cb38f57722 100644 --- a/app/views/admin/enterprises/_admin_index.html.haml +++ b/app/views/admin/enterprises/_admin_index.html.haml @@ -1,7 +1,3 @@ --# For purposes of debugging bulk_update. See Admin/Enterprises#bulk_update. -- if flash[:action] - %p= flash[:action] - = form_for @enterprise_set, url: main_app.bulk_update_admin_enterprises_path do |f| %table#listing_enterprises.index %colgroup From 7fdaa0f0c71169611775f82eac0359449cc30138 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 3 Mar 2020 14:46:12 +0000 Subject: [PATCH 05/23] Make package spec work in rails 4 by persisting the test enterprises so that the copnnection between shipping methods and enterprises works --- spec/models/stock/package_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/stock/package_spec.rb b/spec/models/stock/package_spec.rb index 726eed6c37..6a3ac355cc 100644 --- a/spec/models/stock/package_spec.rb +++ b/spec/models/stock/package_spec.rb @@ -6,8 +6,8 @@ module Stock subject(:package) { Package.new(stock_location, order, contents) } - let(:enterprise) { build(:enterprise) } - let(:other_enterprise) { build(:enterprise) } + let(:enterprise) { create(:enterprise) } + let(:other_enterprise) { create(:enterprise) } let(:order) { build(:order, distributor: enterprise) } From f13d7d6845acdcc27507eeba1bb147702d01b507 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 5 Mar 2020 15:20:45 +0000 Subject: [PATCH 06/23] Fix products api spec in rails 4 --- spec/controllers/api/products_controller_spec.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/spec/controllers/api/products_controller_spec.rb b/spec/controllers/api/products_controller_spec.rb index 5da8d89e32..6bf2cba312 100644 --- a/spec/controllers/api/products_controller_spec.rb +++ b/spec/controllers/api/products_controller_spec.rb @@ -253,13 +253,9 @@ describe Api::ProductsController, type: :controller do end it "filters results by import_date" do - product.variants.first.import_date = 1.day.ago - product2.variants.first.import_date = 2.days.ago - product3.variants.first.import_date = 1.day.ago - - product.save - product2.save - product3.save + product.variants.first.update_attribute :import_date, 1.day.ago + product2.variants.first.update_attribute :import_date, 2.days.ago + product3.variants.first.update_attribute :import_date, 1.day.ago api_get :bulk_products, { page: 1, per_page: 15, import_date: 1.day.ago.to_date.to_s }, format: :json expect(returned_product_ids).to eq [product3.id, product.id] From 461b1b26f3434c539af537de99944ccd141b1e34 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Tue, 18 Feb 2020 19:00:25 +0100 Subject: [PATCH 07/23] Add controller tests to cover totals by supplier --- .../spree/admin/reports_controller.rb | 6 +- .../distributor_totals_by_supplier_spec.rb | 249 ++++++++++++++++++ 2 files changed, 254 insertions(+), 1 deletion(-) create mode 100644 spec/controllers/spree/admin/reports/distributor_totals_by_supplier_spec.rb diff --git a/app/controllers/spree/admin/reports_controller.rb b/app/controllers/spree/admin/reports_controller.rb index ec08bca29c..cdc97fbf39 100644 --- a/app/controllers/spree/admin/reports_controller.rb +++ b/app/controllers/spree/admin/reports_controller.rb @@ -217,7 +217,11 @@ module Spree end def render_report(header, table, create_csv, csv_file_name) - send_data csv_report(header, table), filename: csv_file_name if create_csv + if create_csv + @csv_report = csv_report(header, table) + send_data @csv_report, filename: csv_file_name + end + @header = header @table = table # Rendering HTML is the default. diff --git a/spec/controllers/spree/admin/reports/distributor_totals_by_supplier_spec.rb b/spec/controllers/spree/admin/reports/distributor_totals_by_supplier_spec.rb new file mode 100644 index 0000000000..357c0a8670 --- /dev/null +++ b/spec/controllers/spree/admin/reports/distributor_totals_by_supplier_spec.rb @@ -0,0 +1,249 @@ +require 'spec_helper' + +describe Spree::Admin::ReportsController, type: :controller do + let(:csv) do + <<-CSV.strip_heredoc + Hub,Producer,Product,Variant,Amount,Curr. Cost per Unit,Total Cost,Total Shipping Cost,Shipping Method + Mary's Online Shop,Freddy's Farm Shop,Beef - 5kg Trays,1g,1,12.0,12.0,"",Shipping Method + Mary's Online Shop,Freddy's Farm Shop,Fuji Apple,2g,1,4.0,4.0,"",Shipping Method + Mary's Online Shop,Freddy's Farm Shop,Fuji Apple,5g,5,12.0,60.0,"",Shipping Method + Mary's Online Shop,Freddy's Farm Shop,Fuji Apple,8g,3,15.0,45.0,"",Shipping Method + "",TOTAL,"","","","",121.0,2.0,"" + CSV + end + + before do + DefaultStockLocation.create! + + delivery = marys_online_shop.shipping_methods.new( + name: "Home delivery", + require_ship_address: true, + calculator_type: "Spree::Calculator::FlatRate", + distributor_ids: [marys_online_shop.id] + ) + delivery.shipping_categories << DefaultShippingCategory.find_or_create + delivery.calculator.preferred_amount = 2 + delivery.save! + end + + let(:taxonomy) { Spree::Taxonomy.create!(name: 'Products') } + let(:meat) do + Spree::Taxon.create!(name: 'Meat and Fish', parent_id: taxonomy.root.id, taxonomy_id: taxonomy.id) + end + let(:fruit) do + Spree::Taxon.create!(name: 'Fruit', parent_id: taxonomy.root.id, taxonomy_id: taxonomy.id) + end + + let(:calculator) { Calculator::FlatPercentPerItem.new(preferred_flat_percent: 10) } + + let(:mary) do + password = Spree::User.friendly_token + Spree::User.create!( + email: 'mary_retailer@example.org', + password: password, + password_confirmation: password, + confirmation_sent_at: Time.zone.now, + confirmed_at: Time.zone.now + ) + end + let(:marys_online_shop) do + Enterprise.create!( + name: "Mary's Online Shop", + owner: mary, + is_primary_producer: false, + sells: "any", + address: create(:address) + ) + end + before do + fee = marys_online_shop.enterprise_fees.new( + fee_type: "sales", name: "markup", inherits_tax_category: true + ) + fee.calculator = calculator + fee.save! + end + + let(:freddy) do + password = Spree::User.friendly_token + Spree::User.create!( + email: 'freddy_shop_farmer@example.org', + password: password, + password_confirmation: password, + confirmation_sent_at: Time.zone.now, + confirmed_at: Time.zone.now + ) + end + let(:freddys_farm_shop) do + Enterprise.create!( + name: "Freddy's Farm Shop", + owner: freddy, + is_primary_producer: true, + sells: "own", + address: create(:address) + ) + end + before do + fee = freddys_farm_shop.enterprise_fees.new( + fee_type: "sales", name: "markup", inherits_tax_category: true, + ) + fee.calculator = calculator + fee.save! + end + + let!(:beef) do + product = Spree::Product.new( + name: 'Beef - 5kg Trays', + price: 50.00, + supplier_id: freddys_farm_shop.id, + primary_taxon_id: meat.id, + variant_unit: "weight", + variant_unit_scale: 1, + unit_value: 1, + ) + product.shipping_category = DefaultShippingCategory.find_or_create + product.save! + product.variants.first.update_attribute(:on_demand, true) + + InventoryItem.create!( + enterprise: marys_online_shop, + variant: product.variants.first, + visible: true + ) + VariantOverride.create!( + variant: product.variants.first, + hub: marys_online_shop, + price: 12, + on_demand: false, + count_on_hand: 5 + ) + + product + end + + let!(:apple) do + product = Spree::Product.new( + name: 'Fuji Apple', + price: 5.00, + supplier_id: freddys_farm_shop.id, + primary_taxon_id: fruit.id, + variant_unit: "weight", + variant_unit_scale: 1, + unit_value: 1, + shipping_category: DefaultShippingCategory.find_or_create + ) + product.shipping_category = DefaultShippingCategory.find_or_create + product.save! + product.variants.first.update_attribute :on_demand, true + + VariantOverride.create!( + variant: product.variants.first, + hub: marys_online_shop, + price: 12, + on_demand: false, + count_on_hand: 5 + ) + + product + end + let!(:apple_variant_2) do + variant = apple.variants.create!(weight: 0.0, unit_value: 2.0, price: 4.0) + VariantOverride.create!( + variant: variant, hub: marys_online_shop, on_demand: false, count_on_hand: 4 + ) + variant + end + let!(:apple_variant_5) do + variant = apple.variants.create!(weight: 0.0, unit_value: 5.0, price: 12.0) + VariantOverride.create!( + variant: variant, hub: marys_online_shop, on_demand: false, count_on_hand: 5 + ) + variant.update_attribute :on_demand, true + variant + end + let!(:apple_variant_8) do + variant = apple.variants.create!(weight: 0.0, unit_value: 8.0, price: 15.0) + VariantOverride.create!( + variant: variant, hub: marys_online_shop, on_demand: false, count_on_hand: 3 + ) + variant.update_attribute :on_demand, true + variant + end + + let!(:beef_variant) do + variant = beef.variants.first + OpenFoodNetwork::ScopeVariantToHub.new(marys_online_shop).scope(variant) + variant + end + + let!(:order_cycle) do + cycle = OrderCycle.create!( + name: "Mary's Online Shop OC", + orders_open_at: 1.day.ago, + orders_close_at: 1.month.from_now, + coordinator: marys_online_shop + ) + cycle.coordinator_fees << marys_online_shop.enterprise_fees.first + + incoming = Exchange.create!( + order_cycle: cycle, sender: freddys_farm_shop, receiver: cycle.coordinator, incoming: true + ) + outgoing = Exchange.create!( + order_cycle: cycle, sender: cycle.coordinator, receiver: marys_online_shop, incoming: false + ) + + freddys_farm_shop.supplied_products.each do |product| + incoming.variants << product.variants.first + outgoing.variants << product.variants.first + end + + cycle + end + + let(:order) do + create( + :order, + distributor: marys_online_shop, + order_cycle: order_cycle, + ship_address: create(:address) + ) + end + + before do + order.add_variant(beef_variant, 1, nil, order.currency) + order.add_variant(apple_variant_2, 1, nil, order.currency) + order.add_variant(apple_variant_5, 5, nil, order.currency) + order.add_variant(apple_variant_8, 3, nil, order.currency) + + order.create_proposed_shipments + order.finalize! + + order.completed_at = Time.zone.parse("2020-02-05 00:00:00 +1100") + order.save + + allow(controller).to receive(:spree_current_user).and_return(mary) + end + + it 'returns the right CSV' do + spree_post :orders_and_fulfillment, { + q: { + completed_at_gt: "2020-01-11 00:00:00 +1100", + completed_at_lt: "2020-02-12 00:00:00 +1100", + distributor_id_in: [marys_online_shop.id], + order_cycle_id_in: [""] + }, + report_type: "order_cycle_distributor_totals_by_supplier", + csv: true + } + + csv_report = assigns(:csv_report) + report_lines = csv_report.split("\n") + csv_fixture_lines = csv.split("\n") + + expect(report_lines[0]).to eq(csv_fixture_lines[0]) + expect(report_lines[1]).to eq(csv_fixture_lines[1]) + expect(report_lines[2]).to eq(csv_fixture_lines[2]) + expect(report_lines[3]).to eq(csv_fixture_lines[3]) + expect(report_lines[4]).to eq(csv_fixture_lines[4]) + expect(report_lines[5]).to eq(csv_fixture_lines[5]) + end +end From 53a63775fe2b79cb60a477afa8f03413e1171040 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Fri, 14 Feb 2020 18:38:26 +0100 Subject: [PATCH 08/23] Replace LEFT JOIN with INNER JOIN I see no reason why a LEFT might be needed and its the root cause of the awful performance. --- app/models/spree/order_decorator.rb | 6 ++++++ app/services/permissions/order.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 28d487d6fd..688f1b3b16 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -75,6 +75,12 @@ Spree::Order.class_eval do joins('LEFT OUTER JOIN spree_products ON (spree_products.id = spree_variants.product_id)') } + scope :with_line_items_variants_and_products, lambda { + joins('INNER JOIN spree_line_items ON (spree_line_items.order_id = spree_orders.id)'). + joins('INNER JOIN spree_variants ON (spree_variants.id = spree_line_items.variant_id)'). + joins('INNER JOIN spree_products ON (spree_products.id = spree_variants.product_id)') + } + scope :not_state, lambda { |state| where("state != ?", state) } diff --git a/app/services/permissions/order.rb b/app/services/permissions/order.rb index 5e95ba92c8..cf44b1e0ae 100644 --- a/app/services/permissions/order.rb +++ b/app/services/permissions/order.rb @@ -10,7 +10,7 @@ module Permissions # Find orders that the user can see def visible_orders Spree::Order. - with_line_items_variants_and_products_outer. + with_line_items_variants_and_products. where(visible_orders_where_values) end From 0042ab2f28ef2a7e992313f73910c142f0ea2106 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Mon, 2 Mar 2020 16:40:27 +0100 Subject: [PATCH 09/23] Rewrite INNER JOIN in ActiveRecord's DSL --- app/models/spree/order_decorator.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 688f1b3b16..34398bbe7d 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -76,9 +76,7 @@ Spree::Order.class_eval do } scope :with_line_items_variants_and_products, lambda { - joins('INNER JOIN spree_line_items ON (spree_line_items.order_id = spree_orders.id)'). - joins('INNER JOIN spree_variants ON (spree_variants.id = spree_line_items.variant_id)'). - joins('INNER JOIN spree_products ON (spree_products.id = spree_variants.product_id)') + joins(line_items: { variant: :product }) } scope :not_state, lambda { |state| From 7c3a0a292f88b0496a29100e20e5c5d4b5581181 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 6 Mar 2020 19:31:47 +0000 Subject: [PATCH 10/23] Bump ddtrace from 0.32.0 to 0.33.0 Bumps [ddtrace](https://github.com/DataDog/dd-trace-rb) from 0.32.0 to 0.33.0. - [Release notes](https://github.com/DataDog/dd-trace-rb/releases) - [Changelog](https://github.com/DataDog/dd-trace-rb/blob/master/CHANGELOG.md) - [Commits](https://github.com/DataDog/dd-trace-rb/compare/v0.32.0...v0.33.0) Signed-off-by: dependabot-preview[bot] --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 2bf97f7891..70933c50f5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -211,7 +211,7 @@ GEM activerecord (>= 3.2.0, < 5.0) fog (~> 1.0) rails (>= 3.2.0, < 5.0) - ddtrace (0.32.0) + ddtrace (0.33.0) msgpack debugger-linecache (1.2.0) deface (1.0.2) @@ -467,7 +467,7 @@ GEM railties (>= 3.1) money (5.1.1) i18n (~> 0.6.0) - msgpack (1.3.1) + msgpack (1.3.3) multi_json (1.14.1) multi_xml (0.6.0) multipart-post (2.1.1) From 1e76f3f744190f30af29f705cba5fddd03ba548a Mon Sep 17 00:00:00 2001 From: Transifex-Openfoodnetwork Date: Sun, 8 Mar 2020 01:20:57 +1100 Subject: [PATCH 11/23] Updating translations for config/locales/fr.yml --- config/locales/fr.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/locales/fr.yml b/config/locales/fr.yml index a261ee007d..6385ec2c37 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -2221,7 +2221,7 @@ fr: no_change_to_save: "Pas de changement à sauvegarder" user_invited: "%{email}a été invité à gérer cette entreprise" add_manager: "Ajouter un utilisateur existant" - users: "Utilisateurs" + users: "Gestionnaires" about: "A propos" images: "Images" web: "Web" @@ -2278,6 +2278,7 @@ fr: enterprise_register_success_notice: "Bravo ! L'entreprise %{enterprise} est maintenant inscrite sur Open Food France :-)" enterprise_bulk_update_success_notice: "Entreprises mises à jour avec succès" enterprise_bulk_update_error: 'Echec dans la mise à jour' + enterprise_shop_show_error: "La boutique que vous recherchez n'existe pas ou est inactive. Veuillez sélectionner une boutique depuis la liste ci-dessous." order_cycles_create_notice: 'Votre cycle de vente a été créé.' order_cycles_update_notice: 'Votre cycle de vente a été mis à jour.' order_cycles_bulk_update_notice: 'Des cycles de vente ont été mis à jour.' From 0d02b2afcfc780fc62ed6efed5c1f20984f475be Mon Sep 17 00:00:00 2001 From: Transifex-Openfoodnetwork Date: Sun, 8 Mar 2020 01:21:12 +1100 Subject: [PATCH 12/23] Updating translations for config/locales/en_FR.yml --- config/locales/en_FR.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/locales/en_FR.yml b/config/locales/en_FR.yml index a19db5ae4a..b37822f390 100644 --- a/config/locales/en_FR.yml +++ b/config/locales/en_FR.yml @@ -2274,6 +2274,7 @@ en_FR: enterprise_register_success_notice: "Congratulations! Registration for %{enterprise} is complete!" enterprise_bulk_update_success_notice: "Enterprises updated successfully" enterprise_bulk_update_error: 'Update failed' + enterprise_shop_show_error: "The shop you are looking for doesn't exist or is inactive on OFN. Please check other shops." order_cycles_create_notice: 'Your order cycle has been created.' order_cycles_update_notice: 'Your order cycle has been updated.' order_cycles_bulk_update_notice: 'Order cycles have been updated.' From 7585e3d1d6e7e1648b05abfc54e6b8367563e2ee Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 10 Mar 2020 18:40:46 +0000 Subject: [PATCH 14/23] The variants_to_a method was dead but actually we can use it to make the code simpler --- lib/open_food_network/order_cycle_form_applicator.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/open_food_network/order_cycle_form_applicator.rb b/lib/open_food_network/order_cycle_form_applicator.rb index 611f120f62..8f9c4308d8 100644 --- a/lib/open_food_network/order_cycle_form_applicator.rb +++ b/lib/open_food_network/order_cycle_form_applicator.rb @@ -149,7 +149,7 @@ module OpenFoodNetwork receiver = @order_cycle.coordinator exchange = find_exchange(sender.id, receiver.id, true) - requested_ids = attrs[:variants].select{ |_k, v| v }.keys.map(&:to_i) # Only the ids the user has requested + requested_ids = variants_to_a(attrs[:variants]) # Only the ids the user has requested existing_ids = exchange.present? ? exchange.variants.pluck(:id) : [] # The ids that already exist editable_ids = editable_variant_ids_for_incoming_exchange_between(sender, receiver) # The ids we are allowed to add/remove @@ -166,7 +166,7 @@ module OpenFoodNetwork receiver = Enterprise.find(attrs[:enterprise_id]) exchange = find_exchange(sender.id, receiver.id, false) - requested_ids = attrs[:variants].select{ |_k, v| v }.keys.map(&:to_i) # Only the ids the user has requested + requested_ids = variants_to_a(attrs[:variants]) # Only the ids the user has requested existing_ids = exchange.present? ? exchange.variants.pluck(:id) : [] # The ids that already exist editable_ids = editable_variant_ids_for_outgoing_exchange_between(sender, receiver) # The ids we are allowed to add/remove @@ -184,7 +184,7 @@ module OpenFoodNetwork end def variants_to_a(variants) - variants.select { |_k, v| v }.keys.map(&:to_i).sort + variants.select { |_k, v| v }.keys.map(&:to_i) end end end From 03246d425d02b4fa843aac24ca91c1feab70c6a3 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 10 Mar 2020 18:41:26 +0000 Subject: [PATCH 15/23] Make this method handle the case where the variants hash passed is nil This fixes a spec in the rails 4 branch --- lib/open_food_network/order_cycle_form_applicator.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/open_food_network/order_cycle_form_applicator.rb b/lib/open_food_network/order_cycle_form_applicator.rb index 8f9c4308d8..1abf16f89c 100644 --- a/lib/open_food_network/order_cycle_form_applicator.rb +++ b/lib/open_food_network/order_cycle_form_applicator.rb @@ -184,6 +184,8 @@ module OpenFoodNetwork end def variants_to_a(variants) + return [] unless variants + variants.select { |_k, v| v }.keys.map(&:to_i) end end From c83bded763d1a846599de89d092d5827856ddad1 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 10 Mar 2020 19:19:31 +0000 Subject: [PATCH 16/23] Bump ddtrace from 0.33.0 to 0.33.1 Bumps [ddtrace](https://github.com/DataDog/dd-trace-rb) from 0.33.0 to 0.33.1. - [Release notes](https://github.com/DataDog/dd-trace-rb/releases) - [Changelog](https://github.com/DataDog/dd-trace-rb/blob/master/CHANGELOG.md) - [Commits](https://github.com/DataDog/dd-trace-rb/compare/v0.33.0...v0.33.1) Signed-off-by: dependabot-preview[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 70933c50f5..fb8f877dd9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -211,7 +211,7 @@ GEM activerecord (>= 3.2.0, < 5.0) fog (~> 1.0) rails (>= 3.2.0, < 5.0) - ddtrace (0.33.0) + ddtrace (0.33.1) msgpack debugger-linecache (1.2.0) deface (1.0.2) From 4c7b8209b9a9b7784051e6a3f845fb29f5255203 Mon Sep 17 00:00:00 2001 From: Transifex-Openfoodnetwork Date: Wed, 11 Mar 2020 19:49:14 +1100 Subject: [PATCH 17/23] Updating translations for config/locales/nb.yml --- config/locales/nb.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/locales/nb.yml b/config/locales/nb.yml index 7ce4f8d1ff..1207b53957 100644 --- a/config/locales/nb.yml +++ b/config/locales/nb.yml @@ -2274,6 +2274,7 @@ nb: enterprise_register_success_notice: "Gratulerer! Registrering for %{enterprise} er fullført!" enterprise_bulk_update_success_notice: "Bedrifter oppdatert" enterprise_bulk_update_error: 'Oppdatering mislyktes' + enterprise_shop_show_error: "Butikken du leter etter eksisterer ikke eller er inaktiv på OFN. Sjekk gjerne ut andre butikker." order_cycles_create_notice: 'Din bestillingsrunde er opprettet.' order_cycles_update_notice: 'Din bestillingsrunde har blitt oppdatert.' order_cycles_bulk_update_notice: 'Bestillingsrundene er oppdatert.' From 933b5f16069923f5d2a24a36d5dc63e8acb4229d Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 11 Mar 2020 15:31:25 +0100 Subject: [PATCH 18/23] Fix reloading issue in dev environment I constantly get `NameError: uninitialized constant Spree::AuthenticationHelpers` when touching local files and then reloading a page, and have to restart my rails server every time (in development). I read the other day that this is the best way to fix the issue, and it seems to work... --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5b67897fab..1a841eae27 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,5 @@ require 'open_food_network/referer_parser' -require 'spree/authentication_helpers' +require_dependency 'spree/authentication_helpers' class ApplicationController < ActionController::Base protect_from_forgery From 633f1bd7cf20a380ae0483e55605c04b0b6bfa80 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 11 Mar 2020 19:15:51 +0000 Subject: [PATCH 19/23] Bump rspec-rails from 3.9.0 to 3.9.1 Bumps [rspec-rails](https://github.com/rspec/rspec-rails) from 3.9.0 to 3.9.1. - [Release notes](https://github.com/rspec/rspec-rails/releases) - [Changelog](https://github.com/rspec/rspec-rails/blob/master/Changelog.md) - [Commits](https://github.com/rspec/rspec-rails/compare/v3.9.0...v3.9.1) Signed-off-by: dependabot-preview[bot] --- Gemfile.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 70933c50f5..a76e77889b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -516,7 +516,7 @@ GEM rabl (0.8.4) activesupport (>= 2.3.14) rack (1.4.7) - rack-cache (1.9.0) + rack-cache (1.11.0) rack (>= 0.4) rack-mini-profiler (1.1.6) rack (>= 1.2.0) @@ -548,7 +548,7 @@ GEM thor (>= 0.14.6, < 2.0) rainbow (3.0.0) raindrops (0.19.1) - rake (13.0.0) + rake (13.0.1) ransack (0.7.2) actionpack (~> 3.0) activerecord (~> 3.0) @@ -580,15 +580,15 @@ GEM rspec-core (~> 3.9.0) rspec-expectations (~> 3.9.0) rspec-mocks (~> 3.9.0) - rspec-core (3.9.0) - rspec-support (~> 3.9.0) + rspec-core (3.9.1) + rspec-support (~> 3.9.1) rspec-expectations (3.9.0) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) - rspec-mocks (3.9.0) + rspec-mocks (3.9.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) - rspec-rails (3.9.0) + rspec-rails (3.9.1) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) @@ -598,7 +598,7 @@ GEM rspec-support (~> 3.9.0) rspec-retry (0.6.2) rspec-core (> 3.3) - rspec-support (3.9.0) + rspec-support (3.9.2) rubocop (0.80.1) jaro_winkler (~> 1.5.1) parallel (~> 1.10) From 8eb60388fd38f1a940f259b626347c2a14008e62 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 11 Mar 2020 19:19:24 +0000 Subject: [PATCH 20/23] Bump rack-mini-profiler from 1.1.6 to 2.0.0 Bumps [rack-mini-profiler](https://github.com/MiniProfiler/rack-mini-profiler) from 1.1.6 to 2.0.0. - [Release notes](https://github.com/MiniProfiler/rack-mini-profiler/releases) - [Changelog](https://github.com/MiniProfiler/rack-mini-profiler/blob/master/CHANGELOG.md) - [Commits](https://github.com/MiniProfiler/rack-mini-profiler/compare/v1.1.6...v2.0.0) Signed-off-by: dependabot-preview[bot] --- Gemfile | 2 +- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 2318f4d7ca..a07f9c26ce 100644 --- a/Gemfile +++ b/Gemfile @@ -166,5 +166,5 @@ group :development do # greater than 1.0.9, so we just required the latest available version here. gem 'eventmachine', '>= 1.2.3' - gem 'rack-mini-profiler', '< 2.0.0' + gem 'rack-mini-profiler', '< 3.0.0' end diff --git a/Gemfile.lock b/Gemfile.lock index 70933c50f5..6be680b1f4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -518,7 +518,7 @@ GEM rack (1.4.7) rack-cache (1.9.0) rack (>= 0.4) - rack-mini-profiler (1.1.6) + rack-mini-profiler (2.0.0) rack (>= 1.2.0) rack-protection (1.5.5) rack @@ -762,7 +762,7 @@ DEPENDENCIES pg (~> 0.21.0) pry-byebug (>= 3.4.3) rabl - rack-mini-profiler (< 2.0.0) + rack-mini-profiler (< 3.0.0) rack-rewrite rack-ssl rails (~> 3.2.22) From d14b5eb46ba2980b9a4f6b4ec43ba5b48f43f61b Mon Sep 17 00:00:00 2001 From: Transifex-Openfoodnetwork Date: Thu, 12 Mar 2020 09:22:44 +1100 Subject: [PATCH 21/23] Updating translations for config/locales/pt_BR.yml --- config/locales/pt_BR.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/locales/pt_BR.yml b/config/locales/pt_BR.yml index f048a4d822..a48684cb62 100644 --- a/config/locales/pt_BR.yml +++ b/config/locales/pt_BR.yml @@ -2273,6 +2273,7 @@ pt_BR: enterprise_register_success_notice: "Parabéns! O registro para %{enterprise} está completo!" enterprise_bulk_update_success_notice: "Iniciativas atualizadas com sucesso" enterprise_bulk_update_error: 'Atualização falhou' + enterprise_shop_show_error: "A loja que você está procurando não existe na OFN ou está inativa. Por favor, busque por outras lojas. " order_cycles_create_notice: 'Seu ciclo de pedidos foi criado.' order_cycles_update_notice: 'Seu ciclo de pedidos foi atualizado.' order_cycles_bulk_update_notice: 'Ciclos de pedidos foram atualizados.' From 8ccc8dfaf6920547a012ce6c1b3f96bfedbe7b0b Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Thu, 12 Mar 2020 13:33:42 +0100 Subject: [PATCH 23/23] Update all locales with the latest Transifex translations --- config/locales/ca.yml | 75 +++++++++++++++++++++++++++++++++++++++++++ config/locales/fr.yml | 2 +- 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/config/locales/ca.yml b/config/locales/ca.yml index 25df51631d..7ea493176c 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -1285,6 +1285,7 @@ ca: saving_credit_card: Desant la targeta de crèdit... card_has_been_removed: "S'ha eliminat la teva targeta (número: %{number})" card_could_not_be_removed: Ho sentim, no s'ha pogut eliminar la targeta + invalid_credit_card: "Targeta de crèdit no vàlida" ie_warning_headline: "El vostre navegador no està actualitzat :-(" ie_warning_text: "Per obtenir la millor experiència a Open Food Network et recomanem que actualitzis el teu navegador:" ie_warning_chrome: Descarrega Chrome @@ -2276,6 +2277,7 @@ ca: enterprise_register_success_notice: "Enhorabona! El registre de %{enterprise} s'ha completat!" enterprise_bulk_update_success_notice: "Les organitzacions s'han actualitzat correctament" enterprise_bulk_update_error: 'No s''ha pogut actualitzar' + enterprise_shop_show_error: "La botiga que busqueu no existeix o està inactiva a OFN. Consulteu altres botigues." order_cycles_create_notice: 'S''ha creat el cicle de comanda.' order_cycles_update_notice: 'S''ha actualitzat el cicle de comanda.' order_cycles_bulk_update_notice: 'S''han actualitzat els cicles de comanda.' @@ -2430,6 +2432,12 @@ ca: severity: Severitat description: Descripció resolve: Resoldre + exchange_products: + load_more_variants: "Carregueu més variants" + load_all_variants: "Carregueu totes les variants" + select_all_variants: "Seleccioneu totes les %{total_number_of_variants} variants" + variants_loaded: "%{num_of_variants_loaded} de %{total_number_of_variants} variants carregades" + loading_variants: "Carregant variants" tag_rules: shipping_method_tagged_top: "Els mètodes d'enviament etiquetats" shipping_method_tagged_bottom: "son:" @@ -2588,6 +2596,73 @@ ca: signup_or_login: "Comenceu registrant-vos (o iniciant sessió)" have_an_account: "Ja tens un compte?" action_login: "Inicia la sessió ara." + inflections: + each: + one: "cadascun" + other: "cadascun" + bunch: + one: "munt" + other: "grapats" + pack: + one: "paquet" + other: "paquets" + box: + one: "Caixa" + other: "caixes" + bottle: + one: "ampolla" + other: "ampolles" + jar: + one: "gerro" + other: "pots" + head: + one: "cap" + other: "caps" + bag: + one: "bossa" + other: "bosses" + loaf: + one: "pa" + other: "barres" + single: + one: "solter" + other: "únics" + tub: + one: "tina" + other: "cubells" + item: + one: "article" + other: "articles" + dozen: + one: "dotzena" + other: "dotzenes" + unit: + one: "unitat" + other: "unitats" + serve: + one: "servir" + other: "porcions" + tray: + one: "safata" + other: "safates" + piece: + one: "peça" + other: "peces" + pot: + one: "pot" + other: "pots" + bundle: + one: "paquet" + other: "paquets" + flask: + one: "matràs" + other: "ampolleta" + basket: + one: "cistella" + other: "cistelles" + sack: + one: "sac" + other: "sacs" producers: signup: start_free_profile: "Comença amb un perfil gratuït i amplia'l quan estiguis preparada." diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 6385ec2c37..afb17379ed 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -701,7 +701,7 @@ fr: enable_subscriptions_tip: "Activer la fonction abonnements?" enable_subscriptions_false: "Désactivé" enable_subscriptions_true: "Activé" - shopfront_message: "Message d'accueil boutique ouverte" + shopfront_message: "Message d'accueil" shopfront_message_placeholder: > Vous pouvez indiquer ici un message de bienvenue ou un message expliquant les particularités de votre boutique. Ce message s'affiche dans l'onglet