# encoding:utf-8
class ScaleDevice < ActiveRecord::Base
  has_paper_trail
  self.table_name = "scale_devices"
  belongs_to :wx_user
  #after_create :update_paied_time

  def wx_user_contact
    return "-" if wx_user.blank?
    user = wx_user.user
    return "-" if user.blank?
    contact = user.tel
    contact = user.email if contact.blank?
    contact.blank? ? "-" : contact
  end

  rails_admin do
    navigation_label '体脂秤管理'
    # parent Scale
    weight -921

    list do
      filters [:wx_user,:created_at]
      field :id
      field :wx_user_id
      field :wx_user do
        pretty_value do
          bindings[:object].wx_user_contact
        end
      end
      field :mac_addr
      field :created_at
      field :updated_at
    end

    show do
      field :wx_user_id
      field :wx_user do
        pretty_value do
          bindings[:object].wx_user_contact
        end
      end
      field :mac_addr
      field :created_at
      field :updated_at
    end

    edit do
      field :wx_user_id
      field :wx_user
      field :mac_addr
      field :created_at
      field :updated_at
    end
  end
end
