Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4218 customize distribution receipt #4234

Merged
merged 27 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8b264a0
add params to print button to alter distribution pdf
nikolaz90 Mar 27, 2024
6b2677d
add print params for hide columns on distribution pdf and partial on …
nikolaz90 Mar 28, 2024
6e8751a
adds initial spec for #hide_columns on DistributionPDF
nikolaz90 Mar 28, 2024
229af82
wip : adds comments and tweaks to DistributionPDF spec
nikolaz90 Mar 29, 2024
cf51d5c
undoing params approach to print distribution
nikolaz90 Mar 27, 2024
4faa738
add print params for hide columns on distribution pdf and partial on …
nikolaz90 Mar 28, 2024
0cd2268
adds initial spec for #hide_columns on DistributionPDF
nikolaz90 Mar 28, 2024
b55022d
removed print btn with params distribution with params
nikolaz90 Mar 29, 2024
50e8c68
deletion and comments
nikolaz90 Apr 11, 2024
64368e2
db:migrate
nikolaz90 Apr 11, 2024
1d134dd
add hide option booleans on organizations
nikolaz90 Apr 11, 2024
c00e459
resolve conflicts
nikolaz90 Apr 11, 2024
640476e
comments
nikolaz90 Apr 11, 2024
2e8b185
remove unnecessary partials from distributions show and edit
nikolaz90 Apr 11, 2024
4efbdad
add radio buttons to customize distribution receipt on organizations
nikolaz90 Apr 11, 2024
f74c276
adds context to distribution pdf spec
nikolaz90 Apr 11, 2024
bfb4c2a
add more specs depending on organization print options on distributions
nikolaz90 Apr 17, 2024
d8a7116
Merge branch 'main' into 4218_customize_distribution_receipt
nikolaz90 Apr 20, 2024
87a11aa
add item name to spec
nikolaz90 Apr 21, 2024
f412894
update with upstream
nikolaz90 Apr 21, 2024
e3a8e90
Merge branch '4218_customize_distribution_receipt' of github.com:niko…
nikolaz90 Apr 21, 2024
42ea8dd
tweak on spec for GH actions
nikolaz90 Apr 21, 2024
7fec31c
bundle
nikolaz90 Apr 24, 2024
b93bb17
revert timestamps on schema.
nikolaz90 Apr 24, 2024
2e4fd61
review hide_columns method on DistributionPDF
nikolaz90 May 2, 2024
0576430
merge main and resolve conflicts
nikolaz90 May 10, 2024
2dcd2e3
Merge branch 'main' into 4218_customize_distribution_receipt
dorner May 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -755,4 +755,4 @@ DEPENDENCIES
webmock (~> 3.23)

BUNDLED WITH
2.5.7
2.5.9
1 change: 1 addition & 0 deletions app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def organization_params
:ndbn_member_id, :enable_child_based_requests,
:enable_individual_requests, :enable_quantity_based_requests,
:ytd_on_distribution_printout, :one_step_partner_invite,
:hide_value_columns_on_receipt, :hide_package_column_on_receipt,
partner_form_fields: []
)
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# enable_child_based_requests :boolean default(TRUE), not null
# enable_individual_requests :boolean default(TRUE), not null
# enable_quantity_based_requests :boolean default(TRUE), not null
# hide_package_column_on_receipt :boolean default(FALSE)
# hide_value_columns_on_receipt :boolean default(FALSE)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cielf I'm kind of starting to feel like some of these fields belong in a "settings" model. E.g. these and ytd_on_distribution_printout - these are suuuper particular to be sitting on essentially our "god model". Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a convenience factor in having the organization view looking just at the organization model, I suppose. I do agree that a lot of these are really really specific.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's talk about it on Sunday -- it would be a new issue, in any case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to refactor this PR to include a settings table, or print options table if that helps

# intake_location :integer
# invitation_text :text
# latitude :float
Expand Down
22 changes: 21 additions & 1 deletion app/pdfs/distribution_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def compute_and_render
data = @distribution.request ? request_data : non_request_data
has_request = @distribution.request.present?

hide_columns(data)
hidden_columns_length = column_names_to_hide.length

font_size 11
# Line item table
table(data) do
Expand Down Expand Up @@ -109,7 +112,7 @@ def compute_and_render
row(-2).borders = [:top]
row(-2).padding = [2, 0, 2, 0]

column(0).width = 190
column(0).width = 190 + (hidden_columns_length * 60)

# Quantity column
column(1..-1).row(1..-3).borders = [:left]
Expand Down Expand Up @@ -212,4 +215,21 @@ def non_request_data
@distribution.line_items.total,
""]]
end

