Complete refactoring of orders-workflow.
OrderResult tables are removed. Data consistency is now possible through new article.price-history (ArticlePrice). Balancing-workflow needs to be updated.
This commit is contained in:
parent
80287aeea4
commit
9eb2125f15
98 changed files with 1121 additions and 1717 deletions
|
|
@ -1,15 +1,16 @@
|
|||
# == Schema Information
|
||||
# Schema version: 20090102171850
|
||||
# Schema version: 20090120184410
|
||||
#
|
||||
# Table name: order_articles
|
||||
#
|
||||
# id :integer(4) not null, primary key
|
||||
# order_id :integer(4) default(0), not null
|
||||
# article_id :integer(4) default(0), not null
|
||||
# quantity :integer(4) default(0), not null
|
||||
# tolerance :integer(4) default(0), not null
|
||||
# units_to_order :integer(4) default(0), not null
|
||||
# lock_version :integer(4) default(0), not null
|
||||
# id :integer(4) not null, primary key
|
||||
# order_id :integer(4) default(0), not null
|
||||
# article_id :integer(4) default(0), not null
|
||||
# quantity :integer(4) default(0), not null
|
||||
# tolerance :integer(4) default(0), not null
|
||||
# units_to_order :integer(4) default(0), not null
|
||||
# lock_version :integer(4) default(0), not null
|
||||
# article_price_id :integer(4)
|
||||
#
|
||||
|
||||
# An OrderArticle represents a single Article that is part of an Order.
|
||||
|
|
@ -17,16 +18,25 @@ class OrderArticle < ActiveRecord::Base
|
|||
|
||||
belongs_to :order
|
||||
belongs_to :article
|
||||
belongs_to :article_price
|
||||
has_many :group_order_articles, :dependent => :destroy
|
||||
|
||||
validates_presence_of :order_id
|
||||
validates_presence_of :article_id
|
||||
validates_uniqueness_of :article_id, :scope => :order_id # an article can only have one record per order
|
||||
|
||||
named_scope :ordered, :conditions => "units_to_order >= 1"
|
||||
|
||||
# This method returns either the Article or the ArticlePrice
|
||||
# The latter will be set, when the the order is finished
|
||||
def price
|
||||
article_price || article
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def validate
|
||||
errors.add(:article, "muss angegeben sein und einen aktuellen Preis haben") if !(article = Article.find(article_id)) || article.gross_price.nil?
|
||||
errors.add(:article, "muss angegeben sein und einen aktuellen Preis haben") if !(article = Article.find(article_id)) || article.fc_price.nil?
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue