-
-
Notifications
You must be signed in to change notification settings - Fork 571
3652 #1: kits to items #5426
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
Open
dorner
wants to merge
10
commits into
main
Choose a base branch
from
3652-1-kits-to-items
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+215
−107
Open
3652 #1: kits to items #5426
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b7e1f07
#3652: Switch line_items from kits to items
dorner 84bd594
fix spec
dorner c43aea2
fixes
dorner 07a7008
moar fix
dorner 7a93395
fix
dorner 9264670
spec fixes
dorner 0c0f99c
Merge branch 'main' into 3652-1-kits-to-items
awwaiid 2e0da93
Merge branch 'main' into 3652-1-kits-to-items
awwaiid 93c9d0c
CR updates (thanks Claude for the spec fix)
dorner dd95b67
fixes
dorner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,3 +89,4 @@ out/ | |
|
|
||
| .vscode/ | ||
| .aider* | ||
| .claude | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## Project Overview | ||
|
|
||
| Human Essentials is a Ruby on Rails inventory management system for diaper banks and essentials banks. It's a Ruby for Good project serving 200+ non-profit organizations. The app manages donations, purchases, distributions, inventory, partners, and requests for essential items. | ||
|
|
||
| ## Common Commands | ||
|
|
||
| ### Development | ||
| ```bash | ||
| bin/setup # First-time setup (installs gems, creates DB, seeds) | ||
| bin/start # Starts Rails server (port 3000) + Delayed Job worker | ||
| ``` | ||
|
|
||
| ### Testing | ||
| ```bash | ||
| bundle exec rspec # Run full test suite | ||
| bundle exec rspec spec/models/item_spec.rb # Run a single test file | ||
| bundle exec rspec spec/models/item_spec.rb:42 # Run a single test at line | ||
| bundle exec rspec spec/models/ # Run a directory of tests | ||
| ``` | ||
|
|
||
| CI splits tests into two workflows: `rspec` (unit tests, excludes system/request specs) and `rspec-system` (system and request specs only, 6 parallel nodes). System tests use Capybara with Cuprite (headless Chrome). | ||
|
|
||
| ### Linting | ||
| ```bash | ||
| bundle exec rubocop # Ruby linter (Standard-based config) | ||
| bundle exec erb_lint --lint-all # ERB template linter | ||
| bundle exec brakeman # Security scanner | ||
| ``` | ||
|
|
||
| ### Database | ||
| ```bash | ||
| bundle exec rake db:migrate | ||
| bundle exec rake db:seed | ||
| bundle exec rake db:reset # Drop + create + migrate + seed | ||
| ``` | ||
|
|
||
| ## Architecture | ||
|
|
||
| ### Multi-Tenancy | ||
| Nearly all data is scoped to an `Organization`. Most models `belong_to :organization` and queries should always scope by organization context. The current user's organization is the primary tenant boundary. | ||
|
|
||
| ### Roles (Rolify) | ||
| Four roles defined in `Role`: `ORG_USER`, `ORG_ADMIN`, `SUPER_ADMIN`, `PARTNER`. Roles are polymorphic and scoped to a resource (usually an Organization). Authentication is via Devise. | ||
|
|
||
| ### Event Sourcing for Inventory | ||
| Inventory is **not** tracked via simple column updates. Instead, it uses an event sourcing pattern: | ||
|
|
||
| - **`Event`** (STI base model) stores all inventory-affecting actions as JSONB events | ||
| - Subclasses: `DonationEvent`, `DistributionEvent`, `PurchaseEvent`, `TransferEvent`, `AdjustmentEvent`, `AuditEvent`, `KitAllocateEvent`, `SnapshotEvent`, etc. | ||
| - **`InventoryAggregate`** replays events to compute current inventory state. It finds the most recent `SnapshotEvent` and replays subsequent events | ||
| - **`EventTypes::Inventory`** is the in-memory inventory representation built from events | ||
| - When creating/updating donations, distributions, purchases, transfers, or adjustments, the corresponding service creates an Event, and `Event#validate_inventory` replays all events to verify consistency | ||
|
|
||
| This means: to check inventory levels, use `InventoryAggregate.inventory_for(organization_id)`, not direct DB queries on quantity columns. | ||
|
|
||
| ### Service Objects | ||
| Business logic lives in service classes (`app/services/`), not controllers. Pattern: `{Model}{Action}Service` (e.g., `DistributionCreateService`, `DonationDestroyService`). Controllers are thin and delegate to services. | ||
|
|
||
| ### Key Models | ||
| - **Item**: Individual item types (diapers, wipes, etc.) belonging to an Organization. Maps to a `BaseItem` (system-wide template) via `partner_key`. | ||
| - **Kit**: A bundle of items. Kits contain line items referencing Items. | ||
| - **StorageLocation**: Where inventory is physically stored. Inventory quantities are per storage location. | ||
| - **Distribution**: Items sent to a Partner. **Donation/Purchase**: Items coming in. **Transfer**: Items between storage locations. **Adjustment**: Manual inventory corrections. | ||
| - **Partner**: Organizations that receive distributions. Partners have their own portal (`/partners/*` routes) and users. | ||
| - **Request**: Partner requests for items, which can become Distributions. | ||
|
|
||
| ### Routes Structure | ||
| - `/` - Bank user dashboard and resources (distributions, donations, etc.) | ||
| - `/partners/*` - Partner-facing portal (separate namespace) | ||
| - `/admin/*` - Super admin management | ||
| - `/reports/*` - Reporting endpoints | ||
|
|
||
| ### Query Objects | ||
| Complex queries are extracted into `app/queries/` (e.g., `ItemsInQuery`, `LowInventoryQuery`). | ||
|
|
||
| ### Frontend | ||
| Bootstrap 5.2, Turbo Rails, Stimulus.js, ImportMap (no Webpack/bundler). JavaScript controllers live in `app/javascript/`. | ||
|
|
||
| ### Background Jobs | ||
| Delayed Job for async processing (emails, etc.). Clockwork (`clock.rb`) for scheduled tasks (caching historical data, reminder emails, DB backups). | ||
|
|
||
| ### Feature Flags | ||
| Flipper is available for feature flags, accessible at `/flipper` (auth required). | ||
|
|
||
| ## Testing Conventions | ||
|
|
||
| - RSpec with FactoryBot. Factories are in `spec/factories/`. | ||
| - **Setting up inventory in tests**: Use `TestInventory.create_inventory(organization, { storage_location_id => [[item_id, quantity], ...] })` from `spec/inventory.rb`. There's also a `setup_storage_location` helper in `spec/support/inventory_assistant.rb`. | ||
| - System tests use Capybara with Cuprite driver. Failed screenshots go to `tmp/screenshots/` and `tmp/capybara/`. | ||
| - Models use `has_paper_trail` for audit trails and `Discard` for soft deletes (not `destroy`). | ||
| - The `Filterable` concern provides `class_filter` for scope-based filtering on index actions. | ||
|
|
||
| ## Dev Credentials | ||
|
|
||
| All passwords are `password!`. Key accounts: `superadmin@example.com`, `org_admin1@example.com`, `user_1@example.com`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
app/services/reports/adult_incontinence_report_service.rb def distributed_adult_incontinence_items_from_kits needs SQL updated like this