def hide_columns(data)
column_names_to_hide.each do |col_name|
col_index = data.first.find_index(col_name)
data.each { |line| line.delete_at(col_index) } if col_index.present?
end
end

private

def column_names_to_hide
in_kind_column_name = @distribution.request.present? ? "In-Kind Value Received" : "In-Kind Value"
columns_to_hide = []
columns_to_hide.push("Value/item", in_kind_column_name) if @organization.hide_value_columns_on_receipt
columns_to_hide.push("Packages") if @organization.hide_package_column_on_receipt
columns_to_hide
end
end
12 changes: 12 additions & 0 deletions app/views/organizations/_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@
<%= humanize_boolean(@organization.one_step_partner_invite) %>
</p>
</div>
<div class="mb-4">
<h3 class='font-bold'>Hide value columns on receipt:</h3>
<p>
<%= humanize_boolean(@organization.hide_value_columns_on_receipt) %>
</p>
</div>
<div class="mb-4">
<h3 class='font-bold'>Hide package column on receipt:</h3>
<p>
<%= humanize_boolean(@organization.hide_package_column_on_receipt) %>
</p>
</div>
<% if @organization.logo.attached? %>
<div class="mb-4">
<h3 class='font-bold'>Logo</h3>
Expand Down
2 changes: 2 additions & 0 deletions app/views/organizations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
<%= f.input :enable_quantity_based_requests, label: 'Enable partners to make quantity-based requests?', as: :radio_buttons, collection: [[true, 'Yes'], [false, 'No']], label_method: :second, value_method: :first %>
<%= f.input :ytd_on_distribution_printout, label: 'Show Year-to-date values on distribution printout?', as: :radio_buttons, collection: [[true, 'Yes'], [false, 'No']], label_method: :second, value_method: :first %>
<%= f.input :one_step_partner_invite, label: 'Use One Step Invite and Approve partner process?', as: :radio_buttons, collection: [[true, 'Yes'], [false, 'No']], label_method: :second, value_method: :first %>
<%= f.input :hide_value_columns_on_receipt, label: 'Hide both value columns on distribution receipts?', as: :radio_buttons, collection: [[true, 'Yes'], [false, 'No']], label_method: :second, value_method: :first %>
<%= f.input :hide_package_column_on_receipt, label: 'Hide the package column on distribution receipts?', as: :radio_buttons, collection: [[true, 'Yes'], [false, 'No']], label_method: :second, value_method: :first %>

<% default_email_text_hint = "You can use the variables <code>%{partner_name}</code>, <code>%{delivery_method}</code>, <code>%{distribution_date}</code>, and <code>%{comment}</code> to include the partner's name, delivery method, distribution date, and comments sent in the request." %>
<%= f.input :default_email_text, label: "Distribution Email Content", hint: default_email_text_hint.html_safe do %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddHideOptionsForDistributionPrintingToOrganizations < ActiveRecord::Migration[7.0]
def change
add_column :organizations, :hide_value_columns_on_receipt, :boolean
add_column :organizations, :hide_package_column_on_receipt, :boolean
# Followed strong migration advice, with Backfill migration too
change_column_default :organizations, :hide_value_columns_on_receipt, false
change_column_default :organizations, :hide_package_column_on_receipt, false
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class BackfillAddHideOptionsForDistributionPrintingToOrganizations < ActiveRecord::Migration[7.0]
def change
Organization.unscoped.in_batches do |relation|
relation.update_all hide_value_columns_on_receipt: false, hide_package_column_on_receipt: false
sleep(0.01)
end
end
end
5 changes: 4 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2024_04_02_230156) do
ActiveRecord::Schema[7.0].define(version: 2024_04_11_183741) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -484,6 +485,8 @@
t.boolean "enable_quantity_based_requests", default: true, null: false
t.boolean "ytd_on_distribution_printout", default: true, null: false
t.boolean "one_step_partner_invite", default: false, null: false
t.boolean "hide_value_columns_on_receipt", default: false
t.boolean "hide_package_column_on_receipt", default: false
t.index ["latitude", "longitude"], name: "index_organizations_on_latitude_and_longitude"
t.index ["short_name"], name: "index_organizations_on_short_name"
end
Expand Down
2 changes: 2 additions & 0 deletions spec/factories/organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# enable_child_based_requests :boolean default(TRUE), not null
# enable_individual_requests :boolean default(TRUE), not null
# enable_quantity_based_requests :boolean default(TRUE), not null
# hide_package_column_on_receipt :boolean default(FALSE)
# hide_value_columns_on_receipt :boolean default(FALSE)
# intake_location :integer
# invitation_text :text
# latitude :float
Expand Down
2 changes: 1 addition & 1 deletion spec/models/item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
expect(Item.by_base_item(@c1).size).to eq(1)
end
it "can be chained to organization to constrain it to just 1 org's items" do
create(:item, base_item: @c1, organization: create(:organization))
create(:item, name: "1", base_item: @c1, organization: create(:organization))
expect(@organization.items.by_base_item(@c1).size).to eq(1)
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/models/organization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# enable_child_based_requests :boolean default(TRUE), not null
# enable_individual_requests :boolean default(TRUE), not null
# enable_quantity_based_requests :boolean default(TRUE), not null
# hide_package_column_on_receipt :boolean default(FALSE)
# hide_value_columns_on_receipt :boolean default(FALSE)
# intake_location :integer
# invitation_text :text
# latitude :float
Expand Down
92 changes: 92 additions & 0 deletions spec/pdfs/distribution_pdf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
let(:item2) { FactoryBot.create(:item, name: "Item 2", value_in_cents: 200) }
let(:item3) { FactoryBot.create(:item, name: "Item 3", value_in_cents: 300) }
let(:item4) { FactoryBot.create(:item, name: "Item 4", package_size: 25, value_in_cents: 400) }

