cirandas.net

ref: master

plugins/products/models/products_plugin/price_detail.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class ProductsPlugin::PriceDetail < ApplicationRecord

  self.table_name = :price_details

  attr_accessible :price, :production_cost_id
  attr_accessible :production_cost

  belongs_to :product
  validates_presence_of :product_id

  belongs_to :production_cost
  # Do not validates_presence_of production_cost. We may have undefined other costs.
  validates_uniqueness_of :production_cost_id, scope: :product_id

  def name
    production_cost.nil? ? _('Other costs') : production_cost.name
  end

  def price
    self[:price] || 0
  end

  def formatted_value(value)
    ("%.2f" % self[value]).to_s.gsub('.', product.enterprise.environment.currency_separator) if self[value]
  end

end