Class: GroupOrdersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/group_orders_controller.rb

Overview

Controller for all ordering-actions that are performed by a user who is member of an Ordergroup. Management actions that require the “orders” role are handled by the OrdersController.

Instance Method Summary collapse

Methods inherited from ApplicationController

current

Methods included from PathHelper

#finance_group_transactions_path

Instance Method Details

#archiveObject

Shows all Orders of the Ordergroup if selected, it shows all orders of the foodcoop


58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/group_orders_controller.rb', line 58

def archive
  # get only orders belonging to the ordergroup
  @closed_orders = Order.closed.page(params[:page]).per(10)
  @closed_orders_including_group_order = @closed_orders.ordergroup_group_orders_map(@ordergroup)
  @finished_not_closed_orders_including_group_order = Order.finished_not_closed.ordergroup_group_orders_map(@ordergroup)

  respond_to do |format|
    format.html # archive.html.haml
    format.js   # archive.js.erb
  end
end

#createObject


22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/group_orders_controller.rb', line 22

def create
  @group_order = GroupOrder.new(params[:group_order])
  begin
    @group_order.save_ordering!
    redirect_to group_order_url(@group_order), :notice => I18n.t('group_orders.create.notice')
  rescue ActiveRecord::StaleObjectError
    redirect_to group_orders_url, :alert => I18n.t('group_orders.create.error_stale')
  rescue => exception
    logger.error('Failed to update order: ' + exception.message)
    redirect_to group_orders_url, :alert => I18n.t('group_orders.create.error_general')
  end
end

#editObject


39
40
41
# File 'app/controllers/group_orders_controller.rb', line 39

def edit
  @ordering_data = @group_order.load_data
end

#indexObject

Index page.


11
12
13
14
# File 'app/controllers/group_orders_controller.rb', line 11

def index
  @closed_orders_including_group_order = Order.closed.limit(5).ordergroup_group_orders_map(@ordergroup)
  @finished_not_closed_orders_including_group_order = Order.finished_not_closed.ordergroup_group_orders_map(@ordergroup)
end

#newObject


16
17
18
19
20
# File 'app/controllers/group_orders_controller.rb', line 16

def new
  ordergroup = params[:stock_order] ? nil : @ordergroup
  @group_order = @order.group_orders.build(:ordergroup => ordergroup, :updated_by => current_user)
  @ordering_data = @group_order.load_data
end

#showObject


35
36
37
# File 'app/controllers/group_orders_controller.rb', line 35

def show
  @order= @group_order.order
end

#updateObject


43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/group_orders_controller.rb', line 43

def update
  @group_order.attributes = params[:group_order]
  begin
    @group_order.save_ordering!
    redirect_to group_order_url(@group_order), :notice => I18n.t('group_orders.update.notice')
  rescue ActiveRecord::StaleObjectError
    redirect_to group_orders_url, :alert => I18n.t('group_orders.update.error_stale')
  rescue => exception
    logger.error('Failed to update order: ' + exception.message)
    redirect_to group_orders_url, :alert => I18n.t('group_orders.update.error_general')
  end
end