Merge branch 'master' into tests-rspec

This commit is contained in:
wvengen 2013-07-15 18:45:04 +02:00
commit db80fbd807
13 changed files with 90 additions and 13 deletions

View file

@ -55,4 +55,9 @@ class StockitController < ApplicationController
render :partial => 'form', :locals => {:stock_article => stock_article} render :partial => 'form', :locals => {:stock_article => stock_article}
end end
def history
@stock_article = StockArticle.undeleted.find(params[:stock_article_id])
@stock_changes = @stock_article.stock_changes.order('stock_changes.created_at DESC').each {|s| s.readonly!}
end
end end

View file

@ -4,4 +4,14 @@ module StockitHelper
class_names << "unavailable" if article.quantity_available <= 0 class_names << "unavailable" if article.quantity_available <= 0
class_names.join(" ") class_names.join(" ")
end end
def link_to_stock_change_reason(stock_change)
if stock_change.delivery_id
link_to t('.delivery'), supplier_delivery_path(stock_change.delivery.supplier, stock_change.delivery)
elsif stock_change.order_id
link_to t('.order'), order_path(stock_change.order)
elsif stock_change.stock_taking_id
link_to t('.stock_taking'), stock_taking_path(stock_change.stock_taking)
end
end
end end

View file

@ -108,10 +108,10 @@ class Ordergroup < Group
# Make sure, the name is uniq, add usefull message if uniq group is already deleted # Make sure, the name is uniq, add usefull message if uniq group is already deleted
def uniqueness_of_name def uniqueness_of_name
id = new_record? ? nil : self.id group = Ordergroup.where('groups.name = ?', name)
group = Ordergroup.where('groups.id != ? AND groups.name = ?', id, name).first group = group.where('groups.id != ?', self.id) unless new_record?
if group.present? if group.exists?
message = group.deleted? ? :taken_with_deleted : :taken message = group.first.deleted? ? :taken_with_deleted : :taken
errors.add :name, message errors.add :name, message
end end
end end

View file

@ -18,6 +18,10 @@ class StockArticle < Article
joins(:order).where("orders.state = 'open' OR orders.state = 'finished'").sum(:units_to_order) joins(:order).where("orders.state = 'open' OR orders.state = 'finished'").sum(:units_to_order)
end end
def quantity_history
stock_changes.reorder('stock_changes.created_at ASC').map{|s| s.quantity}.cumulative_sum
end
def self.stock_value def self.stock_value
available.collect { |a| a.quantity * a.gross_price }.sum available.collect { |a| a.quantity * a.gross_price }.sum
end end

View file

@ -1,6 +1,7 @@
class StockChange < ActiveRecord::Base class StockChange < ActiveRecord::Base
belongs_to :delivery belongs_to :delivery
belongs_to :order belongs_to :order
belongs_to :stock_taking
belongs_to :stock_article belongs_to :stock_article
validates_presence_of :stock_article_id, :quantity validates_presence_of :stock_article_id, :quantity

View file

@ -80,10 +80,10 @@ class Supplier < ActiveRecord::Base
# Make sure, the name is uniq, add usefull message if uniq group is already deleted # Make sure, the name is uniq, add usefull message if uniq group is already deleted
def uniqueness_of_name def uniqueness_of_name
id = new_record? ? nil : self.id supplier = Supplier.where('suppliers.name = ?', name)
supplier = Supplier.where('suppliers.id != ? AND suppliers.name = ?', id, name).first supplier = supplier.where('suppliers.id != ?', self.id) unless new_record?
if supplier.present? if supplier.exists?
message = supplier.deleted? ? :taken_with_deleted : :taken message = supplier.first.deleted? ? :taken_with_deleted : :taken
errors.add :name, message errors.add :name, message
end end
end end

View file

@ -0,0 +1,17 @@
- title t('.stock_changes', :article_name => @stock_article.name)
%table.table.table-hover#stock_changes
%thead
%tr
%th= t '.datetime'
%th= t '.reason'
%th= t '.change_quantity'
%th= t '.new_quantity'
%tbody
- reversed_history = @stock_article.quantity_history.reverse
- @stock_changes.each_with_index do |stock_change, index|
%tr
%td= l stock_change.created_at
%td= link_to_stock_change_reason(stock_change)
%td= stock_change.quantity
%td= reversed_history[index]

View file

