Merge branch 'rails3' of http://github.com/bennibu/foodsoft into rails3

This commit is contained in:
Julius 2013-03-14 20:54:59 +01:00
commit a096b3618c
16 changed files with 78 additions and 58 deletions

View file

@ -1 +0,0 @@
1.9.3-p327

View file

@ -10,24 +10,22 @@ class Finance::BalancingController < Finance::BaseController
flash.now.alert = "Achtung, Bestellung wurde schon abgerechnet" if @order.closed?
@comments = @order.comments
if params['sort']
sort = case params['sort']
when "name" then "articles.name"
when "order_number" then "articles.order_number"
when "name_reverse" then "articles.name DESC"
when "order_number_reverse" then "articles.order_number DESC"
end
else
sort = "id"
end
@articles = @order.order_articles.ordered.includes(:order, :article_price,
group_order_articles: {group_order: :ordergroup})
@articles = @order.order_articles.ordered.includes(:article).order(sort)
if params[:sort] == "order_number"
@articles = @articles.to_a.sort { |a,b| a.article.order_number.gsub(/[^[:digit:]]/, "").to_i <=> b.article.order_number.gsub(/[^[:digit:]]/, "").to_i }
elsif params[:sort] == "order_number_reverse"
@articles = @articles.to_a.sort { |a,b| b.article.order_number.gsub(/[^[:digit:]]/, "").to_i <=> a.article.order_number.gsub(/[^[:digit:]]/, "").to_i }
end
sort_param = params['sort'] || 'name'
@articles = case sort_param
when 'name' then
OrderArticle.sort_by_name(@articles)
when 'name_reverse' then
OrderArticle.sort_by_name(@articles).reverse
when 'order_number' then
OrderArticle.sort_by_order_number(@articles)
when 'order_number_reverse' then
OrderArticle.sort_by_order_number(@articles).reverse
else
@articles
end
render layout: false if request.xhr?
end

View file

@ -7,7 +7,7 @@ class Article < ActiveRecord::Base
localize_input_of :price, :tax, :deposit
# Associations
belongs_to :supplier
belongs_to :supplier, :with_deleted => true
belongs_to :article_category
has_many :article_prices, :order => "created_at DESC"

View file

@ -1,6 +1,6 @@
class ArticlePrice < ActiveRecord::Base
belongs_to :article
belongs_to :article, :with_deleted => true
has_many :order_articles
validates_presence_of :price, :tax, :deposit, :unit_quantity

View file

@ -1,6 +1,6 @@
class Delivery < ActiveRecord::Base
belongs_to :supplier
belongs_to :supplier, :with_deleted => true
has_one :invoice
has_many :stock_changes, :dependent => :destroy

View file

@ -1,7 +1,7 @@
# financial transactions are the foodcoop internal financial transactions
# only ordergroups have an account balance and are happy to transfer money
class FinancialTransaction < ActiveRecord::Base
belongs_to :ordergroup
belongs_to :ordergroup, :with_deleted => true
belongs_to :user
validates_presence_of :amount, :note, :user_id, :ordergroup_id

View file

@ -4,7 +4,7 @@ class GroupOrder < ActiveRecord::Base
attr_accessor :group_order_articles_attributes
belongs_to :order
belongs_to :ordergroup
belongs_to :ordergroup, :with_deleted => true
has_many :group_order_articles, :dependent => :destroy
has_many :order_articles, :through => :group_order_articles
belongs_to :updated_by, :class_name => "User", :foreign_key => "updated_by_user_id"
@ -22,35 +22,25 @@ class GroupOrder < ActiveRecord::Base
data = {}
data[:available_funds] = ordergroup.get_available_funds(self)
unless new_record?
# Group has already ordered, so get the results...
goas = {}
group_order_articles.all.each do |goa|
goas[goa.order_article_id] = {
:quantity => goa.quantity,
:tolerance => goa.tolerance,
:quantity_result => goa.result(:quantity),
:tolerance_result => goa.result(:tolerance),
:total_price => goa.total_price
}
end
end
# load prices and other stuff....
data[:order_articles] = {}
#order.order_articles.each do |order_article|
order.articles_grouped_by_category.each do |article_category, order_articles|
order_articles.each do |order_article|
# Get the result of last time ordering, if possible
goa = group_order_articles.detect { |goa| goa.order_article_id == order_article.id }
# Build hash with relevant data
data[:order_articles][order_article.id] = {
:price => order_article.article.fc_price,
:unit => order_article.article.unit_quantity,
:quantity => (new_record? ? 0 : goas[order_article.id][:quantity]),
:others_quantity => order_article.quantity - (new_record? ? 0 : goas[order_article.id][:quantity]),
:used_quantity => (new_record? ? 0 : goas[order_article.id][:quantity_result]),
:tolerance => (new_record? ? 0 : goas[order_article.id][:tolerance]),
:others_tolerance => order_article.tolerance - (new_record? ? 0 : goas[order_article.id][:tolerance]),
:used_tolerance => (new_record? ? 0 : goas[order_article.id][:tolerance_result]),
:total_price => (new_record? ? 0 : goas[order_article.id][:total_price]),
:quantity => (goa ? goa.quantity : 0),
:others_quantity => order_article.quantity - (goa ? goa.quantity : 0),
:used_quantity => (goa ? goa.result(:quantity) : 0),
:tolerance => (goa ? goa.result(:tolerance) : 0),
:others_tolerance => order_article.tolerance - (goa ? goa.result(:tolerance) : 0),
:used_tolerance => (goa ? goa.result(:tolerance) : 0),
:total_price => (goa ? goa.total_price : 0),
:missing_units => order_article.missing_units,
:quantity_available => (order.stockit? ? order_article.article.quantity_available : 0)
}

