Class: EdiMailer

Inherits:
InternalNotificationMailer show all
Defined in:
app/mailers/edi_mailer.rb

Overview

EDI partner / Mirakl notifications (admin + AR alerts, order pushes).

Extracted from the former InternalMailer god object.

See Also:

  • InternalNotificationMailer
  • doc/tasks/202606131218_INTERNAL_MAILER_DECOMPOSITIONdoc/tasks/202606131218_INTERNAL_MAILER_DECOMPOSITION.md

Instance Method Summary collapse

Methods inherited from InternalNotificationMailer

#default_url_options

Methods included from SendgridSmtpApi::InternalMailerHeaders

#mail

Methods inherited from ApplicationMailer

#null_mail

Instance Method Details

#amazon_seller_central_orders_notification(orders) ⇒ Mail::Message, ActionMailer::MessageDelivery

Amazon Seller Central variant of #edi_orders_notification.

Amazon Seller Central is an EDI partner; this delegates to
+edi_orders_notification+ (same instance) and renders its template.

Parameters:

  • orders (Array<Order>)

    orders imported in this batch

Returns:

  • (Mail::Message, ActionMailer::MessageDelivery)

    the digest email,
    or a null delivery when there are no orders



43
44
45
# File 'app/mailers/edi_mailer.rb', line 43

def amazon_seller_central_orders_notification(orders)
  edi_orders_notification(orders, partner_name: 'Amazon')
end

#edi_orders_notification(orders, partner_name: nil) ⇒ Mail::Message, ActionMailer::MessageDelivery

Sends the "orders imported into Heatwave" digest for an EDI partner to the
orders inbox (cc EDI admin).

Returns a no-op null delivery when +orders+ is blank so callers can fire
unconditionally after each order-flow run.

Parameters:

  • orders (Array<Order>)

    orders imported in this batch

  • partner_name (String, nil) (defaults to: nil)

    display-name override; defaults to the
    name resolved from the first order's EDI partner key

Returns:

  • (Mail::Message, ActionMailer::MessageDelivery)

    the digest email,
    or a null delivery when there are no orders



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/mailers/edi_mailer.rb', line 20

def edi_orders_notification(orders, partner_name: nil)
  return null_mail if orders.blank?

  @orders = orders
  @partner_name = partner_name || Edi::PartnerNames.display_for(@orders.first&.edi_orchestrator_partner)

  subject = "#{@partner_name} Orders Imported into Heatwave: #{@orders.map(&:reference_number).join(', ')}"

  mail(from: 'Order Notifications <orders@warmlyyours.com>',
       to: 'orders@warmlyyours.com',
       cc: 'ediadmin@warmlyyours.com',
       subject: subject,
       template_name: 'edi_orders_notification')
end

#notify_ar_of_edi_credit_limit_issue(edi_communication_log, msg: nil) ⇒ Mail::Message

Alerts accounts receivable that an EDI order hit the customer's credit limit.

Parameters:

  • edi_communication_log (EdiCommunicationLog)

    the blocked log entry

  • msg (String, nil) (defaults to: nil)

    additional details

Returns:

  • (Mail::Message)

    the alert email



105
106
107
108
109
110
111
# File 'app/mailers/edi_mailer.rb', line 105

def notify_ar_of_edi_credit_limit_issue(edi_communication_log, msg: nil)
  sender = 'ediadmin@warmlyyours.com'
  recipient = 'ar@warmlyyours.com'
  @edi_communication_log = edi_communication_log
  @msg = msg
  mail(from: sender, to: recipient, subject: "EDI Order Could Not Be Processed Due To Credit Limit #{@edi_communication_log.partner} #{@edi_communication_log.category}")
end

#notify_ar_of_new_receipt_created_from_edi_log(receipt, msg: nil) ⇒ Mail::Message

Alerts accounts receivable that a receipt created from an EDI log needs
manual attention.

Parameters:

  • receipt (Receipt)

    the receipt requiring attention

  • msg (String, nil) (defaults to: nil)

    additional details

Returns:

  • (Mail::Message)

    the alert email



161
162
163
164
165
166
167
168
# File 'app/mailers/edi_mailer.rb', line 161

def notify_ar_of_new_receipt_created_from_edi_log(receipt, msg: nil)
  sender = 'ediadmin@warmlyyours.com'
  recipient = 'ar@warmlyyours.com'
  @receipt = receipt
  @customer = Customer.find(@receipt.customer_id)
  @msg = msg
  mail(from: sender, to: recipient, subject: "Manual attention required to Receipt #{@receipt.id}")
end

#notify_edi_admin_of_edi_cancel(order, msg = nil) ⇒ Mail::Message

Alerts the EDI admin of an EDI order cancellation.

Parameters:

  • order (Order)

    the cancelled order

  • msg (String, nil) (defaults to: nil)

    additional details

Returns:

  • (Mail::Message)

    the alert email



118
119
120
121
122
123
124
# File 'app/mailers/edi_mailer.rb', line 118

def notify_edi_admin_of_edi_cancel(order, msg = nil)
  sender = 'ediadmin@warmlyyours.com'
  recipient = 'ediadmin@warmlyyours.com'
  @order = order
  @msg = msg
  mail(from: sender, to: recipient, subject: "EDI Order Cancellation #{order.reference_number}")
