diff --git a/app/pdfs/distribution_pdf.rb b/app/pdfs/distribution_pdf.rb index fe80342034..d9f6affcd6 100644 --- a/app/pdfs/distribution_pdf.rb +++ b/app/pdfs/distribution_pdf.rb @@ -122,7 +122,6 @@ def compute_and_render # Quantity column column(1..-1).row(1..-3).borders = [:left] column(1..-1).row(1..-3).border_left_color = "aaaaaa" - column(1).style align: :right column(-1).row(-1).borders = [:left, :bottom] end @@ -178,20 +177,20 @@ def request_data end data += line_items.map do |c| - request_item = request_items.find { |i| i.item.id == c.item_id } + request_item = request_items.find { |i| i.item&.id == c.item_id } [c.item.name, - request_item&.quantity || "", + request_display_qty(request_item), c.quantity, dollar_value(c.item.value_in_cents), dollar_value(c.value_per_line_item), c.package_count] end - data += requested_not_received.sort_by(&:name).map do |c| - [c.item.name, - c.quantity, + data += requested_not_received.sort_by(&:name).map do |request_item| + [request_item.item.name, + request_display_qty(request_item), "", - dollar_value(c.item.value_in_cents), + dollar_value(request_item.item.value_in_cents), nil, nil] end @@ -276,4 +275,12 @@ def signature_lines_for(label) draw_text "(Print Name)", at: [0, cursor] draw_text "(Signature and Date)", at: [right_start, cursor] end + + def request_display_qty(request_item) + if Flipper.enabled?(:enable_packs) && request_item&.unit + "#{request_item.quantity} #{request_item.unit.pluralize(request_item.quantity)}" + else + request_item&.quantity || "" + end + end end diff --git a/spec/pdfs/distribution_pdf_spec.rb b/spec/pdfs/distribution_pdf_spec.rb index 44aea55227..268bd67484 100644 --- a/spec/pdfs/distribution_pdf_spec.rb +++ b/spec/pdfs/distribution_pdf_spec.rb @@ -18,9 +18,13 @@ before(:each) do create(:line_item, itemizable: distribution, item: item1, quantity: 50) create(:line_item, itemizable: distribution, item: item2, quantity: 100) - create(:request, distribution: distribution, - request_items: [{"item_id" => item2.id, "quantity" => 30}, - {"item_id" => item3.id, "quantity" => 50}, {"item_id" => item4.id, "quantity" => 120}]) + create(:item_unit, item: item4, name: "pack") + create(:request, :with_item_requests, distribution: distribution, + request_items: [ + {"item_id" => item2.id, "quantity" => 30}, + {"item_id" => item3.id, "quantity" => 50}, + {"item_id" => item4.id, "quantity" => 120, "request_unit" => "pack"} +]) end specify "#request_data" do @@ -36,6 +40,20 @@ ]) end + specify "#request_data with custom units feature" do + Flipper.enable(:enable_packs) + results = described_class.new(organization, distribution).request_data + expect(results).to eq([ + ["Items Received", "Requested", "Received", "Value/item", "In-Kind Value Received", "Packages"], + ["Item 1", "", 50, "$1.00", "$50.00", "1"], + ["Item 2", 30, 100, "$2.00", "$200.00", nil], + ["Item 3", 50, "", "$3.00", nil, nil], + ["Item 4", "120 packs", "", "$4.00", nil, nil], + ["", "", "", "", ""], + ["Total Items Received", 200, 150, "", "$250.00", ""] + ]) + end + specify "#non_request_data" do results = described_class.new(organization, distribution).non_request_data expect(results).to eq([