Merge pull request #150 from foodcoop-rostock/stock_article_quantity_history
Show StockChanges index
This commit is contained in:
commit
126f7e7459
10 changed files with 68 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
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
|
||||
= 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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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: ! '×'
|
||||
or_cancel: oder abbrechen
|
||||
|
|
|
@ -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: ! '×'
|
||||
or_cancel: or cancel
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue