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

[Kit Redesign] Phase 1 - Change itemizable source #3750

Draft
wants to merge 62 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
83347ed
KitAllocation model added for inventory in and inventory out
zeeshan-haidar Jun 6, 2023
2373afb
allocate inventory in and out actions added
zeeshan-haidar Jun 6, 2023
3327d74
Deallocation for inventory in and inventory out added
zeeshan-haidar Jun 7, 2023
8345ef6
spec added for inventory in and inventory out when kit is allocated
zeeshan-haidar Jun 7, 2023
58c8862
fixed typo error
zeeshan-haidar Jun 7, 2023
b30215b
test case added for kit with multiple line items
zeeshan-haidar Jun 8, 2023
d8d1e7b
testcases added for deallocating inventory_in and inventory_out
zeeshan-haidar Jun 8, 2023
bef402e
Merge branch 'main' of github.com:zeeshan-haidar/human-essentials int…
zeeshan-haidar Jun 8, 2023
ded1d9e
rubocop lint applied
zeeshan-haidar Jun 9, 2023
e049dbc
factory_bot lint fixed
zeeshan-haidar Jun 9, 2023
f3fb846
Merge branch 'main' of github.com:zeeshan-haidar/human-essentials int…
zeeshan-haidar Jun 12, 2023
301a67b
removed ruby enum kit_allocation_type
zeeshan-haidar Jun 12, 2023
3912f08
inventory enum added to kit_allocations
zeeshan-haidar Jun 12, 2023
11be7a6
Merge branch 'main' of github.com:zeeshan-haidar/human-essentials int…
zeeshan-haidar Jun 14, 2023
256dcf3
data migration for invetory_in and invetory_out
zeeshan-haidar Jun 14, 2023
592da55
rubocop linting applied
zeeshan-haidar Jun 15, 2023
595b96f
column shipping_cost added to distributions
zeeshan-haidar Jun 16, 2023
b2b377e
added shipping_cost field on distribution form
zeeshan-haidar Jun 19, 2023
6588d3b
save shipping_cost to distribution
zeeshan-haidar Jun 19, 2023
44f6928
Merge branch 'main' of github.com:zeeshan-haidar/human-essentials int…
zeeshan-haidar Jun 20, 2023
9cbd420
shipping cost label added
zeeshan-haidar Jun 20, 2023
9df7f46
shipping cost added to export and view
zeeshan-haidar Jun 20, 2023
ad078b6
Merge branch 'main' of github.com:zeeshan-haidar/human-essentials int…
zeeshan-haidar Jun 20, 2023
15693c6
backfill distribution's shipping cost
zeeshan-haidar Jun 20, 2023
16defa1
Merge branch 'main' of github.com:zeeshan-haidar/human-essentials int…
zeeshan-haidar Jun 21, 2023
162a3ab
Merge branch 'main' of github.com:zeeshan-haidar/human-essentials int…
zeeshan-haidar Jun 21, 2023
02c6cd2
test case added for distribution shipping_cost
zeeshan-haidar Jun 21, 2023
123afb3
fixed failing specs
zeeshan-haidar Jun 21, 2023
32dd83a
for testing
zeeshan-haidar Jun 21, 2023
2061c4f
fixed faling spec
zeeshan-haidar Jun 21, 2023
5325b69
added test case for shipping cost field
zeeshan-haidar Jun 22, 2023
3065054
added distribution shipping cost on view page
zeeshan-haidar Jun 22, 2023
9ccbd6e
Merge branch 'main' of github.com:zeeshan-haidar/human-essentials int…
zeeshan-haidar Jun 23, 2023
fed4645
rubocop linting fixed
zeeshan-haidar Jun 23, 2023
8332212
Merge branch 'main' of github.com:zeeshan-haidar/human-essentials int…
zeeshan-haidar Jun 23, 2023
55d892a
Merge branch 'main' of github.com:zeeshan-haidar/human-essentials int…
zeeshan-haidar Jun 26, 2023
17cc4de
distribution stimulus controller added for shipping cost
zeeshan-haidar Jun 27, 2023
bbc1133
renamed distribution controller to destribution-delivery
zeeshan-haidar Jun 27, 2023
5fb7597
PR requested changes applied
zeeshan-haidar Jun 27, 2023
d584002
PR requested changes applied
zeeshan-haidar Jun 27, 2023
5613746
extra empty line removed
zeeshan-haidar Jun 27, 2023
8536f17
removed typo error
zeeshan-haidar Jun 27, 2023
e19f8cd
PR requested change applied
zeeshan-haidar Jun 27, 2023
2f6305a
PR requested change applied
zeeshan-haidar Jun 27, 2023
4f5a04d
wrapped shipping cost with it's own div
zeeshan-haidar Jun 27, 2023
ca0df90
code refactored with PR requested changes
zeeshan-haidar Jun 30, 2023
28d152f
Merge branch 'main' of github.com:zeeshan-haidar/human-essentials int…
zeeshan-haidar Jun 30, 2023
7182d7c
rubocop linting fixed
zeeshan-haidar Jun 30, 2023
1f140f0
Merge branch 'main' of github.com:zeeshan-haidar/human-essentials int…
zeeshan-haidar Jul 1, 2023
e972029
code refactored
zeeshan-haidar Jul 1, 2023
ae7bce2
Merge branch 'main' of github.com:zeeshan-haidar/human-essentials int…
zeeshan-haidar Jul 3, 2023
df1410e
removed inventory enum from kit_allocation
zeeshan-haidar Jul 3, 2023
7bb7a4e
added kit_allocation_type enum
zeeshan-haidar Jul 3, 2023
e19f699
renamed invetory enum to kit_allocation_type
zeeshan-haidar Jul 3, 2023
6a14d6c
code refactored
zeeshan-haidar Jul 4, 2023
c298036
Merge branch '3656-add-shipped-to-delivery-method' of github.com:zees…
zeeshan-haidar Jul 4, 2023
b822b57
added itemizable module to base item class
zeeshan-haidar Jul 4, 2023
fc9ea26
rake task added to change itemizable_id for kits' line_items
zeeshan-haidar Jul 5, 2023
fe64cb6
migration added to change itemizable_id
zeeshan-haidar Jul 5, 2023
a357379
fixed line_item.item_id issue
zeeshan-haidar Jul 7, 2023
9bba2c3
Merge branch 'main' of github.com:zeeshan-haidar/human-essentials int…
zeeshan-haidar Jul 17, 2023
88c6eba
changed the view logic to fetch line_items form items instead of kits
zeeshan-haidar Jul 18, 2023
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
4 changes: 2 additions & 2 deletions app/controllers/kits_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class KitsController < ApplicationController
def index
@kits = current_organization.kits.includes(line_items: :item, inventory_items: :storage_location).class_filter(filter_params)
@items = Item.where(partner_key: "kit").includes(line_items: :item, inventory_items: :storage_location).class_filter(filter_params)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably should use a join here instead of checking partner_key.

