Class: OrderArticlesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

current

Methods included from PathHelper

#finance_group_transactions_path

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/order_articles_controller.rb', line 17

def create
  # The article may be ordered with zero units - in that case do not complain.
  #   If order_article is ordered and a new order_article is created, an error message will be
  #   given mentioning that the article already exists, which is desired.
  @order_article = @order.order_articles.where(article_version_id: params[:order_article][:article_version_id]).first
  @order_article = @order.order_articles.build(params[:order_article]) unless @order_article && @order_article.units_to_order == 0
  @order_article.save!
rescue StandardError
  render action: :new
end

#destroyObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/order_articles_controller.rb', line 36

def destroy
  @order_article = OrderArticle.find(params[:id])
  # only destroy if there are no associated GroupOrders; if we would, the requested
  # quantity and tolerance would be gone. Instead of destroying, we set all result
  # quantities to zero.
  if @order_article.group_order_articles.count == 0
    @order_article.destroy
  else
    @order_article.group_order_articles.each { |goa| goa.update_attribute(:result, 0) }
    @order_article.update_results!
  end
end

#editObject



15
# File 'app/controllers/order_articles_controller.rb', line 15

def edit; end

#newObject



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

def new
  @order_article = @order.order_articles.build(params[:order_article])
end

#updateObject



28
29
30
31
32
33
34
# File 'app/controllers/order_articles_controller.rb', line 28

def update
  version_params = params.require(:article_version).permit(:id, :unit, :supplier_order_unit, :minimum_order_quantity,
                                                           :billing_unit, :group_order_granularity, :group_order_unit, :price, :price_unit, :tax, :deposit, article_unit_ratios_attributes: %i[id sort quantity unit _destroy])
  @order_article.update_handling_versioning!(params[:order_article], version_params)
rescue StandardError
  render action: :edit
end