Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3528 Scope Customer Totals report also by variant (not just product) and use variant SKU #3646

Merged
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