Module: SpreeCmCommissioner::Admin::InventoryLocksHelper
- Defined in:
- app/helpers/spree_cm_commissioner/admin/inventory_locks_helper.rb
Instance Method Summary collapse
-
#availability_percentage_badge_class(percentage) ⇒ Object
High/medium/low as risk of running out of public stock, not as a grade — a bare number in a dense table doesn't say whether 22% is fine or a problem, so the color carries that instead.
-
#available_capacity_percentage(inventory_item) ⇒ Object
Share of this date's capacity still on public sale.
Instance Method Details
#availability_percentage_badge_class(percentage) ⇒ Object
High/medium/low as risk of running out of public stock, not as a grade — a bare number in a dense table doesn't say whether 22% is fine or a problem, so the color carries that instead. Reuses the badge-success/warning/danger classes already styled for this admin (see gems/spree_backend's _badges.scss) rather than introducing new color tokens.
25 26 27 28 29 30 |
# File 'app/helpers/spree_cm_commissioner/admin/inventory_locks_helper.rb', line 25 def availability_percentage_badge_class(percentage) return 'badge-danger' if percentage <= 20 return 'badge-warning' if percentage <= 50 'badge-success' end |
#available_capacity_percentage(inventory_item) ⇒ Object
Share of this date's capacity still on public sale.
max_capacity is the right denominator because MoveToLocked only ever moves units BETWEEN quantity_available and quantity_locked — it never touches max_capacity — so this figure falls by exactly what an operator withholds.
nil when there is nothing to divide by, so the caller renders a dash instead of a 0% that would read as "sold out" on a date that simply has no stock configured.
12 13 14 15 16 17 18 19 |
# File 'app/helpers/spree_cm_commissioner/admin/inventory_locks_helper.rb', line 12 def available_capacity_percentage(inventory_item) return nil if inventory_item.nil? capacity = inventory_item.max_capacity.to_i return nil if capacity.zero? (inventory_item.quantity_available.to_f / capacity * 100).round end |