unless params[:include_inactive_items]
@kits = @kits.active
@items = @items.active
end
@selected_filter_name = filter_params[:by_name]
end
Expand Down
1 change: 1 addition & 0 deletions app/models/base_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#

class BaseItem < ApplicationRecord
include Itemizable
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, the issue had some bad wording - this has to be added to the Item class, not BaseItem.

has_many :items, dependent: :destroy, inverse_of: :base_item, foreign_key: :partner_key, primary_key: :partner_key
has_many :barcode_items, as: :barcodeable, dependent: :destroy

Expand Down
10 changes: 10 additions & 0 deletions app/models/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ def inventory_item_at(storage_location_id)
inventory_items.find_by(storage_location_id: storage_location_id)
end

def line_items_quantities_by_name
results = {}
self.line_items.each do |li|
next if li.quantity.zero?

results[li.id] = { item_id: li.item.id, name: li.item.name, quantity: li.quantity }
end
results
end

private

def update_associated_kit_name
Expand Down
8 changes: 4 additions & 4 deletions app/views/kits/_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
</tr>
</thead>
<tbody>
<% @kits.each do |kit| %>
<% @items.each do |item| %>
<tr>
<td><%= kit.name %></td>
<td><%= item.name %></td>
<td>
<ul>
<% kit.line_items.quantities_by_name.map do |id, item_hash| %>
<% item.line_items_quantities_by_name.map do |id, item_hash| %>
<li><%= "#{item_hash[:quantity]} #{item_hash[:name]}" %></li>
<% end %>
</ul>
Expand All @@ -26,7 +26,7 @@
<td> Quantity </td>
</tr>
</thead>
<% kit.inventory_items.map do |inventory_item| %>
<% item.inventory_items.map do |inventory_item| %>
<% next if inventory_item.storage_location.discarded_at %>
<tr>
<td><%= inventory_item.storage_location.name %></td>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20230705105404_change_itemizable_id.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ChangeItemizableId < ActiveRecord::Migration[7.0]
def change
Rake::Task['change_itemizable_id'].invoke
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why was this split into a Rake task?

end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_06_16_055847) do
ActiveRecord::Schema[7.0].define(version: 2023_07_05_105404) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down
18 changes: 18 additions & 0 deletions lib/tasks/change_kit_line_items_itemizable_id.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
desc "change the itemizable_id for all kits' line items to kit.item.id"
task change_itemizable_id: :environment do
line_items = LineItem.where(itemizable_type: "Kit")
puts "Total line_items: #{line_items.count}"

line_items.each do |line_item|
puts "Processing line_item with id: #{line_item.id}"
item = line_item.itemizable.item

item_id = line_item.item_id
line_item.itemizable = item
line_item.item_id = item_id

line_item.save!
end

puts "Done..."
end
Loading