class PSheetLineStock < ApplicationRecord
  
  belongs_to :p_sheet_line
  belongs_to :p_brut_product
  belongs_to :p_product_brut_stock
  
  validates :qte_ok, :presence => true, :if => :validate_ok?
  validates :ok_at, :presence => true, :if => :validate_ok?
  validates :price_ok, :presence => true, :if => :validate_ok?
  
  def validate_ok?
    if self.ok
      true
    else
      false
    end
  end
  
  
  def price_tot_ok
    self.qte_ok.to_f * self.price_ok.to_f
  end
  after_destroy do
    self.p_product_brut_stock.save
  end
  

  
end
