Merge branch 'tolerance_not_costly'

This commit is contained in:
Benjamin Meichsner 2009-08-05 17:02:12 +02:00
commit f45509fc07
5 changed files with 51 additions and 9 deletions

View file

@ -29,13 +29,18 @@ class GroupOrder < ActiveRecord::Base
named_scope :finished, lambda { {:conditions => ["order_id IN (?)", Order.finished_not_closed.collect(&:id)]} } named_scope :finished, lambda { {:conditions => ["order_id IN (?)", Order.finished_not_closed.collect(&:id)]} }
# Updates the "price" attribute. # Updates the "price" attribute.
# This will be the maximum value of an open order or # Until the order is finished this will be the maximum price or
# the value depending of the article results. # the minimum price depending on configuration. When the order is finished it
# will be the value depending of the article results.
def update_price! def update_price!
total = 0 total = 0
for article in group_order_articles.find(:all, :include => :order_article) for article in group_order_articles.find(:all, :include => :order_article)
unless order.finished? unless order.finished?
if Foodsoft.config[:tolerance_is_costly]
total += article.order_article.article.fc_price * (article.quantity + article.tolerance) total += article.order_article.article.fc_price * (article.quantity + article.tolerance)
else
total += article.order_article.article.fc_price * article.quantity
end
else else
total += article.order_article.price.fc_price * article.result total += article.order_article.price.fc_price * article.result
end end

View file

@ -78,7 +78,10 @@
- tolerance = goa.tolerance - tolerance = goa.tolerance
- result = goa.result - result = goa.result
- if @order.open? - if @order.open?
- if Foodsoft.config[:tolerance_is_costly]
- sub_total = oa.price.fc_price * (quantity + tolerance) - sub_total = oa.price.fc_price * (quantity + tolerance)
- else
- sub_total = oa.price.fc_price * quantity
- else - else
- sub_total = oa.price.fc_price * result - sub_total = oa.price.fc_price * result
- else - else

View file

@ -32,9 +32,12 @@
</tr> </tr>
<%- <%-
order_articles.each do |order_article| 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 total += article_total
-%> -%>
<tr class="<%= cycle('even', 'odd', :name => 'articles') %>" valign="top"> <tr class="<%= cycle('even', 'odd', :name => 'articles') %>" valign="top">
<td class="name"> <td class="name">
@ -107,14 +110,23 @@
<script type="text/javascript"> <script type="text/javascript">
//<![CDATA[ //<![CDATA[
// preset data // preset data
<% for i in 0...@price.size -%> <% if Foodsoft.config[:tolerance_is_costly]
for i in 0...@price.size -%>
addData(<%= @price[i] %>, <%= @unit[i] %>, <%= @price[i] * (@tolerance[i] + @quantity[i])%>, <%= @others_quantity[i] %>, <%= @others_tolerance[i] %>, <%= @used_quantity[i] %>, 0); addData(<%= @price[i] %>, <%= @unit[i] %>, <%= @price[i] * (@tolerance[i] + @quantity[i])%>, <%= @others_quantity[i] %>, <%= @others_tolerance[i] %>, <%= @used_quantity[i] %>, 0);
<% end -%> <% end
else
for j in 0...@price.size -%>
addData(<%= @price[j] %>, <%= @unit[j] %>, <%= @price[j] * @quantity[j]%>, <%= @others_quantity[j] %>, <%= @others_tolerance[j] %>, <%= @used_quantity[j] %>, 0);
<% end
end%>
setGroupBalance(<%= @availableFunds %>); setGroupBalance(<%= @availableFunds %>);
// localization // localization
setDecimalSeparator(","); setDecimalSeparator(",");
// configuration
setToleranceBehaviour(<%= Foodsoft.config[:tolerance_is_costly] %>);
// initialize javascript // initialize javascript
updateBalance(); updateBalance();
//]]> //]]>

View file

