-
-
Notifications
You must be signed in to change notification settings - Fork 585
Replace Kits with KitItems #5597
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
b24566a
d92bcc6
3bb518d
ad68c01
fc8da66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ def show | |
| end | ||
|
|
||
| def index | ||
| @kits = current_organization.kits.includes(kit_item: {line_items: :item}).class_filter(filter_params) | ||
| @kits = current_organization.kit_items.includes(line_items: :item).class_filter(filter_params) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note to self: consider renaming kit_items to kits, and therefore these diffs will look different and the semantics are lifted to the rename
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main problem is having to rewrite the Claude estimates we'd save about 30 lines of churn by doing it all at once. I'm not really sure which way I'm leaning right now.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @awwaiid I put in the commit to rename. IMO things look much smoother now. |
||
| @inventory = View::Inventory.new(current_organization.id) | ||
| unless params[:include_inactive_items] | ||
| @kits = @kits.active | ||
|
|
@@ -15,9 +15,8 @@ def index | |
| def new | ||
| load_form_collections | ||
|
|
||
| @kit = current_organization.kits.new | ||
| @kit.kit_item = KitItem.new(organization: current_organization) | ||
| @kit.kit_item.line_items.build | ||
| @kit = current_organization.kit_items.new | ||
| @kit.line_items.build | ||
| end | ||
|
|
||
| def create | ||
|
|
@@ -32,26 +31,22 @@ def create | |
| .map { |error| formatted_error_message(error) } | ||
| .join(", ") | ||
|
|
||
| # Extract kit and item params separately since line_items belong to Item, not Kit | ||
| kit_only_params = kit_params.except(:line_items_attributes) | ||
| @kit = Kit.new(kit_only_params) | ||
| load_form_collections | ||
| @kit.kit_item ||= KitItem.new(organization: current_organization, | ||
| **kit_params.slice(:line_items_attributes)) | ||
| @kit.kit_item.line_items.build if @kit.kit_item.line_items.empty? | ||
| @kit = current_organization.kit_items.new(kit_params) | ||
| @kit.line_items.build if @kit.line_items.empty? | ||
|
|
||
| render :new | ||
| end | ||
| end | ||
|
|
||
| def deactivate | ||
| @kit = current_organization.kits.find(params[:id]) | ||
| @kit.deactivate | ||
| @kit = current_organization.kit_items.find(params[:id]) | ||
| @kit.deactivate! | ||
| redirect_back_or_to(dashboard_path, notice: "Kit has been deactivated!") | ||
| end | ||
|
|
||
| def reactivate | ||
| @kit = current_organization.kits.find(params[:id]) | ||
| @kit = current_organization.kit_items.find(params[:id]) | ||
| if @kit.can_reactivate? | ||
| @kit.reactivate | ||
| redirect_back_or_to(dashboard_path, notice: "Kit has been reactivated!") | ||
|
|
@@ -61,15 +56,15 @@ def reactivate | |
| end | ||
|
|
||
| def allocations | ||
| @kit = current_organization.kits.find(params[:id]) | ||
| @kit = current_organization.kit_items.find(params[:id]) | ||
| @storage_locations = current_organization.storage_locations.active | ||
| @inventory = View::Inventory.new(current_organization.id) | ||
|
|
||
| load_form_collections | ||
| end | ||
|
|
||
| def allocate | ||
| @kit = current_organization.kits.find(params[:id]) | ||
| @kit = current_organization.kit_items.find(params[:id]) | ||
| @storage_location = current_organization.storage_locations.active.find(kit_adjustment_params[:storage_location_id]) | ||
| @change_by = kit_adjustment_params[:change_by].to_i | ||
| begin | ||
|
|
@@ -92,14 +87,12 @@ def load_form_collections | |
| end | ||
|
|
||
| def kit_params | ||
| kit_params = params.require(:kit).permit( | ||
| params.require(:kit_item).permit( | ||
| :name, | ||
| :visible_to_partners, | ||
| :value_in_dollars | ||
| ) | ||
| item_params = params.require(:kit_item) | ||
| .permit(line_items_attributes: [:item_id, :quantity, :_destroy]) | ||
| kit_params.to_h.merge(item_params.to_h) | ||
| :value_in_dollars, | ||
| line_items_attributes: [:item_id, :quantity, :_destroy] | ||
| ).to_h | ||
| end | ||
|
|
||
| def kit_adjustment_params | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| module EventsHelper | ||
| # KitItems (kit allocate/deallocate events) don't have their own route, so polymorphic | ||
| # routing would look for a non-existent kit_item_path. Link them to the kits page instead. | ||
| def eventable_path(eventable) | ||
| eventable.is_a?(KitItem) ? kit_path(eventable) : eventable | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,4 +23,5 @@ | |
| # organization_id :integer | ||
| # | ||
| class ConcreteItem < Item | ||
| validates :reporting_category, presence: true | ||
| end | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add current_organization.concrete_items