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



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

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



30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/group_orders_controller.rb', line 30

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 StandardError => e
    logger.error('Failed to update order: ' + e.message)
    redirect_to group_orders_url, alert: I18n.t('group_orders.create.error_general')
  end
end

#editObject



26
27
28
# File 'app/controllers/group_orders_controller.rb', line 26

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



20
21
22
23
24
# File 'app/controllers/group_orders_controller.rb', line 20

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



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

def show
  @order = @group_order.order
end

#updateObject



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

def update
  @group_order.attributes = params[:group_order]
  @group_order.updated_by = current_user
  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 StandardError => e
    logger.error('Failed to update order: ' + e.message)
    redirect_to group_orders_url, alert: I18n.t('group_orders.update.error_general')
  end
end