@ -56,6 +56,7 @@
%td= article.article_category.name %td= article.article_category.name
%td %td
= link_to t('ui.edit'), edit_stock_article_path(article), class: 'btn btn-mini' = link_to t('ui.edit'), edit_stock_article_path(article), class: 'btn btn-mini'
= link_to t('ui.history'), stock_article_history_path(article), class: 'btn btn-mini'
= link_to t('ui.delete'), article, :method => :delete, :confirm => t('.confirm_delete'), = link_to t('ui.delete'), article, :method => :delete, :confirm => t('.confirm_delete'),
class: 'btn btn-mini btn-danger', :remote => true class: 'btn btn-mini btn-danger', :remote => true
%p %p

View file

@ -10,3 +10,10 @@ class String
end end
end end
end end
class Array
def cumulative_sum
csum = 0
self.map{|val| csum += val}
end
end

View file

@ -1428,7 +1428,7 @@ de:
sessions: sessions:
logged_in: Angemeldet! logged_in: Angemeldet!
logged_out: Abgemeldet! logged_out: Abgemeldet!
login_invalid: login_invalid: Ungültiger Benutzername oder Passwort
new: new:
forgot_password: Passwort vergessen? forgot_password: Passwort vergessen?
login: Anmelden login: Anmelden
@ -1676,6 +1676,15 @@ de:
title: Lagerartikel bearbeiten title: Lagerartikel bearbeiten
form: form:
price_hint: Um Chaos zu vermeiden können bis auf weiteres die Preise von angelegten Lagerartikeln nicht mehr verändert werden. price_hint: Um Chaos zu vermeiden können bis auf weiteres die Preise von angelegten Lagerartikeln nicht mehr verändert werden.
history:
change_quantity: Veränderung
datetime: Zeitpunkt
delivery: Lieferung
new_quantity: Neuer Bestand
order: Bestellung
reason: Ereignis
stock_changes: Verlauf anzeigen für »%{article_name}«
stock_taking: Inventur
index: index:
article: article:
article: Artikel article: Artikel
@ -1822,6 +1831,7 @@ de:
close: Schließen close: Schließen
delete: Löschen delete: Löschen
edit: Bearbeiten edit: Bearbeiten
history: Verlauf anzeigen
marks: marks:
close: ! '&times;' close: ! '&times;'
or_cancel: oder abbrechen or_cancel: oder abbrechen

View file

@ -602,8 +602,8 @@ en:
orders: orders:
clear: accounting clear: accounting
cleared: accounted (%{amount}) cleared: accounted (%{amount})
close: settle directly close: close directly
confirm: Do you really want to settle the order? confirm: Do you really want to fully close the order?
end: End end: End
ended: closed ended: closed
last_edited_by: Last edited by last_edited_by: Last edited by
@ -1678,6 +1678,15 @@ en:
title: Edit stock articles title: Edit stock articles
form: form:
price_hint: To avoid choas, it is not possible to edit the prices of already added stock articles until further notice. price_hint: To avoid choas, it is not possible to edit the prices of already added stock articles until further notice.
history:
change_quantity: Change
datetime: Time
delivery: Delivery
new_quantity: New quantity
order: Order
reason: Reason
stock_changes: Stock quantity changes of %{article_name}
stock_taking: Inventory
index: index:
article: article:
article: Article article: Article
@ -1824,6 +1833,7 @@ en:
close: Close close: Close
delete: Delete delete: Delete
edit: Edit edit: Edit
history: Show history
marks: marks:
close: ! '&times;' close: ! '&times;'
or_cancel: or cancel or_cancel: or cancel

View file

@ -1567,6 +1567,15 @@ nl:
title: title:
form: form:
price_hint: price_hint:
history:
change_quantity:
datetime:
delivery:
new_quantity:
order:
reason:
stock_changes:
stock_taking:
index: index:
article: article:
article: article:
@ -1713,6 +1722,7 @@ nl:
close: Sluiten close: Sluiten
delete: Verwijder delete: Verwijder
edit: Bewerk edit: Bewerk
history:
marks: marks:
close: ! '&times;' close: ! '&times;'
or_cancel: of annuleren or_cancel: of annuleren

View file

@ -96,6 +96,8 @@ Foodsoft::Application.routes.draw do
get :articles_search get :articles_search
get :fill_new_stock_article_form get :fill_new_stock_article_form
end end
get :history
end end
resources :suppliers do resources :suppliers do