From cbec4956206c71c8499ecb2795a76306433206d1 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Wed, 11 Dec 2019 12:16:47 +0000 Subject: [PATCH] Fix some rubocop issues in order_and_distributor_report --- .rubocop_manual_todo.yml | 1 - .../order_and_distributor_report.rb | 27 ++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.rubocop_manual_todo.yml b/.rubocop_manual_todo.yml index 61e2fda2a4..634091cc73 100644 --- a/.rubocop_manual_todo.yml +++ b/.rubocop_manual_todo.yml @@ -114,7 +114,6 @@ Metrics/LineLength: - lib/open_food_network/enterprise_issue_validator.rb - lib/open_food_network/group_buy_report.rb - lib/open_food_network/lettuce_share_report.rb - - lib/open_food_network/order_and_distributor_report.rb - lib/open_food_network/order_cycle_form_applicator.rb - lib/open_food_network/order_cycle_management_report.rb - lib/open_food_network/payments_report.rb diff --git a/lib/open_food_network/order_and_distributor_report.rb b/lib/open_food_network/order_and_distributor_report.rb index 52205f5fcd..b32ab803cc 100644 --- a/lib/open_food_network/order_and_distributor_report.rb +++ b/lib/open_food_network/order_and_distributor_report.rb @@ -42,15 +42,17 @@ module OpenFoodNetwork orders = search.result - # If empty array is passed in, the where clause will return all line_items, which is bad - orders_with_hidden_details = - @permissions.editable_orders.empty? ? orders : orders.where('spree_orders.id NOT IN (?)', @permissions.editable_orders) - - orders.select{ |order| orders_with_hidden_details.include? order }.each do |order| + orders.select{ |order| orders_with_hidden_details(orders).include? order }.each do |order| # TODO We should really be hiding customer code here too, but until we # have an actual association between order and customer, it's a bit tricky - order.bill_address.andand.assign_attributes(firstname: I18n.t('admin.reports.hidden'), lastname: "", phone: "", address1: "", address2: "", city: "", zipcode: "", state: nil) - order.ship_address.andand.assign_attributes(firstname: I18n.t('admin.reports.hidden'), lastname: "", phone: "", address1: "", address2: "", city: "", zipcode: "", state: nil) + order.bill_address.andand. + assign_attributes(firstname: I18n.t('admin.reports.hidden'), + lastname: "", phone: "", address1: "", address2: "", + city: "", zipcode: "", state: nil) + order.ship_address.andand. + assign_attributes(firstname: I18n.t('admin.reports.hidden'), + lastname: "", phone: "", address1: "", address2: "", + city: "", zipcode: "", state: nil) order.assign_attributes(email: I18n.t('admin.reports.hidden')) end @@ -59,6 +61,17 @@ module OpenFoodNetwork private + def orders_with_hidden_details(orders) + # If empty array is passed in, the where clause will return all line_items, which is bad + if @permissions.editable_orders.empty? + orders + else + orders. + where('spree_orders.id NOT IN (?)', + @permissions.editable_orders) + end + end + def line_item_details(orders) order_and_distributor_details = []