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}
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

View File

@ -4,4 +4,14 @@ module StockitHelper
class_names << "unavailable" if article.quantity_available <= 0
class_names.join(" ")
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

View File

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

View File

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

View File

@ -1,6 +1,7 @@
class StockChange < ActiveRecord::Base
belongs_to :delivery
belongs_to :order
belongs_to :stock_taking
belongs_to :stock_article
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
def uniqueness_of_name
id = new_record? ? nil : self.id
supplier = Supplier.where('suppliers.id != ? AND suppliers.name = ?', id, name).first
if supplier.present?
message = supplier.deleted? ? :taken_with_deleted : :taken
supplier = Supplier.where('suppliers.name = ?', name)
supplier = supplier.where('suppliers.id != ?', self.id) unless new_record?
if supplier.exists?
message = supplier.first.deleted? ? :taken_with_deleted : :taken
errors.add :name, message
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
= 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'),
class: 'btn btn-mini btn-danger', :remote => true
%p

View File

@ -9,4 +9,11 @@ class String
string
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:
logged_in: Angemeldet!
logged_out: Abgemeldet!
login_invalid:
login_invalid: Ungültiger Benutzername oder Passwort
new:
forgot_password: Passwort vergessen?
login: Anmelden
@ -1676,6 +1676,15 @@ de:
title: Lagerartikel bearbeiten
form:
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:
article:
article: Artikel
@ -1822,6 +1831,7 @@ de:
close: Schließen
delete: Löschen
edit: Bearbeiten
history: Verlauf anzeigen
marks:
close: ! '&times;'
or_cancel: oder abbrechen

View File

@ -602,8 +602,8 @@ en:
orders:
clear: accounting
cleared: accounted (%{amount})
close: settle directly
confirm: Do you really want to settle the order?
close: close directly
confirm: Do you really want to fully close the order?
end: End
ended: closed
last_edited_by: Last edited by
@ -1678,6 +1678,15 @@ en:
title: Edit stock articles
form:
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:
article:
article: Article
@ -1824,6 +1833,7 @@ en:
close: Close
delete: Delete
edit: Edit
history: Show history
marks:
close: ! '&times;'
or_cancel: or cancel

View File

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

View File

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