Merge branch 'rails3' of http://github.com/bennibu/foodsoft into rails3
This commit is contained in:
commit
a096b3618c
16 changed files with 78 additions and 58 deletions
|
@ -1 +0,0 @@
|
||||||
1.9.3-p327
|
|
|
@ -10,24 +10,22 @@ class Finance::BalancingController < Finance::BaseController
|
||||||
flash.now.alert = "Achtung, Bestellung wurde schon abgerechnet" if @order.closed?
|
flash.now.alert = "Achtung, Bestellung wurde schon abgerechnet" if @order.closed?
|
||||||
@comments = @order.comments
|
@comments = @order.comments
|
||||||
|
|
||||||
if params['sort']
|
@articles = @order.order_articles.ordered.includes(:order, :article_price,
|
||||||
sort = case params['sort']
|
group_order_articles: {group_order: :ordergroup})
|
||||||
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(:article).order(sort)
|
sort_param = params['sort'] || 'name'
|
||||||
|
@articles = case sort_param
|
||||||
if params[:sort] == "order_number"
|
when 'name' then
|
||||||
@articles = @articles.to_a.sort { |a,b| a.article.order_number.gsub(/[^[:digit:]]/, "").to_i <=> b.article.order_number.gsub(/[^[:digit:]]/, "").to_i }
|
OrderArticle.sort_by_name(@articles)
|
||||||
elsif params[:sort] == "order_number_reverse"
|
when 'name_reverse' then
|
||||||
@articles = @articles.to_a.sort { |a,b| b.article.order_number.gsub(/[^[:digit:]]/, "").to_i <=> a.article.order_number.gsub(/[^[:digit:]]/, "").to_i }
|
OrderArticle.sort_by_name(@articles).reverse
|
||||||
end
|
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?
|
render layout: false if request.xhr?
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@ class Article < ActiveRecord::Base
|
||||||
localize_input_of :price, :tax, :deposit
|
localize_input_of :price, :tax, :deposit
|
||||||
|
|
||||||
# Associations
|
# Associations
|
||||||
belongs_to :supplier
|
belongs_to :supplier, :with_deleted => true
|
||||||
belongs_to :article_category
|
belongs_to :article_category
|
||||||
has_many :article_prices, :order => "created_at DESC"
|
has_many :article_prices, :order => "created_at DESC"
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class ArticlePrice < ActiveRecord::Base
|
class ArticlePrice < ActiveRecord::Base
|
||||||
|
|
||||||
belongs_to :article
|
belongs_to :article, :with_deleted => true
|
||||||
has_many :order_articles
|
has_many :order_articles
|
||||||
|
|
||||||
validates_presence_of :price, :tax, :deposit, :unit_quantity
|
validates_presence_of :price, :tax, :deposit, :unit_quantity
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class Delivery < ActiveRecord::Base
|
class Delivery < ActiveRecord::Base
|
||||||
|
|
||||||
belongs_to :supplier
|
belongs_to :supplier, :with_deleted => true
|
||||||
has_one :invoice
|
has_one :invoice
|
||||||
has_many :stock_changes, :dependent => :destroy
|
has_many :stock_changes, :dependent => :destroy
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# financial transactions are the foodcoop internal financial transactions
|
# financial transactions are the foodcoop internal financial transactions
|
||||||
# only ordergroups have an account balance and are happy to transfer money
|
# only ordergroups have an account balance and are happy to transfer money
|
||||||
class FinancialTransaction < ActiveRecord::Base
|
class FinancialTransaction < ActiveRecord::Base
|
||||||
belongs_to :ordergroup
|
belongs_to :ordergroup, :with_deleted => true
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
||||||
validates_presence_of :amount, :note, :user_id, :ordergroup_id
|
validates_presence_of :amount, :note, :user_id, :ordergroup_id
|
||||||
|
|
|
@ -4,7 +4,7 @@ class GroupOrder < ActiveRecord::Base
|
||||||
attr_accessor :group_order_articles_attributes
|
attr_accessor :group_order_articles_attributes
|
||||||
|
|
||||||
belongs_to :order
|
belongs_to :order
|
||||||
belongs_to :ordergroup
|
belongs_to :ordergroup, :with_deleted => true
|
||||||
has_many :group_order_articles, :dependent => :destroy
|
has_many :group_order_articles, :dependent => :destroy
|
||||||
has_many :order_articles, :through => :group_order_articles
|
has_many :order_articles, :through => :group_order_articles
|
||||||
belongs_to :updated_by, :class_name => "User", :foreign_key => "updated_by_user_id"
|
belongs_to :updated_by, :class_name => "User", :foreign_key => "updated_by_user_id"
|
||||||
|
@ -22,35 +22,25 @@ class GroupOrder < ActiveRecord::Base
|
||||||
data = {}
|
data = {}
|
||||||
data[:available_funds] = ordergroup.get_available_funds(self)
|
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....
|
# load prices and other stuff....
|
||||||
data[:order_articles] = {}
|
data[:order_articles] = {}
|
||||||
#order.order_articles.each do |order_article|
|
|
||||||
order.articles_grouped_by_category.each do |article_category, order_articles|
|
order.articles_grouped_by_category.each do |article_category, order_articles|
|
||||||
order_articles.each do |order_article|
|
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] = {
|
data[:order_articles][order_article.id] = {
|
||||||
:price => order_article.article.fc_price,
|
:price => order_article.article.fc_price,
|
||||||
:unit => order_article.article.unit_quantity,
|
:unit => order_article.article.unit_quantity,
|
||||||
:quantity => (new_record? ? 0 : goas[order_article.id][:quantity]),
|
:quantity => (goa ? goa.quantity : 0),
|
||||||
:others_quantity => order_article.quantity - (new_record? ? 0 : goas[order_article.id][:quantity]),
|
:others_quantity => order_article.quantity - (goa ? goa.quantity : 0),
|
||||||
:used_quantity => (new_record? ? 0 : goas[order_article.id][:quantity_result]),
|
:used_quantity => (goa ? goa.result(:quantity) : 0),
|
||||||
:tolerance => (new_record? ? 0 : goas[order_article.id][:tolerance]),
|
:tolerance => (goa ? goa.result(:tolerance) : 0),
|
||||||
:others_tolerance => order_article.tolerance - (new_record? ? 0 : goas[order_article.id][:tolerance]),
|
:others_tolerance => order_article.tolerance - (goa ? goa.result(:tolerance) : 0),
|
||||||
:used_tolerance => (new_record? ? 0 : goas[order_article.id][:tolerance_result]),
|
:used_tolerance => (goa ? goa.result(:tolerance) : 0),
|
||||||
:total_price => (new_record? ? 0 : goas[order_article.id][:total_price]),
|
:total_price => (goa ? goa.total_price : 0),
|
||||||
:missing_units => order_article.missing_units,
|
:missing_units => order_article.missing_units,
|
||||||
:quantity_available => (order.stockit? ? order_article.article.quantity_available : 0)
|
:quantity_available => (order.stockit? ? order_article.article.quantity_available : 0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class Invoice < ActiveRecord::Base
|
class Invoice < ActiveRecord::Base
|
||||||
|
|
||||||
belongs_to :supplier
|
belongs_to :supplier, :with_deleted => true
|
||||||
belongs_to :delivery
|
belongs_to :delivery
|
||||||
belongs_to :order
|
belongs_to :order
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ class Order < ActiveRecord::Base
|
||||||
has_one :invoice
|
has_one :invoice
|
||||||
has_many :comments, :class_name => "OrderComment", :order => "created_at"
|
has_many :comments, :class_name => "OrderComment", :order => "created_at"
|
||||||
has_many :stock_changes
|
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 :updated_by, :class_name => 'User', :foreign_key => 'updated_by_user_id'
|
||||||
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_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
|
validate :starts_before_ends, :include_articles
|
||||||
|
|
||||||
# Callbacks
|
# Callbacks
|
||||||
after_update :update_price_of_group_orders
|
after_save :save_order_articles, :update_price_of_group_orders
|
||||||
after_save :save_order_articles
|
|
||||||
|
|
||||||
# Finders
|
# Finders
|
||||||
scope :open, where(state: 'open').order('ends DESC')
|
scope :open, where(state: 'open').order('ends DESC')
|
||||||
|
@ -215,7 +214,24 @@ class Order < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_order_articles
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -4,7 +4,7 @@ class OrderArticle < ActiveRecord::Base
|
||||||
attr_reader :update_current_price
|
attr_reader :update_current_price
|
||||||
|
|
||||||
belongs_to :order
|
belongs_to :order
|
||||||
belongs_to :article
|
belongs_to :article, :with_deleted => true
|
||||||
belongs_to :article_price
|
belongs_to :article_price
|
||||||
has_many :group_order_articles, :dependent => :destroy
|
has_many :group_order_articles, :dependent => :destroy
|
||||||
|
|
||||||
|
@ -17,6 +17,17 @@ class OrderArticle < ActiveRecord::Base
|
||||||
before_create :init_from_balancing
|
before_create :init_from_balancing
|
||||||
after_destroy :update_ordergroup_prices
|
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
|
# This method returns either the ArticlePrice or the Article
|
||||||
# The first will be set, when the the order is finished
|
# The first will be set, when the the order is finished
|
||||||
def price
|
def price
|
||||||
|
|
|
@ -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= 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{'data-check-this' => "#checkbox_#{article.id}", :class => 'click-me'}= article.name
|
||||||
%td= article.origin
|
%td= article.origin
|
||||||
|
@ -14,6 +14,4 @@
|
||||||
%td= link_to "Bearbeiten", edit_supplier_article_path(@supplier, article),
|
%td= link_to "Bearbeiten", edit_supplier_article_path(@supplier, article),
|
||||||
:remote => true, class: 'btn btn-mini'
|
:remote => true, class: 'btn btn-mini'
|
||||||
%td= link_to "Löschen", [@supplier, article],
|
%td= link_to "Löschen", [@supplier, article],
|
||||||
:method => :delete, :confirm => 'Bist du sicher?', :remote => true, class: 'btn btn-mini btn-danger'
|
:method => :delete, :confirm => 'Bist du sicher?', :remote => true, class: 'btn btn-mini btn-danger'
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
= link_to 'Gruppe hinzufügen', new_finance_group_order_article_path(order_article_id: order_article.id),
|
= link_to 'Gruppe hinzufügen', new_finance_group_order_article_path(order_article_id: order_article.id),
|
||||||
remote: true, class: 'btn btn-mini'
|
remote: true, class: 'btn btn-mini'
|
||||||
%tbody
|
%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]
|
%tr[group_order_article]
|
||||||
%td
|
%td
|
||||||
%td{:style=>"width:50%"}
|
%td{:style=>"width:50%"}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
.well.well-small
|
.well.well-small
|
||||||
%h3 Kommentare
|
%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
|
- content_for :actionbar do
|
||||||
.btn-group
|
.btn-group
|
||||||
|
|
|
@ -45,6 +45,8 @@
|
||||||
%thead
|
%thead
|
||||||
%tr
|
%tr
|
||||||
%th Name
|
%th Name
|
||||||
|
- if @order.stockit?
|
||||||
|
%th{style: 'width:120px'} Lieferant
|
||||||
%th{style: "width:13px;"}
|
%th{style: "width:13px;"}
|
||||||
%th{style: "width:4.5em;"} Preis
|
%th{style: "width:4.5em;"} Preis
|
||||||
%th{style: "width:4.5em;"} Einheit
|
%th{style: "width:4.5em;"} Einheit
|
||||||
|
@ -66,6 +68,8 @@
|
||||||
- order_articles.each do |order_article|
|
- order_articles.each do |order_article|
|
||||||
%tr{class: "#{cycle('even', 'odd', name: 'articles')} order-article", valign: "top"}
|
%tr{class: "#{cycle('even', 'odd', name: 'articles')} order-article", valign: "top"}
|
||||||
%td.name= order_article.article.name
|
%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= h order_article.article.origin
|
||||||
%td= number_to_currency(@ordering_data[:order_articles][order_article.id][:price])
|
%td= number_to_currency(@ordering_data[:order_articles][order_article.id][:price])
|
||||||
%td= order_article.article.unit
|
%td= order_article.article.unit
|
||||||
|
|
|
@ -7,4 +7,5 @@ Deine aktueller Äpfelpunktestand: #{apple_bar.apples}
|
||||||
Konkret: Pro #{number_to_currency(apple_bar.mean_order_amount_per_job, :precision => 0 )} Bestellsumme solltest Du eine Aufgabe machen!
|
Konkret: Pro #{number_to_currency(apple_bar.mean_order_amount_per_job, :precision => 0 )} Bestellsumme solltest Du eine Aufgabe machen!
|
||||||
- if FoodsoftConfig[:stop_ordering_under].present?
|
- if FoodsoftConfig[:stop_ordering_under].present?
|
||||||
%strong Achtung,
|
%strong Achtung,
|
||||||
hast Du weniger als #{FoodsoftConfig[:stop_ordering_under]} Äpfel, darfst Du nicht mehr bestellen!
|
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'
|
3
config/initializers/rack.rb
Normal file
3
config/initializers/rack.rb
Normal 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
|
Loading…
Reference in a new issue