Skip to content

Commit

Permalink
Merge pull request #3646 from kristinalim/fix/3528-product_sku_in_report
Browse files Browse the repository at this point in the history
3528 Scope Customer Totals report also by variant (not just product) and use variant SKU
  • Loading branch information
mkllnk authored Mar 26, 2019
2 parents 6cd07cd + 807cdb4 commit 9e3734f
Show file tree
Hide file tree
Showing 7 changed files with 283 additions and 132 deletions.
1 change: 0 additions & 1 deletion .rubocop_manual_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ Metrics/LineLength:
- spec/lib/open_food_network/order_cycle_form_applicator_spec.rb
- spec/lib/open_food_network/order_cycle_permissions_spec.rb
- spec/lib/open_food_network/order_grouper_spec.rb
- spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb
- spec/lib/open_food_network/packing_report_spec.rb
- spec/lib/open_food_network/permissions_spec.rb
- spec/lib/open_food_network/products_and_inventory_report_spec.rb
Expand Down
3 changes: 0 additions & 3 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,6 @@ Layout/SpaceInsideBlockBraces:
- 'spec/jobs/update_billable_periods_spec.rb'
- 'spec/lib/open_food_network/order_cycle_form_applicator_spec.rb'
- 'spec/lib/open_food_network/order_grouper_spec.rb'
- 'spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb'
- 'spec/lib/open_food_network/products_renderer_spec.rb'
- 'spec/lib/open_food_network/tag_rule_applicator_spec.rb'
- 'spec/models/column_preference_spec.rb'
Expand Down Expand Up @@ -1077,7 +1076,6 @@ Lint/Void:
- 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb'
- 'spec/lib/open_food_network/enterprise_issue_validator_spec.rb'
- 'spec/lib/open_food_network/group_buy_report_spec.rb'
- 'spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb'
- 'spec/lib/open_food_network/packing_report_spec.rb'
- 'spec/lib/open_food_network/reports/report_spec.rb'
- 'spec/lib/open_food_network/reports/rule_spec.rb'
Expand Down Expand Up @@ -2000,7 +1998,6 @@ Style/MixinUsage:
- 'spec/features/admin/orders_spec.rb'
- 'spec/lib/open_food_network/bulk_coop_report_spec.rb'
- 'spec/lib/open_food_network/order_cycle_management_report_spec.rb'
- 'spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb'
- 'spec/lib/open_food_network/packing_report_spec.rb'

# Offense count: 4
Expand Down
5 changes: 5 additions & 0 deletions app/models/concerns/address_display.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module AddressDisplay
def full_name_reverse
[lastname, firstname].reject(&:blank?).join(" ")
end
end
2 changes: 2 additions & 0 deletions app/models/spree/address_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Spree::Address.class_eval do
include AddressDisplay

has_one :enterprise, dependent: :restrict
belongs_to :country, class_name: "Spree::Country"

Expand Down
86 changes: 44 additions & 42 deletions lib/open_food_network/orders_and_fulfillments_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,55 +102,57 @@ def rules
sort_by: proc { |full_name| full_name } } ]
when "order_cycle_customer_totals"
[ { group_by: proc { |line_item| line_item.order.distributor },
sort_by: proc { |distributor| distributor.name } },
sort_by: proc { |distributor| distributor.name } },
{ group_by: proc { |line_item| line_item.order },
sort_by: proc { |order| order.bill_address.lastname + " " + order.bill_address.firstname },
summary_columns: [
proc { |line_items| line_items.first.order.distributor.name },
proc { |line_items| line_items.first.order.bill_address.firstname + " " + line_items.first.order.bill_address.lastname },
proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| I18n.t('admin.reports.total') },
proc { |line_items| "" },
sort_by: proc { |order| order.bill_address.full_name_reverse },
summary_columns: [
proc { |line_items| line_items.first.order.distributor.name },
proc { |line_items| line_items.first.order.bill_address.full_name },
proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| I18n.t('admin.reports.total') },
proc { |line_items| "" },

proc { |line_items| "" },
proc { |line_items| line_items.sum { |li| li.amount } },
proc { |line_items| line_items.sum { |li| li.amount_with_adjustments } },
proc { |line_items| line_items.map { |li| li.order }.uniq.sum { |o| o.admin_and_handling_total } },
proc { |line_items| line_items.map { |li| li.order }.uniq.sum { |o| o.ship_total } },
proc { |line_items| line_items.map { |li| li.order }.uniq.sum { |o| o.payment_fee } },
proc { |line_items| line_items.map { |li| li.order }.uniq.sum { |o| o.total } },
proc { |line_items| line_items.all? { |li| li.order.paid? } ? I18n.t(:yes) : I18n.t(:no) },
proc { |line_items| "" },
proc { |line_items| line_items.sum(&:amount) },
proc { |line_items| line_items.sum(&:amount_with_adjustments) },
proc { |line_items| line_items.first.order.admin_and_handling_total },
proc { |line_items| line_items.first.order.ship_total },
proc { |line_items| line_items.first.order.payment_fee },
proc { |line_items| line_items.first.order.total },
proc { |line_items| line_items.first.order.paid? ? I18n.t(:yes) : I18n.t(:no) },

proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| "" },

proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| "" },

proc { |line_items| line_items.first.order.special_instructions } ,
proc { |line_items| "" },

proc { |line_items| line_items.first.order.order_cycle.andand.name },
proc { |line_items| line_items.first.order.payments.first.andand.payment_method.andand.name },
proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| "" },

proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| "" }
] },
proc { |line_items| line_items.first.order.special_instructions } ,
proc { |line_items| "" },

proc { |line_items| line_items.first.order.order_cycle.andand.name },
proc { |line_items|
line_items.first.order.payments.first.andand.payment_method.andand.name
},
proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| "" }
] },
{ group_by: proc { |line_item| line_item.product },
sort_by: proc { |product| product.name } },
sort_by: proc { |product| product.name } },
{ group_by: proc { |line_item| line_item.variant },
sort_by: proc { |variant| variant.full_name } },
{ group_by: proc { |line_item| line_item.full_name },
sort_by: proc { |full_name| full_name } } ]
sort_by: proc { |full_name| full_name } } ]
else
[ { group_by: proc { |line_item| line_item.product.supplier },
sort_by: proc { |supplier| supplier.name } },
Expand Down Expand Up @@ -222,7 +224,7 @@ def columns
proc { |line_items| line_items.first.order.ship_address.andand.state if rsa.call(line_items) },

proc { |line_items| "" },
proc { |line_items| line_items.first.product.sku },
proc { |line_items| line_items.first.variant.sku },

proc { |line_items| line_items.first.order.order_cycle.andand.name },
proc { |line_items| line_items.first.order.payments.first.andand.payment_method.andand.name },
Expand Down
Loading

0 comments on commit 9e3734f

Please sign in to comment.