From 0adce9d54c6bf4360c3d574f2a1fca208722c65d Mon Sep 17 00:00:00 2001 From: sandoz Date: Sun, 2 Aug 2009 11:00:57 +0200 Subject: [PATCH 1/2] First try making tolerance not costly. A new configuration setting was introduced: tolerance_is_costly If set to false, article tolerance values do not count for total article price as long as the order is not finished. This reduces the negative effect on using tolerance for the user. --- app/models/group_order.rb | 11 ++++++++--- app/views/ordering/my_order_result.haml | 5 ++++- app/views/ordering/order.rhtml | 20 ++++++++++++++++---- public/javascripts/ordering.js | 11 ++++++++++- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/app/models/group_order.rb b/app/models/group_order.rb index 1a730b88..788c1656 100644 --- a/app/models/group_order.rb +++ b/app/models/group_order.rb @@ -29,13 +29,18 @@ class GroupOrder < ActiveRecord::Base named_scope :finished, lambda { {:conditions => ["order_id IN (?)", Order.finished_not_closed.collect(&:id)]} } # Updates the "price" attribute. - # This will be the maximum value of an open order or - # the value depending of the article results. + # Until the order is finished this will be the maximum price or + # the minimum price depending on configuration. When the order is finished it + # will be the value depending of the article results. def update_price! total = 0 for article in group_order_articles.find(:all, :include => :order_article) unless order.finished? - total += article.order_article.article.fc_price * (article.quantity + article.tolerance) + if Foodsoft.config[:tolerance_is_costly] + total += article.order_article.article.fc_price * (article.quantity + article.tolerance) + else + total += article.order_article.article.fc_price * article.quantity + end else total += article.order_article.price.fc_price * article.result end diff --git a/app/views/ordering/my_order_result.haml b/app/views/ordering/my_order_result.haml index ecd7a736..21d9dc14 100644 --- a/app/views/ordering/my_order_result.haml +++ b/app/views/ordering/my_order_result.haml @@ -78,7 +78,10 @@ - tolerance = goa.tolerance - result = goa.result - if @order.open? - - sub_total = oa.price.fc_price * (quantity + tolerance) + - if Foodsoft.config[:tolerance_is_costly] + - sub_total = oa.price.fc_price * (quantity + tolerance) + - else + - sub_total = oa.price.fc_price * quantity - else - sub_total = oa.price.fc_price * result - else diff --git a/app/views/ordering/order.rhtml b/app/views/ordering/order.rhtml index 654cf55f..6daf9a1e 100644 --- a/app/views/ordering/order.rhtml +++ b/app/views/ordering/order.rhtml @@ -32,9 +32,12 @@ <%- order_articles.each do |order_article| - article_total = @price[i] * (@tolerance[i] + @quantity[i]); + if Foodsoft.config[:tolerance_is_costly] + article_total = @price[i] * (@tolerance[i] + @quantity[i]) + else + article_total = @price[i] * @quantity[i] + end total += article_total - -%> @@ -107,13 +110,22 @@