app/models/educode_sales/business.rb in educode_sales-1.10.48 vs app/models/educode_sales/business.rb in educode_sales-1.10.49

- old
+ new

@@ -16,10 +16,11 @@ has_many :follow_ups has_many :business_clazz_changes has_many :business_levels, dependent: :destroy has_many :business_watches, dependent: :destroy has_many :business_histories, dependent: :destroy + has_many :business_deliver_subjects, dependent: :destroy # 商机交付课程 has_many :money_plans has_one :invoice_apply has_many :invoice_details has_many :sales_details @@ -33,10 +34,11 @@ enum source_way: ['会议活动', '公司资源', '400电话', '商务邮箱', '渠道代理', '合作伙伴', '招标信息', '客户', '朋友'] # 关联关注 has_many :users, :class_name => 'EducodeSales::BusinessRelationShip', foreign_key: 'business_id', :dependent => :destroy + after_update :change_diliver # 每次查询时 默认的查询条件 default_scope -> { where(deleted_at: nil) } enum p_stage: %w[合同阶段 验收阶段 回款阶段] enum p_difficulty: %w[困难 适中 容易] @@ -73,8 +75,28 @@ '已中标' => ['已中标','已签单','已验收','回款中', '服务中','已结束'], '已签单' => ['已签单','已验收','回款中', '服务中','已结束'], '应收款' => ['已中标','已签单','已验收','回款中', '服务中','已结束'] }[type] end + + + # 创建商机交付课程数据 + def change_diliver + + if previous_changes["last_follow_up_id"].present? + last_clazz_id = previous_changes["last_follow_up_id"][-1] + common_type = FollowUp.find_by(id: last_clazz_id)&.stage&.name == "已中标" + BusinessDeliverSubject.find_or_create_by(business_id: self.id) if common_type + end + end + + def school_name + department&.school&.name || "--" + end + + def staff_name + last_follow_up&.assign_follow_ups.present? ? (last_follow_up.assign_follow_ups.map{ |d| d.staff.user.real_name}.join("、")) : staff&.user&.real_name + end + end end