Fix some rubocop issues in order_and_distributor_report

This commit is contained in:
luisramos0
2019-12-11 12:16:47 +00:00
parent 55eea21bb0
commit cbec495620
2 changed files with 20 additions and 8 deletions

View File

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

View File

@@ -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 = []