diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb
index 7c8bba423e..1a837ba719 100644
--- a/app/controllers/items_controller.rb
+++ b/app/controllers/items_controller.rb
@@ -11,7 +11,7 @@ def index
@items = @items.active unless params[:include_inactive_items]
@item_categories = current_organization.item_categories.includes(:items).order('name ASC')
- @kits = current_organization.kits.includes(item: {line_items: :item})
+ @kits = current_organization.kits.includes(kit_item: {line_items: :item})
@storages = current_organization.storage_locations.active.order(id: :asc)
@include_inactive_items = params[:include_inactive_items]
diff --git a/app/controllers/kits_controller.rb b/app/controllers/kits_controller.rb
index d1d43918b0..1e3d81eed5 100644
--- a/app/controllers/kits_controller.rb
+++ b/app/controllers/kits_controller.rb
@@ -4,7 +4,7 @@ def show
end
def index
- @kits = current_organization.kits.includes(item: {line_items: :item}).class_filter(filter_params)
+ @kits = current_organization.kits.includes(kit_item: {line_items: :item}).class_filter(filter_params)
@inventory = View::Inventory.new(current_organization.id)
unless params[:include_inactive_items]
@kits = @kits.active
@@ -16,8 +16,8 @@ def new
load_form_collections
@kit = current_organization.kits.new
- @kit.item = current_organization.items.new
- @kit.item.line_items.build
+ @kit.kit_item = current_organization.items.new
+ @kit.kit_item.line_items.build
end
def create
@@ -36,8 +36,8 @@ def create
kit_only_params = kit_params.except(:line_items_attributes)
@kit = Kit.new(kit_only_params)
load_form_collections
- @kit.item ||= current_organization.items.new(kit_params.slice(:line_items_attributes))
- @kit.item.line_items.build if @kit.item.line_items.empty?
+ @kit.kit_item ||= current_organization.items.new(kit_params.slice(:line_items_attributes))
+ @kit.kit_item.line_items.build if @kit.kit_item.line_items.empty?
render :new
end
diff --git a/app/events/kit_allocate_event.rb b/app/events/kit_allocate_event.rb
index a71a11aeb7..46160a83a0 100644
--- a/app/events/kit_allocate_event.rb
+++ b/app/events/kit_allocate_event.rb
@@ -1,6 +1,6 @@
class KitAllocateEvent < Event
def self.event_line_items(kit, storage_location, quantity)
- items = kit.item.line_items.map do |item|
+ items = kit.kit_item.line_items.map do |item|
EventTypes::EventLineItem.new(
quantity: item.quantity * quantity,
item_id: item.item_id,
@@ -11,8 +11,8 @@ def self.event_line_items(kit, storage_location, quantity)
end
items.push(EventTypes::EventLineItem.new(
quantity: quantity,
- item_id: kit.item.id,
- item_value_in_cents: kit.item.value_in_cents,
+ item_id: kit.kit_item.id,
+ item_value_in_cents: kit.kit_item.value_in_cents,
to_storage_location: storage_location,
from_storage_location: nil
))
diff --git a/app/events/kit_deallocate_event.rb b/app/events/kit_deallocate_event.rb
index 5ddc7366a4..26a41a387d 100644
--- a/app/events/kit_deallocate_event.rb
+++ b/app/events/kit_deallocate_event.rb
@@ -1,6 +1,6 @@
class KitDeallocateEvent < Event
def self.event_line_items(kit, storage_location, quantity)
- items = kit.item.line_items.map do |item|
+ items = kit.kit_item.line_items.map do |item|
EventTypes::EventLineItem.new(
quantity: item.quantity * quantity,
item_id: item.item_id,
@@ -11,8 +11,8 @@ def self.event_line_items(kit, storage_location, quantity)
end
items.push(EventTypes::EventLineItem.new(
quantity: quantity,
- item_id: kit.item.id,
- item_value_in_cents: kit.item.value_in_cents,
+ item_id: kit.kit_item.id,
+ item_value_in_cents: kit.kit_item.value_in_cents,
from_storage_location: storage_location,
to_storage_location: nil
))
diff --git a/app/models/concrete_item.rb b/app/models/concrete_item.rb
new file mode 100644
index 0000000000..7a56d8f80f
--- /dev/null
+++ b/app/models/concrete_item.rb
@@ -0,0 +1,26 @@
+# == Schema Information
+#
+# Table name: items
+#
+# id :integer not null, primary key
+# active :boolean default(TRUE)
+# additional_info :text
+# barcode_count :integer
+# distribution_quantity :integer
+# name :string
+# on_hand_minimum_quantity :integer default(0), not null
+# on_hand_recommended_quantity :integer
+# package_size :integer
+# partner_key :string
+# reporting_category :string
+# type :string default("ConcreteItem"), not null
+# value_in_cents :integer default(0)
+# visible_to_partners :boolean default(TRUE), not null
+# created_at :datetime not null
+# updated_at :datetime not null
+# item_category_id :integer
+# kit_id :integer
+# organization_id :integer
+#
+class ConcreteItem < Item
+end
diff --git a/app/models/item.rb b/app/models/item.rb
index 12adb66f18..e9776300a6 100644
--- a/app/models/item.rb
+++ b/app/models/item.rb
@@ -13,6 +13,7 @@
# package_size :integer
# partner_key :string
# reporting_category :string
+# type :string default("ConcreteItem"), not null
# value_in_cents :integer default(0)
# visible_to_partners :boolean default(TRUE), not null
# created_at :datetime not null
@@ -105,11 +106,11 @@ def in_request?
def is_in_kit?(kits = nil)
if kits
- kits.any? { |k| k.item.line_items.map(&:item_id).include?(id) }
+ kits.any? { |k| k.kit_item.line_items.map(&:item_id).include?(id) }
else
organization.kits
.active
- .joins(item: :line_items)
+ .joins(kit_item: :line_items)
.where(line_items: { item_id: id}).any?
end
end
diff --git a/app/models/kit.rb b/app/models/kit.rb
index 4f571b9e85..bc014c5d0a 100644
--- a/app/models/kit.rb
+++ b/app/models/kit.rb
@@ -17,7 +17,7 @@ class Kit < ApplicationRecord
include Valuable
belongs_to :organization
- has_one :item, dependent: :restrict_with_exception
+ has_one :kit_item, dependent: :restrict_with_exception
scope :active, -> { where(active: true) }
scope :alphabetized, -> { order(:name) }
@@ -30,23 +30,23 @@ class Kit < ApplicationRecord
# @return [Boolean]
def can_deactivate?(inventory = nil)
inventory ||= View::Inventory.new(organization_id)
- inventory.quantity_for(item_id: item.id).zero?
+ inventory.quantity_for(item_id: kit_item.id).zero?
end
def deactivate
update!(active: false)
- item.update!(active: false)
+ kit_item.update!(active: false)
end
# Kits can't reactivate if they have any inactive items, because now whenever they are allocated
# or deallocated, we are changing inventory for inactive items (which we don't allow).
# @return [Boolean]
def can_reactivate?
- item.line_items.joins(:item).where(items: { active: false }).none?
+ kit_item.line_items.joins(:kit_item).where(items: { active: false }).none?
end
def reactivate
update!(active: true)
- item.update!(active: true)
+ kit_item.update!(active: true)
end
end
diff --git a/app/models/kit_item.rb b/app/models/kit_item.rb
new file mode 100644
index 0000000000..9081efd30e
--- /dev/null
+++ b/app/models/kit_item.rb
@@ -0,0 +1,29 @@
+# == Schema Information
+#
+# Table name: items
+#
+# id :integer not null, primary key
+# active :boolean default(TRUE)
+# additional_info :text
+# barcode_count :integer
+# distribution_quantity :integer
+# name :string
+# on_hand_minimum_quantity :integer default(0), not null
+# on_hand_recommended_quantity :integer
+# package_size :integer
+# partner_key :string
+# reporting_category :string
+# type :string default("ConcreteItem"), not null
+# value_in_cents :integer default(0)
+# visible_to_partners :boolean default(TRUE), not null
+# created_at :datetime not null
+# updated_at :datetime not null
+# item_category_id :integer
+# kit_id :integer
+# organization_id :integer
+#
+class KitItem < Item
+ # for now. Technically not optional, but since we will be changing this to be standalone (no kit),
+ # there isn't really a reason to enforce this at the moment.
+ belongs_to :kit, optional: true
+end
diff --git a/app/services/kit_create_service.rb b/app/services/kit_create_service.rb
index 34fecebbcd..5be5670788 100644
--- a/app/services/kit_create_service.rb
+++ b/app/services/kit_create_service.rb
@@ -38,6 +38,7 @@ def call
item_creation = ItemCreateService.new(
organization_id: organization.id,
item_params: {
+ type: 'KitItem',
line_items_attributes: line_items,
name: kit.name,
partner_key: item_housing_a_kit_base_item.partner_key,
diff --git a/app/services/reports/adult_incontinence_report_service.rb b/app/services/reports/adult_incontinence_report_service.rb
index bb3f4efaae..ef77136aae 100644
--- a/app/services/reports/adult_incontinence_report_service.rb
+++ b/app/services/reports/adult_incontinence_report_service.rb
@@ -144,7 +144,7 @@ def distributed_kits_for_year
def total_distributed_kits_containing_adult_incontinence_items_per_month
kits = Kit.where(id: distributed_kits_for_year).select do |kit|
- kit.item.items.adult_incontinence.exists?
+ kit.kit_item.items.adult_incontinence.exists?
end
total_assisted_adults = kits.sum do |kit|
diff --git a/app/services/reports/children_served_report_service.rb b/app/services/reports/children_served_report_service.rb
index 386b8edb2a..f3f818d5af 100644
--- a/app/services/reports/children_served_report_service.rb
+++ b/app/services/reports/children_served_report_service.rb
@@ -52,7 +52,7 @@ def children_served_with_kits_containing_disposables
kits_subquery = organization
.distributions
.for_year(year)
- .joins(line_items: { item: { kit: { item: { line_items: :item} } }})
+ .joins(line_items: { item: { kit: { kit_item: { line_items: :item} } }})
.where("items_line_items.reporting_category = 'disposable_diapers'")
.select("DISTINCT ON (distributions.id, line_items.id, kits.id) line_items.quantity, items.distribution_quantity")
.to_sql
diff --git a/app/views/kits/_form.html.erb b/app/views/kits/_form.html.erb
index e5fe5ccac3..f4da7936f7 100644
--- a/app/views/kits/_form.html.erb
+++ b/app/views/kits/_form.html.erb
@@ -19,7 +19,7 @@
<%= f.input_field :value_in_dollars, class: "form-control", min: 0 %>
<% end %>
- <%= fields_for @kit.item do |ff| %>
+ <%= fields_for @kit.kit_item do |ff| %>