Merge pull request #9808 from abdellani/sort_items_by_product_name_in_ocstd_report

add sort by product name to order_cycle_supplier_totals_by_distributo…
This commit is contained in:
Konrad
2022-10-25 10:34:22 +02:00
committed by GitHub
2 changed files with 12 additions and 3 deletions

View File

@@ -24,7 +24,8 @@ module Reporting
header: true,
},
{
group_by: proc { |line_items, _row| line_items.first.variant }
group_by: proc { |line_items, _row| line_items.first.variant },
sort_by: proc { |variant| variant.product.name }
},
{
group_by: :hub,

View File

@@ -9,7 +9,7 @@ module Reporting
let!(:distributor) { create(:distributor_enterprise) }
let!(:order) do
create(:completed_order_with_totals, line_items_count: 1, distributor: distributor)
create(:completed_order_with_totals, line_items_count: 3, distributor: distributor)
end
let(:current_user) { distributor.owner }
@@ -23,7 +23,7 @@ module Reporting
end
it "generates the report" do
expect(report_table.length).to eq(2)
expect(report_table.length).to eq(6)
end
it "has a variant row under the distributor" do
@@ -31,6 +31,14 @@ module Reporting
expect(report.rows.first.producer).to eq supplier.name
expect(report.rows.first.hub).to eq distributor.name
end
it "lists products sorted by name" do
order.line_items[0].variant.product.update(name: "Cucumber")
order.line_items[1].variant.product.update(name: "Apple")
order.line_items[2].variant.product.update(name: "Banane")
product_names = report.rows.map(&:product).filter(&:present?)
expect(product_names).to eq(["Apple", "Banane", "Cucumber"])
end
end
end
end