# == Schema Information
#
# Table name: product_records
#
#  id              :bigint           not null, primary key
#  product_sn      :string(255)
#  product_id      :bigint           not null
#  shipping_box_id :integer
#  type            :string(255)
#  status          :integer
#  created_by      :string(255)
#  remark          :string(255)
#  created_at      :datetime         not null
#  updated_at      :datetime         not null
#  lot_no          :string(255)
#
class ProductRecord < ApplicationRecord
  belongs_to :product

  validates :product_sn, presence: true

  def record_name
    if self.type == "ShippingBoxItem"
      "发货单编号##{self.shipping_box_id}"
    elsif self.type == "RmaRecord"
      "维修"
    elsif self.type == "RefundRecord"
      "退货"
    else
      self.type
    end
  end
end
