From 3654ba7cf185d7662c4e5c8035b55b4de70cc636 Mon Sep 17 00:00:00 2001 From: sandoz Date: Sat, 21 Mar 2009 01:56:17 +0800 Subject: [PATCH] Added buttons to in/decrease group order article results. Signed-off-by: bennibu --- .../finance/balancing_controller.rb | 22 +++++++++++++++++++ app/models/group_order_article.rb | 1 + .../balancing/_group_order_articles.html.haml | 4 +++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/controllers/finance/balancing_controller.rb b/app/controllers/finance/balancing_controller.rb index 6ccde68b..570bce98 100644 --- a/app/controllers/finance/balancing_controller.rb +++ b/app/controllers/finance/balancing_controller.rb @@ -196,6 +196,28 @@ class Finance::BalancingController < ApplicationController end end + def update_group_order_article_result + goa = GroupOrderArticle.find(params[:id]) + + if params[:modifier] == '-' + goa.update_attributes({:result => goa.result - 1}) + elsif params[:modifier] == '+' + goa.update_attributes({:result => goa.result + 1}) + end + + render :update do |page| + goa.group_order.update_price! # Update the price attribute of new GroupOrder + goa.order_article.update_results! if goa.order_article.article.is_a?(StockArticle) # Update units_to_order of order_article + + page["order_article_#{goa.order_article.id}"].replace_html :partial => 'order_article', :locals => {:order_article => goa.order_article} + page["group_order_articles_#{goa.order_article.id}"].replace_html :partial => 'group_order_articles', + :locals => {:order_article => goa.order_article} + page["summary"].replace_html :partial => 'summary', :locals => {:order => goa.order_article.order} + page["order_profit"].visual_effect :highlight, :duration => 2 + end + + end + def destroy_group_order_article goa = GroupOrderArticle.find(params[:id]) goa.destroy diff --git a/app/models/group_order_article.rb b/app/models/group_order_article.rb index 3635b689..89d41407 100644 --- a/app/models/group_order_article.rb +++ b/app/models/group_order_article.rb @@ -24,6 +24,7 @@ class GroupOrderArticle < ActiveRecord::Base validates_presence_of :group_order_id, :order_article_id validates_inclusion_of :quantity, :in => 0..99 + validates_inclusion_of :result, :in => 0..99, :allow_nil => true validates_inclusion_of :tolerance, :in => 0..99 validates_uniqueness_of :order_article_id, :scope => :group_order_id # just once an article per group order diff --git a/app/views/finance/balancing/_group_order_articles.html.haml b/app/views/finance/balancing/_group_order_articles.html.haml index af3c283b..f6db6c8c 100644 --- a/app/views/finance/balancing/_group_order_articles.html.haml +++ b/app/views/finance/balancing/_group_order_articles.html.haml @@ -14,8 +14,10 @@ %td %td{:style=>"width:50%"} = group_order_article.group_order.ordergroup.name - %td{:id => "group_order_article_#{group_order_article.id}_quantity"} + %td{:id => "group_order_article_#{group_order_article.id}_quantity", :style => "white-space:nowrap"} = group_order_article.result + = button_to_remote( "+", :url => {:action => "update_group_order_article_result", :id => group_order_article, :modifier => '+'}, :html => {:style => "float:left"}, :success => "Element.hide('loader');", :before => "Element.show('loader');") + = button_to_remote( "-", :url => {:action => "update_group_order_article_result", :id => group_order_article, :modifier => '-'}, :success => "Element.hide('loader');", :before => "Element.show('loader');") %td.currency = number_to_currency(group_order_article.order_article.price.fc_price * group_order_article.result, :unit => "") %td.actions{:style=>"width:1em"}