end

#notify_edi_admin_of_error(edi_communication_log, msg: nil) ⇒ Mail::Message

Alerts the EDI admin of a processing error tied to a communication log.

Parameters:

  • edi_communication_log (EdiCommunicationLog)

    the failed log entry

  • msg (String, nil) (defaults to: nil)

    additional error details

Returns:

  • (Mail::Message)

    the alert email



67
68
69
70
71
72
73
# File 'app/mailers/edi_mailer.rb', line 67

def notify_edi_admin_of_error(edi_communication_log, msg: nil)
  sender = 'ediadmin@warmlyyours.com'
  recipient = 'ediadmin@warmlyyours.com'
  @edi_communication_log = edi_communication_log
  @msg = msg
  mail(from: sender, to: recipient, subject: "EDI Processing Error #{@edi_communication_log.partner} #{@edi_communication_log.category}")
end

#notify_edi_admin_of_menard_inventory_error(error_message, item_count: 0) ⇒ Mail::Message

Alerts the EDI admin that a Menard inventory upload failed.

Parameters:

  • error_message (String)

    the upload failure details

  • item_count (Integer) (defaults to: 0)

    number of items in the failed upload

Returns:

  • (Mail::Message)

    the alert email



131
132
133
134
135
136
137
# File 'app/mailers/edi_mailer.rb', line 131

def notify_edi_admin_of_menard_inventory_error(error_message, item_count: 0)
  sender = 'ediadmin@warmlyyours.com'
  recipient = 'ediadmin@warmlyyours.com'
  @error_message = error_message
  @item_count = item_count
  mail(from: sender, to: recipient, subject: 'Menard Inventory Upload Failed')
end

#notify_edi_admin_of_mirakl_error(partner, category, msg) ⇒ Mail::Message

Alerts the EDI admin of a Mirakl processing error.

Parameters:

  • partner (String)

    EDI partner key (e.g. +'leroymerlin_adeo'+)

  • category (String)

    EDI communication category (e.g. +'order_batch'+)

  • msg (String)

    error details

Returns:

  • (Mail::Message)

    the alert email



53
54
55
56
57
58
59
60
# File 'app/mailers/edi_mailer.rb', line 53

def notify_edi_admin_of_mirakl_error(partner, category, msg)
  sender = 'ediadmin@warmlyyours.com'
  recipient = 'ediadmin@warmlyyours.com'
  @partner = partner
  @category = category
  @msg = msg
  mail(from: sender, to: recipient, subject: "EDI Processing Error #{partner} #{category}")
end

#notify_edi_admin_of_order_status_mismatches(result) ⇒ Mail::Message

Alerts the EDI admin when Amazon order statuses diverge from Heatwave's.

Parameters:

  • result (Object)

    mismatch report responding to +partner+ and
    +mismatches+

Returns:

  • (Mail::Message)

    the alert email



80
81
82
83
84
85
86
# File 'app/mailers/edi_mailer.rb', line 80

def notify_edi_admin_of_order_status_mismatches(result)
  sender = 'ediadmin@warmlyyours.com'
  recipient = 'ediadmin@warmlyyours.com'
  @result = result
  mail(from: sender, to: recipient,
       subject: "Amazon Order Status Mismatch: #{result.partner}#{result.mismatches.size} order(s)")
end

#notify_edi_admin_of_warning(subj, msg) ⇒ Mail::Message

Sends a free-form processing warning to the EDI admin.

Parameters:

  • subj (String)

    warning subject

  • msg (String)

    warning details

Returns:

  • (Mail::Message)

    the warning email



93
94
95
96
97
98
# File 'app/mailers/edi_mailer.rb', line 93

def notify_edi_admin_of_warning(subj, msg)
  sender = 'ediadmin@warmlyyours.com'
  recipient = 'ediadmin@warmlyyours.com'
  @msg = msg
  mail(from: sender, to: recipient, subject: "EDI Processing Warning: #{subj}")
end

#notify_menard_of_pending_discontinue(catalog_item, discontinue_date:, recipients:) ⇒ Mail::Message

Sends Menard a pending-discontinue notice for a catalog item.

Parameters:

  • catalog_item (CatalogItem)

    the item pending discontinuation

  • discontinue_date (Date)

    the date the item will be discontinued

  • recipients (String, Array<String>)

    Menard-side recipient address(es)

Returns:

  • (Mail::Message)

    the notice email



145
146
147
148
149
150
151
152
153
# File 'app/mailers/edi_mailer.rb', line 145

def notify_menard_of_pending_discontinue(catalog_item, discontinue_date:, recipients:)
  sender = 'ediadmin@warmlyyours.com'
  @catalog_item = catalog_item
  @item = catalog_item.store_item.item
  @discontinue_date = discontinue_date
  @parent_sku = catalog_item.parent_sku
  @model_number = catalog_item.third_party_sku.presence || @item.sku
  mail(from: sender, to: recipients, subject: "WarmlyYours — Pending Discontinue Notice for #{@model_number}")
end