app/models/educode_sales/business.rb in educode_sales-0.5.0 vs app/models/educode_sales/business.rb in educode_sales-0.5.1
- old
+ new
@@ -1,10 +1,23 @@
module EducodeSales
class Business < ApplicationRecord
+
belongs_to :staff
belongs_to :department
belongs_to :last_follow_up, class_name: 'FollowUp', optional: true
- has_many :sale_plans, dependent: :destroy
- has_many :follow_ups, dependent: :destroy
+ has_many :sale_plans
+ has_many :follow_ups
+
+ default_scope -> {where(deleted_at: nil)}
+
+ def soft_destroy(user_id)
+ self.update(deleted_at: Time.now)
+ self.sale_plans.each do |d|
+ d.soft_destroy(user_id)
+ end
+ self.follow_ups.update_all(deleted_at: Time.now)
+ EducodeSales::Recycle.create(source: self, deleter_id: user_id)
+ end
+
end
end