Introduced StockChange. Implemented first part of stockit-logic with updating article's quantity.
This commit is contained in:
parent
7ff0467b16
commit
b38025869a
27 changed files with 233 additions and 123 deletions
|
|
@ -1,5 +1,5 @@
|
|||
# == Schema Information
|
||||
# Schema version: 20090113111624
|
||||
# Schema version: 20090115232435
|
||||
#
|
||||
# Table name: articles
|
||||
#
|
||||
|
|
@ -21,32 +21,9 @@
|
|||
# order_number :string(255)
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# quantity :decimal(6, 2) default(0.0)
|
||||
#
|
||||
|
||||
# == Schema Information
|
||||
# Schema version: 20090102171850
|
||||
#
|
||||
# Table name: articles
|
||||
#
|
||||
# id :integer(4) not null, primary key
|
||||
# name :string(255) default(""), not null
|
||||
# supplier_id :integer(4) default(0), not null
|
||||
# article_category_id :integer(4) default(0), not null
|
||||
# unit :string(255) default(""), not null
|
||||
# note :string(255)
|
||||
# availability :boolean(1) default(TRUE), not null
|
||||
# manufacturer :string(255)
|
||||
# origin :string(255)
|
||||
# shared_updated_on :datetime
|
||||
# net_price :decimal(8, 2)
|
||||
# gross_price :decimal(8, 2) default(0.0), not null
|
||||
# tax :float
|
||||
# deposit :decimal(8, 2) default(0.0)
|
||||
# unit_quantity :integer(4) default(1), not null
|
||||
# order_number :string(255)
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
#
|
||||
class Article < ActiveRecord::Base
|
||||
belongs_to :supplier
|
||||
belongs_to :article_category
|
||||
|
|
@ -230,4 +207,9 @@ class Article < ActiveRecord::Base
|
|||
# it could be so easy ... but that doesn't work for empty category-ids...
|
||||
# articles.group_by {|a| a.article_category}.sort {|a, b| a[0].name <=> b[0].name}
|
||||
end
|
||||
|
||||
def update_quantity(amount)
|
||||
update_attribute :quantity, quantity + amount
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,6 +12,14 @@
|
|||
class Delivery < ActiveRecord::Base
|
||||
|
||||
belongs_to :supplier
|
||||
has_many :stock_changes
|
||||
|
||||
validates_presence_of :supplier_id
|
||||
|
||||
def stock_change_attributes=(stock_change_attributes)
|
||||
for attributes in stock_change_attributes
|
||||
stock_changes.build(attributes) unless attributes[:quantity] == 0.0 or attributes[:quantity].blank?
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ class Mailer < ActionMailer::Base
|
|||
from (message.system_message? ? "FoodSoft <#{APP_CONFIG[:email_sender]}>" : "#{message.sender.nick} <#{message.sender.email}>")
|
||||
body :body => message.body, :sender => (message.system_message? ? 'Foodsoft' : message.sender.nick),
|
||||
:recipients => message.recipients,
|
||||
:reply => url_for(:host => request.host, reply_message_path(message),
|
||||
:profile => url_for(:host => request.host, my_profile_path),
|
||||
:link => url_for(:host => request.host, message_path(message),
|
||||
:foodsoftUrl => url_for(:host => request.host, :controller => "index")
|
||||
:reply => url_for(:host => request.host, :controller => "messages", :action => "reply", :id => message),
|
||||
:profile => url_for(:host => request.host, :controller => "home", :action => "profile"),
|
||||
:link => url_for(:host => request.host, :controller => "messages", :action => "show", :id => message),
|
||||
:foodsoftUrl => url_for(:host => request.host, :controller => "/")
|
||||
end
|
||||
|
||||
# Sends an invite email.
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
# == Schema Information
|
||||
# Schema version: 20090115123421
|
||||
# Schema version: 20090115232435
|
||||
#
|
||||
# Table name: messages
|
||||
#
|
||||
# id :integer(4) not null, primary key
|
||||
# sender_id :integer(4)
|
||||
# recipients_ids :text default(""), not null
|
||||
# recipients_ids :text
|
||||
# subject :string(255) not null
|
||||
# body :text
|
||||
# email_state :integer(4) default(0), not null
|
||||
|
|
|
|||
34
app/models/stock_change.rb
Normal file
34
app/models/stock_change.rb
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# == Schema Information
|
||||
# Schema version: 20090115232435
|
||||
#
|
||||
# Table name: stock_changes
|
||||
#
|
||||
# id :integer(4) not null, primary key
|
||||
# delivery_id :integer(4)
|
||||
# order_id :integer(4)
|
||||
# article_id :integer(4)
|
||||
# quantity :decimal(6, 2) default(0.0)
|
||||
# created_at :datetime
|
||||
#
|
||||
|
||||
class StockChange < ActiveRecord::Base
|
||||
belongs_to :delivery
|
||||
belongs_to :order
|
||||
belongs_to :article
|
||||
|
||||
validates_presence_of :article_id, :quantity
|
||||
validates_numericality_of :quantity
|
||||
|
||||
after_save :update_article_quantity
|
||||
after_destroy :remove_added_quantity
|
||||
|
||||
protected
|
||||
|
||||
def update_article_quantity
|
||||
article.update_quantity(quantity)
|
||||
end
|
||||
|
||||
def remove_added_quantity
|
||||
article.update_quantity(quantity * -1)
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue