class MOdrFileProduct < ApplicationRecord
  belongs_to :m_odr_file
  belongs_to :m_odr_product
  belongs_to :m_odr_product_size

  #validates :qte, :presence => true, numericality: { greater_than: 0}
  
  attr_accessor :admin_form
  
  validates :qte, :presence => true, :if => :is_tire_admin_form?
  validates :price, :presence => true, :if => :is_tire_admin_form?
  validates :m_odr_product_id, :presence => true, :if => :is_tire_admin_form?
  
  def is_tire_admin_form?
    if self.m_odr_file and self.m_odr_file.m_odr_file_type_id == 2
      if self.admin_form
        true
      else
        false
      end
    else
      false
    end
  
  end
  
  
  
  before_save do
    if self.m_odr_product_size
      self.m_odr_product = self.m_odr_product_size.m_odr_product
    end
  end
end