let(:org_hiding_packages_and_values) do
FactoryBot.create(:organization, name: DEFAULT_TEST_ORGANIZATION_NAME,
hide_value_columns_on_receipt: true, hide_package_column_on_receipt: true)
end
let(:org_hiding_packages) { FactoryBot.create(:organization, name: DEFAULT_TEST_ORGANIZATION_NAME, hide_package_column_on_receipt: true) }
let(:org_hiding_values) { FactoryBot.create(:organization, name: DEFAULT_TEST_ORGANIZATION_NAME, hide_value_columns_on_receipt: true) }

before(:each) do
FactoryBot.create(:line_item, itemizable: distribution, item: item1, quantity: 50)
FactoryBot.create(:line_item, itemizable: distribution, item: item2, quantity: 100)
Expand Down Expand Up @@ -37,5 +45,89 @@
["Total Items Received", "", "$250.00", 150, ""]
])
end

context "with request data" do
describe "#hide_columns" do
it "hides value and package columns when true on organization" do
pdf = described_class.new(org_hiding_packages_and_values, distribution)
data = pdf.request_data
pdf.hide_columns(data)
expect(data).to eq([
["Items Received", "Requested", "Received"],
["Item 1", "", 50],
["Item 2", 30, 100],
["Item 3", 50, ""],
["Item 4", 120, ""],
["", "", ""],
["Total Items Received", 200, 150]
])
end

it "hides value columns when true on organization" do
pdf = described_class.new(org_hiding_values, distribution)
data = pdf.request_data
pdf.hide_columns(data)
expect(data).to eq([
["Items Received", "Requested", "Received", "Packages"],
["Item 1", "", 50, "1"],
["Item 2", 30, 100, nil],
["Item 3", 50, "", nil],
["Item 4", 120, "", nil],
["", "", ""],
["Total Items Received", 200, 150, ""]
])
end
end
end

context "with non request data" do
it "hides value and package columns when true on organization" do
pdf = described_class.new(org_hiding_packages_and_values, distribution)
data = pdf.request_data
pdf.hide_columns(data)
expect(data).to eq([
["Items Received", "Requested", "Received"],
["Item 1", "", 50],
["Item 2", 30, 100],
["Item 3", 50, ""],
["Item 4", 120, ""],
["", "", ""],
["Total Items Received", 200, 150]
])
end

it "hides value columns when true on organization" do
pdf = described_class.new(org_hiding_values, distribution)
data = pdf.request_data
pdf.hide_columns(data)
expect(data).to eq([
["Items Received", "Requested", "Received", "Packages"],
["Item 1", "", 50, "1"],
["Item 2", 30, 100, nil],
["Item 3", 50, "", nil],
["Item 4", 120, "", nil],
["", "", ""],
["Total Items Received", 200, 150, ""]
])
end
end
context "regardles of request data" do
describe "#hide_columns" do
it "hides package column when true on organization" do
pdf = described_class.new(org_hiding_packages, distribution)
data = pdf.request_data
pdf.hide_columns(data)
expect(data).to eq([
["Items Received", "Requested", "Received", "Value/item", "In-Kind Value Received"],
["Item 1", "", 50, "$1.00", "$50.00"],
["Item 2", 30, 100, "$2.00", "$200.00"],
["Item 3", 50, "", "$3.00", nil],
["Item 4", 120, "", "$4.00", nil],
["", "", "", "", ""],
["Total Items Received", 200, 150, "", "$250.00"]
])
end
end
end
end
# rubocop:enable Layout/ArrayAlignment