diff --git a/app/models/article.rb b/app/models/article.rb index 76078e89..b0852133 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -1,5 +1,6 @@ # encoding: utf-8 class Article < ActiveRecord::Base + include PriceCalculation # @!attribute name # @return [String] Article name @@ -67,16 +68,6 @@ class Article < ActiveRecord::Base before_save :update_price_history before_destroy :check_article_in_use - # The financial gross, net plus tax and deposti - def gross_price - ((price + deposit) * (tax / 100 + 1)).round(2) - end - - # The price for the foodcoop-member. - def fc_price - (gross_price * (FoodsoftConfig[:price_markup] / 100 + 1)).round(2) - end - # Returns true if article has been updated at least 2 days ago def recently_updated updated_at > 2.days.ago diff --git a/app/models/article_price.rb b/app/models/article_price.rb index 67e4df76..9aa84c97 100644 --- a/app/models/article_price.rb +++ b/app/models/article_price.rb @@ -1,4 +1,5 @@ class ArticlePrice < ActiveRecord::Base + include PriceCalculation # @!attribute price # @return [Number] Net price @@ -27,17 +28,4 @@ class ArticlePrice < ActiveRecord::Base validates_numericality_of :unit_quantity, :greater_than => 0 validates_numericality_of :deposit, :tax - # Gross price = net price + deposit + tax. - # @return [Number] Gross price. - # @todo remove code-duplication with Article - def gross_price - ((price + deposit) * (tax / 100 + 1)).round(2) - end - - # @return [Number] Price for the foodcoop-member. - # @todo remove code-duplication with Article - def fc_price - (gross_price * (FoodsoftConfig[:price_markup] / 100 + 1)).round(2) - end end - diff --git a/app/models/concerns/price_calculation.rb b/app/models/concerns/price_calculation.rb new file mode 100644 index 00000000..b73e43c6 --- /dev/null +++ b/app/models/concerns/price_calculation.rb @@ -0,0 +1,14 @@ +module PriceCalculation + extend ActiveSupport::Concern + + # Gross price = net price + deposit + tax. + # @return [Number] Gross price. + def gross_price + ((price + deposit) * (tax / 100 + 1)).round(2) + end + + # @return [Number] Price for the foodcoop-member. + def fc_price + (gross_price * (FoodsoftConfig[:price_markup] / 100 + 1)).round(2) + end +end