Sha256: e7f61aafc13e1bd1599711174e3391b6e7d060e4fc56593381ba38cca10ffb5e

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

module EducodeSales
  class Staff < ApplicationRecord
    belongs_to :user
    belongs_to :role, optional: true

    has_many :market_areas, dependent: :destroy
    has_many :sale_plans, dependent: :restrict_with_exception
    has_many :sale_reports, dependent: :restrict_with_exception
    has_many :follow_ups, dependent: :restrict_with_exception
    has_many :teacher_follows, dependent: :restrict_with_exception
    has_many :teachers, dependent: :restrict_with_exception
    has_many :places, dependent: :restrict_with_exception
    has_many :businesses
    has_many :activities
    has_many :role_permissions, dependent: :destroy

    has_many :areas, through: :market_areas
    validates :user_id, uniqueness: { message: '已存在' }

    # attr_writer :month

    def self.month_list
      list = []
      24.times.map do |d|
        ["#{d + 1}个月", d + 1]
      end
    end

    def area_ids
      self.market_areas.pluck(:area_id)
    end

    def month
      if expired_at.present?
        (expired_at.year * 12 + expired_at.month) - (enabled_at.year * 12 + enabled_at.month)
      else
        nil
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
educode_sales-0.1.0 app/models/educode_sales/staff.rb