class PSheetLineLine < ActiveRecord::Base
  belongs_to :p_sheet_line
  belongs_to :p_product_stock
  belongs_to :p_size
  belongs_to :p_color
  
  def p_size
    
    if self.p_size_id
      PSize.where(:id => self.p_size_id).first
    else
      self.p_product_stock.p_size
    end 
    
  end
  
  def p_color
    if self.p_color_id
      PColor.where(:id => self.p_color_id).first
    else
      self.p_product_stock.p_color
    end 
  end
  
  
  def fige
    if self.p_product_stock.p_color
      p_color = self.p_product_stock.p_color.dup
      p_color.archived = true
      self.p_color = p_color
    end
    
    if self.p_product_stock.p_size
      p_size = self.p_product_stock.p_size.dup
      p_size.archived = true
      self.p_size = p_size
    end
    
    
    self.ok_code = self.p_product_stock.code
  end
  
  
  
end