@ -11,25 +11,37 @@ development: &defaults
country: Deutschland country: Deutschland
email: foodsoft@myfoodcoop.org email: foodsoft@myfoodcoop.org
phone: "030 323 23249" phone: "030 323 23249"
# base URL for this installation # base URL for this installation
base_url: http://foodsoft.fctest.de base_url: http://foodsoft.fctest.de
# Homepage # Homepage
homepage: http://www.fctest.de homepage: http://www.fctest.de
# foodsoft documentation URL # foodsoft documentation URL
help_url: http://foodsoft.fcschinke09.de/trac/wiki/FoodsoftDoku help_url: http://foodsoft.fcschinke09.de/trac/wiki/FoodsoftDoku
# price markup in percent # price markup in percent
price_markup: 2.0 price_markup: 2.0
# tolerance order option: If set to false, article tolerance values do not count
# for total article price as long as the order is not finished.
tolerance_is_costly: false
# email address to be used as sender # email address to be used as sender
email_sender: foodsoft@myfoodcoop.org email_sender: foodsoft@myfoodcoop.org
# If your foodcoop uses a mailing list instead of internal messaging system # If your foodcoop uses a mailing list instead of internal messaging system
#mailing_list: list@myfoodcoop.org #mailing_list: list@myfoodcoop.org
#mailing_list_subscribe: list-subscribe@myfoodcoop.org #mailing_list_subscribe: list-subscribe@myfoodcoop.org
# Config for the exception_notification plugin # Config for the exception_notification plugin
notification: notification:
error_recipients: error_recipients:
- admin@myfoodcoop.org - admin@myfoodcoop.org
sender_address: "\"FoodSoft Error\" <foodsoft@myfoodcoop.org>" sender_address: "\"FoodSoft Error\" <foodsoft@myfoodcoop.org>"
email_prefix: "[FoodSoft]" email_prefix: "[FoodSoft]"
# Access to sharedLists, the external article-database # Access to sharedLists, the external article-database
shared_lists: shared_lists:
adapter: mysql adapter: mysql
@ -39,6 +51,7 @@ development: &defaults
password: password:
encoding: utf8 encoding: utf8
socket: /opt/lampp/var/mysql/mysql.sock socket: /opt/lampp/var/mysql/mysql.sock
# auto-units-conversion # auto-units-conversion
# this is used for automatic article-synchronization to handle different units # this is used for automatic article-synchronization to handle different units
# e.g. when foodcoop-unit should be 500g and supplier-unit is 1kg # e.g. when foodcoop-unit should be 500g and supplier-unit is 1kg

View file

@ -8,6 +8,7 @@
var modified = false // indicates if anything has been clicked on this page var modified = false // indicates if anything has been clicked on this page
var groupBalance = 0; // available group money var groupBalance = 0; // available group money
var decimalSeparator = "."; // default decimal separator var decimalSeparator = "."; // default decimal separator
var toleranceIsCostly = true; // default tolerance behaviour
// Article data arrays: // Article data arrays:
var price = new Array(); var price = new Array();
@ -22,6 +23,10 @@ function setDecimalSeparator(character) {
decimalSeparator = character; decimalSeparator = character;
} }
function setToleranceBehaviour(value) {
toleranceIsCostly = value;
}
function setGroupBalance(amount) { function setGroupBalance(amount) {
groupBalance = amount; groupBalance = amount;
} }
@ -98,7 +103,11 @@ function update(item, quantity, tolerance) {
} }
// update total price // update total price
if(toleranceIsCostly == true) {
itemTotal[item] = price[item] * (Number(quantity) + Number(tolerance)); itemTotal[item] = price[item] * (Number(quantity) + Number(tolerance));
} else {
itemTotal[item] = price[item] * (Number(quantity));
}
$('price_' + item + '_display').update(asMoney(itemTotal[item])); $('price_' + item + '_display').update(asMoney(itemTotal[item]));
// update balance // update balance