2009-01-29 01:57:51 +01:00
|
|
|
# == Schema Information
|
2009-02-02 16:35:43 +01:00
|
|
|
# Schema version: 20090119155930
|
2009-01-29 01:57:51 +01:00
|
|
|
#
|
|
|
|
# Table name: article_prices
|
|
|
|
#
|
2009-02-02 16:35:43 +01:00
|
|
|
# id :integer not null, primary key
|
|
|
|
# article_id :integer
|
2009-01-29 01:57:51 +01:00
|
|
|
# price :decimal(8, 2) default(0.0), not null
|
|
|
|
# tax :decimal(8, 2) default(0.0), not null
|
|
|
|
# deposit :decimal(8, 2) default(0.0), not null
|
2009-02-02 16:35:43 +01:00
|
|
|
# unit_quantity :integer
|
2009-01-29 01:57:51 +01:00
|
|
|
# created_at :datetime
|
|
|
|
#
|
|
|
|
|
|
|
|
class ArticlePrice < ActiveRecord::Base
|
|
|
|
|
|
|
|
belongs_to :article
|
|
|
|
has_many :order_articles
|
2009-02-09 20:12:56 +01:00
|
|
|
|
|
|
|
# Custom attribute setter that accepts decimal numbers using localized decimal separator.
|
|
|
|
def price=(price)
|
|
|
|
self[:price] = String.delocalized_decimal(price)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Custom attribute setter that accepts decimal numbers using localized decimal separator.
|
|
|
|
def tax=(tax)
|
|
|
|
self[:tax] = String.delocalized_decimal(tax)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Custom attribute setter that accepts decimal numbers using localized decimal separator.
|
|
|
|
def deposit=(deposit)
|
|
|
|
self[:deposit] = String.delocalized_decimal(deposit)
|
|
|
|
end
|
2009-01-29 01:57:51 +01:00
|
|
|
|
|
|
|
# The financial gross, net plus tax and deposit.
|
|
|
|
def gross_price
|
2009-03-01 18:45:34 +01:00
|
|
|
((price + deposit) * (tax / 100 + 1)).round(2)
|
2009-01-29 01:57:51 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# The price for the foodcoop-member.
|
|
|
|
def fc_price
|
2009-03-24 17:25:33 +01:00
|
|
|
(gross_price * (Foodsoft.config[:price_markup] / 100 + 1)).round(2)
|
2009-01-29 01:57:51 +01:00
|
|
|
end
|
|
|
|
end
|