From 6d1a6c6d0ef3812dfec7429ac5428398f4060f62 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Tue, 5 Mar 2024 15:58:26 +1100 Subject: [PATCH] Fix orders and fulfillment reports Plus specs --- lib/reporting/line_items.rb | 2 +- lib/reporting/reports/orders_and_fulfillment/base.rb | 4 ++-- .../orders_and_fulfillment/order_cycle_customer_totals.rb | 2 +- .../order_cycle_distributor_totals_by_supplier.rb | 2 +- .../orders_and_fulfillment/order_cycle_supplier_totals.rb | 2 +- .../order_cycle_supplier_totals_by_distributor.rb | 2 +- .../order_cycle_customer_totals_report_spec.rb | 2 +- .../order_cycle_distributor_totals_by_supplier_report_spec.rb | 2 +- .../order_cycle_supplier_totals_by_distributor_report_spec.rb | 2 +- .../orders_cycle_supplier_totals_report_spec.rb | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/reporting/line_items.rb b/lib/reporting/line_items.rb index 233c965c2a..01cd726ed0 100644 --- a/lib/reporting/line_items.rb +++ b/lib/reporting/line_items.rb @@ -15,7 +15,7 @@ module Reporting @orders ||= search_orders end - def list(line_item_includes = [variant: [product: :supplier]]) + def list(line_item_includes = [variant: [:supplier, :product]]) line_items = order_permissions.visible_line_items.in_orders(orders.result) .order("supplier.name", "product.name", "variant.display_name") diff --git a/lib/reporting/reports/orders_and_fulfillment/base.rb b/lib/reporting/reports/orders_and_fulfillment/base.rb index 4d223be657..36b6ecf325 100644 --- a/lib/reporting/reports/orders_and_fulfillment/base.rb +++ b/lib/reporting/reports/orders_and_fulfillment/base.rb @@ -49,11 +49,11 @@ module Reporting end def supplier_name - proc { |line_items| line_items.first.variant.product.supplier.name } + proc { |line_items| line_items.first.variant.supplier.name } end def supplier_charges_sales_tax? - proc { |line_items| line_items.first.variant.product.supplier.charges_sales_tax } + proc { |line_items| line_items.first.variant.supplier.charges_sales_tax } end def product_name diff --git a/lib/reporting/reports/orders_and_fulfillment/order_cycle_customer_totals.rb b/lib/reporting/reports/orders_and_fulfillment/order_cycle_customer_totals.rb index 8a538dfe23..b5703dcbda 100644 --- a/lib/reporting/reports/orders_and_fulfillment/order_cycle_customer_totals.rb +++ b/lib/reporting/reports/orders_and_fulfillment/order_cycle_customer_totals.rb @@ -93,7 +93,7 @@ module Reporting end def line_item_includes - [{ variant: { product: :supplier }, + [{ variant: [:product, :supplier], order: [:bill_address, :ship_address, :order_cycle, :adjustments, :payments, :user, :distributor, :shipments] }] end diff --git a/lib/reporting/reports/orders_and_fulfillment/order_cycle_distributor_totals_by_supplier.rb b/lib/reporting/reports/orders_and_fulfillment/order_cycle_distributor_totals_by_supplier.rb index 9e2dcd4d43..f39cae4725 100644 --- a/lib/reporting/reports/orders_and_fulfillment/order_cycle_distributor_totals_by_supplier.rb +++ b/lib/reporting/reports/orders_and_fulfillment/order_cycle_distributor_totals_by_supplier.rb @@ -40,7 +40,7 @@ module Reporting :adjustments, { shipments: { shipping_rates: :shipping_method } } ], - variant: { product: :supplier } + variant: [:product, :supplier] }] end end diff --git a/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals.rb b/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals.rb index 87837d32a0..dedbc9e2d8 100644 --- a/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals.rb +++ b/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals.rb @@ -42,7 +42,7 @@ module Reporting end def line_item_includes - [{ variant: { product: :supplier } }] + [{ variant: [:supplier, :product] }] end def query_result diff --git a/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor.rb b/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor.rb index 3d7c211126..aae3478837 100644 --- a/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor.rb +++ b/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor.rb @@ -41,7 +41,7 @@ module Reporting def line_item_includes [{ order: :distributor, - variant: { product: :supplier } }] + variant: [:product, :supplier] }] end end end diff --git a/spec/lib/reports/orders_and_fulfillment/order_cycle_customer_totals_report_spec.rb b/spec/lib/reports/orders_and_fulfillment/order_cycle_customer_totals_report_spec.rb index 16511bca45..8ca2d09130 100644 --- a/spec/lib/reports/orders_and_fulfillment/order_cycle_customer_totals_report_spec.rb +++ b/spec/lib/reports/orders_and_fulfillment/order_cycle_customer_totals_report_spec.rb @@ -29,7 +29,7 @@ RSpec.describe Reporting::Reports::OrdersAndFulfillment::OrderCycleCustomerTotal distributor:, completed_at: order_date, ).tap do |order| - order.line_items[0].product.supplier.update(name: "Apple Farmer") + order.line_items[0].variant.supplier.update(name: "Apple Farmer") order.line_items[0].product.update(name: "Apples") order.line_items[0].variant.update(sku: "APP") end diff --git a/spec/lib/reports/orders_and_fulfillment/order_cycle_distributor_totals_by_supplier_report_spec.rb b/spec/lib/reports/orders_and_fulfillment/order_cycle_distributor_totals_by_supplier_report_spec.rb index 9bedefa186..094e9a5c72 100644 --- a/spec/lib/reports/orders_and_fulfillment/order_cycle_distributor_totals_by_supplier_report_spec.rb +++ b/spec/lib/reports/orders_and_fulfillment/order_cycle_distributor_totals_by_supplier_report_spec.rb @@ -30,7 +30,7 @@ module Reporting distributor_name_field = report_table.first[0] expect(distributor_name_field).to eq distributor.name - supplier = order.line_items.first.variant.product.supplier + supplier = order.line_items.first.variant.supplier supplier_name_field = report_table.first[1] expect(supplier_name_field).to eq supplier.name end diff --git a/spec/lib/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor_report_spec.rb b/spec/lib/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor_report_spec.rb index c6cbb733d0..4681387af4 100644 --- a/spec/lib/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor_report_spec.rb +++ b/spec/lib/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor_report_spec.rb @@ -27,7 +27,7 @@ module Reporting end it "has a variant row under the distributor" do - supplier = order.line_items.first.variant.product.supplier + supplier = order.line_items.first.variant.supplier expect(report.rows.first.producer).to eq supplier.name expect(report.rows.first.hub).to eq distributor.name end diff --git a/spec/lib/reports/orders_and_fulfillment/orders_cycle_supplier_totals_report_spec.rb b/spec/lib/reports/orders_and_fulfillment/orders_cycle_supplier_totals_report_spec.rb index c40dcc90db..e81596cbbd 100644 --- a/spec/lib/reports/orders_and_fulfillment/orders_cycle_supplier_totals_report_spec.rb +++ b/spec/lib/reports/orders_and_fulfillment/orders_cycle_supplier_totals_report_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Reporting::Reports::OrdersAndFulfillment::OrderCycleSupplierTotal create(:completed_order_with_totals, line_items_count: 1, distributor:) end let!(:supplier) do - order.line_items.first.variant.product.supplier + order.line_items.first.variant.supplier end let(:current_user) { distributor.owner } let(:params) { { display_summary_row: false, fields_to_hide: [] } }