allow to edit GroupOrderArticle result from orders screen

Conflicts:
	app/assets/javascripts/application.js
This commit is contained in:
wvengen 2014-01-23 16:17:16 +01:00
parent f9d2c20aaa
commit 60826ceedc
34 changed files with 393 additions and 220 deletions

View file

@ -1,6 +1,7 @@
class Finance::GroupOrderArticlesController < ApplicationController
class GroupOrderArticlesController < ApplicationController
before_filter :authenticate_finance
before_filter :find_group_order_article, except: [:new, :create]
layout false # We only use this controller to server js snippets, no need for layout rendering
@ -10,6 +11,8 @@ class Finance::GroupOrderArticlesController < ApplicationController
end
def create
# XXX when ordergroup_id appears before order_article_id in the parameters, you
# can get `NoMethodError - undefined method 'order_id' for nil:NilClass`
@group_order_article = GroupOrderArticle.new(params[:group_order_article])
@order_article = @group_order_article.order_article
@ -21,59 +24,38 @@ class Finance::GroupOrderArticlesController < ApplicationController
@group_order_article = goa
update_summaries(@group_order_article)
render :update
render :create
elsif @group_order_article.save
update_summaries(@group_order_article)
render :update
render :create
else # Validation failed, show form
render :new
end
end
def edit
@group_order_article = GroupOrderArticle.find(params[:id])
@order_article = @group_order_article.order_article
end
def update
@group_order_article = GroupOrderArticle.find(params[:id])
@order_article = @group_order_article.order_article
if @group_order_article.update_attributes(params[:group_order_article])
update_summaries(@group_order_article)
if params[:delta]
@group_order_article.update_attribute :result, [@group_order_article.result + params[:delta].to_f, 0].max
else
render :edit
end
end
def update_result
group_order_article = GroupOrderArticle.find(params[:id])
@order_article = group_order_article.order_article
if params[:modifier] == '-'
group_order_article.update_attribute :result, group_order_article.result - 1
elsif params[:modifier] == '+'
group_order_article.update_attribute :result, group_order_article.result + 1
@group_order_article.update_attributes(params[:group_order_article])
end
update_summaries(group_order_article)
update_summaries(@group_order_article)
render :update
end
def destroy
group_order_article = GroupOrderArticle.find(params[:id])
# only destroy if quantity and tolerance was zero already, so that we don't
# lose what the user ordered, if any
if group_order_article.quantity > 0 or group_order_article.tolerance >0
group_order_article.update_attribute(:result, 0)
if @group_order_article.quantity > 0 or @group_order_article.tolerance >0
@group_order_article.update_attribute(:result, 0)
else
group_order_article.destroy
@group_order_article.destroy
end
update_summaries(group_order_article)
@order_article = group_order_article.order_article
update_summaries(@group_order_article)
render :update
end
@ -86,4 +68,8 @@ class Finance::GroupOrderArticlesController < ApplicationController
# Update units_to_order of order_article
group_order_article.order_article.update_results! if group_order_article.order_article.article.is_a?(StockArticle)
end
def find_group_order_article
@group_order_article = GroupOrderArticle.find(params[:id])
end
end

View file

@ -13,10 +13,10 @@ class OrdersController < ApplicationController
@per_page = 15
if params['sort']
sort = case params['sort']
when "supplier" then "suppliers.name, ends DESC"
when "ends" then "ends DESC"
when "supplier_reverse" then "suppliers.name DESC"
when "ends_reverse" then "ends"
when "supplier" then "suppliers.name, ends DESC"
when "ends" then "ends DESC"
when "supplier_reverse" then "suppliers.name DESC"
when "ends_reverse" then "ends"
end
else
sort = "ends DESC"
@ -30,9 +30,9 @@ class OrdersController < ApplicationController
@order= Order.find(params[:id])
@view = (params[:view] or 'default').gsub(/[^-_a-zA-Z0-9]/, '')
@partial = case @view
when 'default' then 'articles'
when 'groups'then 'shared/articles_by_groups'
when 'articles'then 'shared/articles_by_articles'
when 'default' then 'articles'
when 'groups' then 'shared/articles_by/groups'
when 'articles' then 'shared/articles_by/articles'
else 'articles'
end
@ -43,10 +43,10 @@ class OrdersController < ApplicationController
end
format.pdf do
pdf = case params[:document]
when 'groups' then OrderByGroups.new(@order)
when 'groups' then OrderByGroups.new(@order)
when 'articles' then OrderByArticles.new(@order)
when 'fax' then OrderFax.new(@order)
when 'matrix' then OrderMatrix.new(@order)
when 'fax' then OrderFax.new(@order)
when 'matrix' then OrderMatrix.new(@order)
end
send_data pdf.to_pdf, filename: pdf.filename, type: 'application/pdf'
end
@ -120,13 +120,11 @@ class OrdersController < ApplicationController
def receive_on_order_article_create # See publish/subscribe design pattern in /doc.
@order_article = OrderArticle.find(params[:order_article_id])
render :layout => false
end
def receive_on_order_article_update # See publish/subscribe design pattern in /doc.
@order_article = OrderArticle.find(params[:order_article_id])
render :layout => false
end