From cc26da6560e4ba1d39f841b59a8c08ac4df7f11d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 10 Jul 2023 11:26:25 +0200 Subject: [PATCH] We'll need to get all the orders per line to count and sum them; prepare it --- lib/reporting/reports/customers/addresses.rb | 18 +++++++++--------- spec/lib/reports/customers_report_spec.rb | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/reporting/reports/customers/addresses.rb b/lib/reporting/reports/customers/addresses.rb index 28362586f7..569a509224 100644 --- a/lib/reporting/reports/customers/addresses.rb +++ b/lib/reporting/reports/customers/addresses.rb @@ -15,19 +15,19 @@ module Reporting hub_id: order.distributor_id, shipping_method_id: order.shipping_method&.id, } - end.values.map(&:first) + end.values end def columns { - first_name: proc { |order| order.billing_address.firstname }, - last_name: proc { |order| order.billing_address.lastname }, - billing_address: proc { |order| order.billing_address.address_and_city }, - email: proc { |order| order.email }, - phone: proc { |order| order.billing_address.phone }, - hub: proc { |order| order.distributor&.name }, - hub_address: proc { |order| order.distributor&.address&.address_and_city }, - shipping_method: proc { |order| order.shipping_method&.name }, + first_name: proc { |orders| orders.first.billing_address.firstname }, + last_name: proc { |orders| orders.first.billing_address.lastname }, + billing_address: proc { |orders| orders.first.billing_address.address_and_city }, + email: proc { |orders| orders.first.email }, + phone: proc { |orders| orders.first.billing_address.phone }, + hub: proc { |orders| orders.first.distributor&.name }, + hub_address: proc { |orders| orders.first.distributor&.address&.address_and_city }, + shipping_method: proc { |orders| orders.first.shipping_method&.name }, } end diff --git a/spec/lib/reports/customers_report_spec.rb b/spec/lib/reports/customers_report_spec.rb index df8c3e4aa9..fdd7926328 100644 --- a/spec/lib/reports/customers_report_spec.rb +++ b/spec/lib/reports/customers_report_spec.rb @@ -74,7 +74,7 @@ module Reporting o = create(:order, distributor: d, bill_address: a) o.shipments << create(:shipment) - allow(subject).to receive(:query_result).and_return [o] + allow(subject).to receive(:query_result).and_return [[o]] expect(subject.table_rows).to eq([[ a.firstname, a.lastname, [a.address1, a.address2, a.city].join(" "), @@ -106,7 +106,7 @@ module Reporting end it "returns only one row per customer" do - expect(subject.query_result).to match_array [o1] + expect(subject.query_result).to match_array [[o1, o2]] expect(subject.table_rows.size).to eq(1) expect(subject.table_rows) .to eq([[