Class: Quote::AssignLargeOppActivity
- Inherits:
-
BaseService
- Object
- BaseService
- Quote::AssignLargeOppActivity
- Defined in:
- app/services/quote/assign_large_opp_activity.rb
Defined Under Namespace
Classes: Result
Constant Summary collapse
- MIN_REVENUE =
USD/CAD
10_000- NEW_LARGE_OP =
'NEW_LARGE_OP'
Instance Attribute Summary collapse
-
#activity_map ⇒ Object
readonly
, :cf_pro, :cf_hom.
-
#min_revenue ⇒ Object
readonly
, :cf_pro, :cf_hom.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ AssignLargeOppActivity
constructor
A new instance of AssignLargeOppActivity.
- #process(quote) ⇒ Object
Methods inherited from BaseService
#log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger
Constructor Details
#initialize(options = {}) ⇒ AssignLargeOppActivity
Returns a new instance of AssignLargeOppActivity.
12 13 14 15 16 17 18 |
# File 'app/services/quote/assign_large_opp_activity.rb', line 12 def initialize( = {}) # Initialize our filters # @cf_pro = CustomerFilter.find(PRO_CUSTOMER_FILTER_ID) # @cf_hom = CustomerFilter.find(HOM_CUSTOMER_FILTER_ID) @min_revenue = [:min_revenue] || MIN_REVENUE super end |
Instance Attribute Details
#activity_map ⇒ Object (readonly)
, :cf_pro, :cf_hom
6 7 8 |
# File 'app/services/quote/assign_large_opp_activity.rb', line 6 def activity_map @activity_map end |
#min_revenue ⇒ Object (readonly)
, :cf_pro, :cf_hom
6 7 8 |
# File 'app/services/quote/assign_large_opp_activity.rb', line 6 def min_revenue @min_revenue end |
Instance Method Details
#process(quote) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/services/quote/assign_large_opp_activity.rb', line 20 def process(quote) # Since the activity will be tied to the opportunity and later we will skip if an open existing activity exists, we can # let this quote check on revision off the table. # return Result.new(assigned: false, message: "Quote Revision Do Not Qualify") if quote.is_revision? return Result.new(assigned: false, message: 'Quote is not a sales quote') unless quote.is_sales_quote? return Result.new(assigned: false, message: "Quote total is too low, must be #{@min_revenue}") if quote.total.to_f < min_revenue customer = quote.customer if quote.contact&.contactable? party = quote.contact elsif customer party = quote.customer end return Result.new(assigned: false, message: 'Quote has no valid parties with email') unless party # Check our product line and filters # product_lines = ProductLine.where(id: quote.goods_product_line_ids) # is_pro = cf_pro.applies_to_customer?(customer) # is_hom = cf_hom.applies_to_customer?(customer) task_type = NEW_LARGE_OP # Note, per https://3.basecamp.com/3233448/buckets/10545972/todos/6611562782#__recording_6641883981 # We are simplifying, i am keeping the old code in case we need to bring granularity back # if product_lines.where(ProductLine[:url].matches('snow-melting%')).exists? # if is_pro # LARGEOP_SM_PRO # elsif is_hom # LARGEOP_SM_HOM # end # elsif product_lines.where(ProductLine[:url].matches('floor-heating%')).exists? # if is_pro # LARGEOP_EFH_PRO # elsif is_hom # LARGEOP_EFH_HOM # end # else # if is_pro # LARGEOP_MISC_PRO # elsif is_hom # LARGEOP_MISC_HOM # end # end return Result.new(assigned: false, message: 'Product assortment or customer filter does not apply') unless task_type activity = party.create_activity(task_type, skip_if_exists: true, resource: quote.opportunity) if activity&.persisted? Result.new(assigned: true, activity: activity, message: "Activity #{task_type} assigned to #{party.full_name}") elsif activity.present? && activity.errors.present? = "#{task_type} activity could not be saved due to validation errors: #{activity.errors_to_s}" ErrorReporting.error(, { quote_id: quote.id }) Result.new(assigned: false, message: ) else Result.new(assigned: false, message: 'Activity not created, possibly exist already') end end |