Order refactoring part two: Balancing workflow was adapted to the new order schema. Article modification is still missing.
This commit is contained in:
parent
9eb2125f15
commit
190a777278
53 changed files with 568 additions and 603 deletions
|
|
@ -24,19 +24,39 @@ class OrderArticle < ActiveRecord::Base
|
|||
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
|
||||
validate :article_and_price_exist
|
||||
|
||||
named_scope :ordered, :conditions => "units_to_order >= 1"
|
||||
|
||||
# TODO: How to create/update articles/article_prices during balancing
|
||||
# # Accessors for easy create of new order_articles in balancing process
|
||||
# attr_accessor :name, :order_number, :units_to_order, :unit_quantity, :unit, :net_price, :tax, :deposit
|
||||
#
|
||||
# before_validation_on_create :create_new_article
|
||||
|
||||
# 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
|
||||
|
||||
# Count quantities of belonging group_orders.
|
||||
# In balancing this can differ from ordered (by supplier) quantity for this article.
|
||||
def group_orders_sum
|
||||
quantity = group_order_articles.collect(&:quantity).sum
|
||||
{:quantity => quantity, :price => quantity * price.fc_price}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def validate
|
||||
errors.add(:article, "muss angegeben sein und einen aktuellen Preis haben") if !(article = Article.find(article_id)) || article.fc_price.nil?
|
||||
end
|
||||
|
||||
def article_and_price_exist
|
||||
errors.add(:article, "muss angegeben sein und einen aktuellen Preis haben") if !(article = Article.find(article_id)) || article.fc_price.nil?
|
||||
end
|
||||
|
||||
# def create_new_article
|
||||
# old_article = order.articles.find_by_name(name) # Check if there is already an Article with this name
|
||||
# unless old_article
|
||||
# self.article.build
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue