Merge pull request #10664 from abdellani/fix-remove-duplicated-cusomter-from-mailing-list-report

Fix Repeated customer entries on Mailing List Report
This commit is contained in:
Konrad
2023-04-16 21:17:33 +02:00
committed by GitHub
2 changed files with 36 additions and 0 deletions

View File

@@ -4,6 +4,17 @@ module Reporting
module Reports
module Customers
class MailingList < Base
def query_result
super.group_by do |order|
{
email: order.email,
first_name: order.billing_address.firstname,
last_name: order.billing_address.lastname,
suburb: order.billing_address.city,
}
end.values.map(&:first)
end
def columns
{
email: proc { |order| order.email },

View File

@@ -32,6 +32,31 @@ module Reporting
"test@test.com", "Firsty", "Lasty", "Suburbia"
]])
end
context "when there are multiple orders for the same customer" do
let!(:address) {
create(:bill_address, firstname: "Firsty",
lastname: "Lasty", city: "Suburbia")
}
let!(:order1) {
create(:order_with_totals_and_distribution, :completed, bill_address: address)
}
let!(:order2) {
create(:order_with_totals_and_distribution, :completed, bill_address: address)
}
before do
[order1, order2].each do |order|
order.update!(email: "test@test.com")
end
end
it "returns only one row per customer" do
expect(subject.query_result).to match_array [order1]
expect(subject.table_rows.size).to eq(1)
expect(subject.table_rows).to eq([[
"test@test.com", "Firsty", "Lasty", "Suburbia"
]])
end
end
end
describe "addresses report" do