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, create new order: distributor and order cycle are now mandatory on step 1 (aka the set_distribution step) #10712

9 changes: 6 additions & 3 deletions app/controllers/spree/admin/orders_controller.rb
Expand Up @@ -9,8 +9,8 @@ class OrdersController < Spree::Admin::BaseController
helper CheckoutHelper

before_action :load_order, only: [:edit, :update, :fire, :resend,
:invoice, :print]
before_action :load_distribution_choices, only: [:new, :edit, :update]
:invoice, :print, :set_distribution]
before_action :load_distribution_choices, only: [:new, :edit, :update, :set_distribution]

# Ensure that the distributor is set for an order when
before_action :ensure_distribution, only: :new
Expand All @@ -21,10 +21,13 @@ class OrdersController < Spree::Admin::BaseController
def new
@order = Order.create
@order.created_by = spree_current_user
@order.generate_order_number
@order.save
redirect_to spree.edit_admin_order_url(@order)
redirect_to spree.distribution_admin_order_path(@order)
end

def set_distribution; end

def edit
@order.shipments.map(&:refresh_rates)

Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/ability.rb
Expand Up @@ -274,7 +274,7 @@ def add_order_management_abilities(user)
# Enterprise User can access orders that are placed inside a OC they coordinate
order.order_cycle&.coordinated_by?(user)
end
can [:admin, :bulk_management, :managed], Spree::Order do
can [:admin, :bulk_management, :managed, :set_distribution], Spree::Order do
user.admin? || user.enterprises.any?(&:is_distributor)
end
can [:admin, :create, :show, :poll], :invoice
Expand Down
1 change: 1 addition & 0 deletions config/routes/spree.rb
Expand Up @@ -89,6 +89,7 @@
post :resend
get :invoice
get :print
get :distribution, to: 'orders#set_distribution'
mkllnk marked this conversation as resolved.
Show resolved Hide resolved
end

collection do
Expand Down