Skip to content

Commit

Permalink
Scope query to org and use item_requests instead of request_items
Browse files Browse the repository at this point in the history
  • Loading branch information
norrismei committed Sep 12, 2024
1 parent 7ec63c3 commit 03a7b79
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 5 additions & 1 deletion app/controllers/requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ def start
end

def print_unfulfilled
requests = Request.includes(partner: [:profile]).where(status: [0, 1])
requests = current_organization
.requests
.includes(:item_requests, partner: [:profile])
.where(status: [:pending, :started])
.order(created_at: :desc)

respond_to do |format|
format.any do
Expand Down
14 changes: 8 additions & 6 deletions app/pdfs/picklists_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ def compute_and_render

move_down 20

items = request.request_items.map do |request_item|
RequestItem.from_json(request_item, request)
end
items = request.item_requests
data = has_custom_units?(items) ? data_with_units(items) : data_no_units(items)

font_size 11
Expand Down Expand Up @@ -134,7 +132,7 @@ def compute_and_render
end

def has_custom_units?(items)
Flipper.enabled?(:enable_packs) && items.any? { |item| item.unit }
Flipper.enabled?(:enable_packs) && items.any? { |item| item.request_unit }
end

def data_with_units(items)
Expand All @@ -145,7 +143,9 @@ def data_with_units(items)
"Differences / Comments"]]

data + items.map do |i|
[i.item.name,
item_name = Item.find(i.item_id).name

[item_name,
i.quantity,
i.unit&.capitalize&.pluralize(i.quantity),
"[ ]",
Expand All @@ -160,7 +160,9 @@ def data_no_units(items)
"Differences / Comments"]]

data + items.map do |i|
[i.item.name,
item_name = Item.find(i.item_id).name

[item_name,
i.quantity,
"[ ]",
""]
Expand Down

0 comments on commit 03a7b79

Please sign in to comment.