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

[Admin] Add stock_items/edit modal component #5543

Merged
merged 9 commits into from
Dec 12, 2023
Prev Previous commit
Next Next commit
Introduce stock movements column in stock items index
Co-Authored-By: Elia Schito <[email protected]>
  • Loading branch information
rainerdema and elia committed Dec 11, 2023
commit 5b159589d8e39f78ba096a23069bedae86009db3
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def columns
stock_location_column,
back_orderable_column,
count_on_hand_column,
stock_movements_column,
]
end

Expand Down Expand Up @@ -127,8 +128,29 @@ def variant_column
def stock_location_column
{
header: :stock_location,
data: ->(stock_item) do
link_to stock_item.stock_location.name, spree.admin_stock_location_stock_movements_path(stock_item.stock_location.id, q: { variant_sku_eq: stock_item.variant.sku })
data: ->(stock_item) { stock_item.stock_location.name },
}
end

# Cache the stock movement counts to avoid N+1 queries
def stock_movement_counts
@stock_movement_counts ||= Spree::StockMovement.where(stock_item_id: @page.records.ids).group(:stock_item_id).count
end

def stock_movements_column
{
header: :stock_movements,
data: -> do
count = stock_movement_counts[_1.id] || 0

link_to(
"#{count} #{Spree::StockMovement.model_name.human(count: count).downcase}",
spree.admin_stock_location_stock_movements_path(
_1.stock_location.id,
q: { variant_sku_eq: _1.variant.sku },
),
class: 'body-link'
)
end
}
end
Expand Down