Merge branch 'master' into tests-rspec
This commit is contained in:
commit
db80fbd807
13 changed files with 90 additions and 13 deletions
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
17
app/views/stockit/history.haml
Normal file
17
app/views/stockit/history.haml
Normal 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]
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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: ! '×'
|
close: ! '×'
|
||||||
or_cancel: oder abbrechen
|
or_cancel: oder abbrechen
|
||||||
|
|
|
@ -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: ! '×'
|
close: ! '×'
|
||||||
or_cancel: or cancel
|
or_cancel: or cancel
|
||||||
|
|
|
@ -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: ! '×'
|
close: ! '×'
|
||||||
or_cancel: of annuleren
|
or_cancel: of annuleren
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue