mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Inject shops and order cycles
This commit is contained in:
@@ -10,6 +10,8 @@ Spree::Admin::OrdersController.class_eval do
|
||||
# in an auth failure as the @order object is nil for collection actions
|
||||
before_filter :check_authorization, except: [:bulk_management, :managed]
|
||||
|
||||
before_filter :load_distribution_choices, only: :new
|
||||
|
||||
# After updating an order, the fees should be updated as well
|
||||
# Currently, adding or deleting line items does not trigger updating the
|
||||
# fees! This is a quick fix for that.
|
||||
@@ -19,6 +21,7 @@ Spree::Admin::OrdersController.class_eval do
|
||||
|
||||
before_filter :require_distributor_abn, only: :invoice
|
||||
|
||||
|
||||
respond_to :html, :json
|
||||
|
||||
# Mostly the original Spree method, tweaked to allow us to ransack with completed_at in a sane way
|
||||
@@ -112,4 +115,9 @@ Spree::Admin::OrdersController.class_eval do
|
||||
respond_with(@order) { |format| format.html { redirect_to edit_admin_order_path(@order) } }
|
||||
end
|
||||
end
|
||||
|
||||
def load_distribution_choices
|
||||
@shops = Enterprise.is_distributor.managed_by(spree_current_user)
|
||||
@order_cycles = OrderCycle.managed_by(spree_current_user)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,8 +25,8 @@ module Admin
|
||||
admin_inject_json_ams_array "admin.shipping_methods", "shippingMethods", @shipping_methods, Api::Admin::IdNameSerializer
|
||||
end
|
||||
|
||||
def admin_inject_shops
|
||||
admin_inject_json_ams_array "admin.customers", "shops", @shops, Api::Admin::IdNameSerializer
|
||||
def admin_inject_shops(ngModule='admin.customers')
|
||||
admin_inject_json_ams_array ngModule, "shops", @shops, Api::Admin::IdNameSerializer
|
||||
end
|
||||
|
||||
def admin_inject_hubs
|
||||
@@ -74,6 +74,10 @@ module Admin
|
||||
render partial: "admin/json/injection_ams", locals: {ngModule: 'admin.orderCycles', name: 'ocInstance', json: "{coordinator_id: '#{@order_cycle.coordinator.id}'}"}
|
||||
end
|
||||
|
||||
def admin_inject_order_cycles
|
||||
admin_inject_json_ams_array "admin.orders", "orderCycles", @order_cycles, Api::Admin::IdNameSerializer, current_user: spree_current_user
|
||||
end
|
||||
|
||||
def admin_inject_spree_api_key
|
||||
render partial: "admin/json/injection_ams", locals: {ngModule: 'ofn.admin', name: 'SpreeApiKey', json: "'#{@spree_api_key.to_s}'"}
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
require 'open_food_network/order_cycle_permissions'
|
||||
|
||||
class Api::Admin::OrderCycleSerializer < ActiveModel::Serializer
|
||||
attributes :id, :name, :orders_open_at, :orders_close_at, :coordinator_id, :exchanges
|
||||
attributes :editable_variants_for_incoming_exchanges, :editable_variants_for_outgoing_exchanges
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
- content_for :page_actions do
|
||||
%li= button_link_to t(:back_to_orders_list), spree.admin_orders_path, :icon => 'icon-arrow-left'
|
||||
|
||||
= admin_inject_shops 'admin.orders'
|
||||
= admin_inject_order_cycles
|
||||
|
||||
= render 'spree/admin/shared/order_tabs', :current => 'Order Details'
|
||||
|
||||
= csrf_meta_tags
|
||||
|
||||
Reference in New Issue
Block a user