View file

@ -1,6 +1,6 @@
class Invoice < ActiveRecord::Base
belongs_to :supplier
belongs_to :supplier, :with_deleted => true
belongs_to :delivery
belongs_to :order

View file

@ -10,7 +10,7 @@ class Order < ActiveRecord::Base
has_one :invoice
has_many :comments, :class_name => "OrderComment", :order => "created_at"
has_many :stock_changes
belongs_to :supplier
belongs_to :supplier, :with_deleted => true
belongs_to :updated_by, :class_name => 'User', :foreign_key => 'updated_by_user_id'
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id'
@ -19,8 +19,7 @@ class Order < ActiveRecord::Base
validate :starts_before_ends, :include_articles
# Callbacks
after_update :update_price_of_group_orders
after_save :save_order_articles
after_save :save_order_articles, :update_price_of_group_orders
# Finders
scope :open, where(state: 'open').order('ends DESC')
@ -215,7 +214,24 @@ class Order < ActiveRecord::Base
end
def save_order_articles
self.articles = Article.find(article_ids)
#self.articles = Article.find(article_ids) # This doesn't deletes the group_order_articles, belonging to order_articles,
# # see http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_many
#
## Ensure to delete also the group_order_articles, belonging to order_articles
## This case is relevant, when removing articles from a running order
#goa_ids = GroupOrderArticle.where(group_order_id: group_order_ids).includes(:order_article).
# select { |goa| goa.order_article.nil? }.map(&:id)
#GroupOrderArticle.delete_all(id: goa_ids) unless goa_ids.empty?
# fetch selected articles
articles_list = Article.find(article_ids)
# create new order_articles
(articles_list - articles).each { |article| order_articles.create(:article => article) }
# delete old order_articles
articles.reject { |article| articles_list.include?(article) }.each do |article|
order_articles.detect { |order_article| order_article.article_id == article.id }.destroy
end
end
private

View file

@ -4,7 +4,7 @@ class OrderArticle < ActiveRecord::Base
attr_reader :update_current_price
belongs_to :order
belongs_to :article
belongs_to :article, :with_deleted => true
belongs_to :article_price
has_many :group_order_articles, :dependent => :destroy
@ -17,6 +17,17 @@ class OrderArticle < ActiveRecord::Base
before_create :init_from_balancing
after_destroy :update_ordergroup_prices
def self.sort_by_name(order_articles)
order_articles.sort { |a,b| a.article.name <=> b.article.name }
end
def self.sort_by_order_number(order_articles)
order_articles.sort do |a,b|
a.article.order_number.to_s.gsub(/[^[:digit:]]/, "").to_i <=>
b.article.order_number.to_s.gsub(/[^[:digit:]]/, "").to_i
end
end
# This method returns either the ArticlePrice or the Article
# The first will be set, when the the order is finished
def price

View file

@ -1,4 +1,4 @@
%tr{class: row_classes(article)}
%tr{class: row_classes(article)}[article]
%td= check_box_tag 'selected_articles[]', article.id.to_s, false, {:id => "checkbox_#{article.id}", 'data-ignore-onchange' => true}
%td{'data-check-this' => "#checkbox_#{article.id}", :class => 'click-me'}= article.name
%td= article.origin
@ -15,5 +15,3 @@
:remote => true, class: 'btn btn-mini'
%td= link_to "Löschen", [@supplier, article],
:method => :delete, :confirm => 'Bist du sicher?', :remote => true, class: 'btn btn-mini btn-danger'

View file

@ -10,7 +10,7 @@
= link_to 'Gruppe hinzufügen', new_finance_group_order_article_path(order_article_id: order_article.id),
remote: true, class: 'btn btn-mini'
%tbody
- for group_order_article in order_article.group_order_articles.ordered.all(:include => [:group_order])
- for group_order_article in order_article.group_order_articles.select { |goa| goa.result > 0 }
%tr[group_order_article]
%td
%td{:style=>"width:50%"}

View file

@ -20,7 +20,7 @@
.well.well-small
%h3 Kommentare
#comments= render :partial => 'shared/comments', locals: {comments: @order.comments}
#comments= render :partial => 'shared/comments', locals: {comments: @order.comments.includes(:user)}
- content_for :actionbar do
.btn-group

View file

@ -45,6 +45,8 @@
%thead
%tr
%th Name
- if @order.stockit?
%th{style: 'width:120px'} Lieferant
%th{style: "width:13px;"}
%th{style: "width:4.5em;"} Preis
%th{style: "width:4.5em;"} Einheit
@ -66,6 +68,8 @@
- order_articles.each do |order_article|
%tr{class: "#{cycle('even', 'odd', name: 'articles')} order-article", valign: "top"}
%td.name= order_article.article.name
- if @order.stockit?
%td= truncate order_article.article.supplier.name, length: 15
%td= h order_article.article.origin
%td= number_to_currency(@ordering_data[:order_articles][order_article.id][:price])
%td= order_article.article.unit

View file

@ -8,3 +8,4 @@ Deine aktueller Äpfelpunktestand: #{apple_bar.apples}
- if FoodsoftConfig[:stop_ordering_under].present?
%strong Achtung,
hast Du weniger als #{FoodsoftConfig[:stop_ordering_under]} Äpfel, darfst Du nicht mehr bestellen!
= link_to 'Mehr Informationen', 'https://github.com/bennibu/foodsoft/wiki/%C3%84pfel-u.-Birnen', target: '_blank'

View file

@ -0,0 +1,3 @@
# Increase key space for post request.
# Warning, this is dangerous. See http://stackoverflow.com/questions/12243694/getting-error-exceeded-available-parameter-key-space
Rack::Utils.key_space_limit = 262144