Skip to content

Commit f005fbc

Browse files
5250 add quota to pick sheets (#5264)
* Add quota information to PDF output * Add tests for rendering quota information in PicklistsPdf * Update essentials_requests_picklist.png image in user guide * Refactor quota information rendering in PicklistsPdf to display only when set and greater than zero
1 parent 6b3c5c6 commit f005fbc

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

app/pdfs/picklists_pdf.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ def compute_and_render
7676
font_size 10
7777
end
7878

79+
# Add quota information only if quota is set and greater than 0
80+
quota = request.partner.quota
81+
if quota && quota > 0
82+
move_down 5
83+
text "Quota:", style: :bold, align: :right
84+
font_size 12
85+
text quota.to_s, align: :right
86+
font_size 10
87+
end
88+
7989
move_down 10
8090
text "Comments:", style: :bold
8191
font_size 12
-56.1 KB
Loading

spec/pdfs/picklists_pdf_spec.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,43 @@
6767
expect(pdf_test.page(1).text).to include(request.partner.profile.pick_up_phone)
6868
end
6969
end
70+
71+
context "when partner has a quota" do
72+
it "renders the quota information when quota is set" do
73+
partner = create(:partner)
74+
partner.update(quota: 100)
75+
request = create(:request, :pending, organization: organization, partner: partner)
76+
create(:item_request, request: request, item: item1, name: "Item 1")
77+
78+
pdf = described_class.new(organization, [request])
79+
pdf_test = PDF::Reader.new(StringIO.new(pdf.compute_and_render))
80+
81+
expect(pdf_test.page(1).text).to include("Quota:")
82+
expect(pdf_test.page(1).text).to include("100")
83+
end
84+
85+
it "does not render quota information when quota is not set" do
86+
partner = create(:partner, quota: nil)
87+
request = create(:request, :pending, organization: organization, partner: partner)
88+
create(:item_request, request: request, item: item1, name: "Item 1")
89+
90+
pdf = described_class.new(organization, [request])
91+
pdf_test = PDF::Reader.new(StringIO.new(pdf.compute_and_render))
92+
93+
expect(pdf_test.page(1).text).not_to include("Quota:")
94+
end
95+
96+
it "does not render quota information when quota is zero" do
97+
partner = create(:partner, quota: 0)
98+
request = create(:request, :pending, organization: organization, partner: partner)
99+
create(:item_request, request: request, item: item1, name: "Item 1")
100+
101+
pdf = described_class.new(organization, [request])
102+
pdf_test = PDF::Reader.new(StringIO.new(pdf.compute_and_render))
103+
104+
expect(pdf_test.page(1).text).not_to include("Quota:")
105+
end
106+
end
70107
end
71108

72109
context "When packs are not enabled" do

0 commit comments

Comments
 (0)