Class: InventoryMailer

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

Overview

Inventory / catalog: stock, reorder, cycle-count, price-change alerts.

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

#catalog_price_changes_alert(main_catalogs, other_catalogs) ⇒ Mail::Message

Daily digest of catalog price changes (WarmlyYours catalogs only).

Parameters:

  • main_catalogs (Array<Hash>)

    rows for the main catalogs

  • other_catalogs (Array<Hash>)

    rows for remaining catalogs

Returns:

  • (Mail::Message)


154
155
156
157
158
159
160
161
# File 'app/mailers/inventory_mailer.rb', line 154

def catalog_price_changes_alert(main_catalogs, other_catalogs)
  @main_catalogs = main_catalogs
  @other_catalogs = other_catalogs
  mail(from: ADMINISTRATOR_EMAIL,
       to: 'pricechangealerts@warmlyyours.com',
       cc: 'heatwaveteam@warmlyyours.com',
       subject: 'Catalog Price Changes')
end

#cycle_counts_due(store) ⇒ Mail::Message

Draft warehouse cycle counts that are due for the given store.

Parameters:

  • store (Store)

    the warehouse whose draft cycle counts to report

Returns:

  • (Mail::Message)


36
37
38
39
40
41
42
# File 'app/mailers/inventory_mailer.rb', line 36

def cycle_counts_due(store)
  @cycle_counts = store.cycle_counts.where(state: 'draft', marketing_only: false)

  mail(from: 'Heatwave Team <heatwaveteam@warmlyyours.com>',
       to: store.id == 2 ? 'warehousecanada@warmlyyours.com' : 'warehouseusa@warmlyyours.com',
       subject: 'You Have Inventory Cycle Counts Due')
end

#empty_promised_date_reminder(po_items) ⇒ Mail::Message

Reminds AP of PO lines missing a promised date.

Parameters:

Returns:

  • (Mail::Message)

    the reminder, or a null mail when po_items is blank



103
104
105
106
107
108
109
110
# File 'app/mailers/inventory_mailer.rb', line 103

def empty_promised_date_reminder(po_items)
  return null_mail if po_items.blank?

  @po_items = po_items.group_by(&:purchase_order)
  mail(from: "Accounts Payable <#{ACCOUNTS_PAYABLE_EMAIL}>",
       to: ACCOUNTS_PAYABLE_EMAIL,
       subject: 'POs With Empty Promised Date Found')
end

#inventory_adjustment_notification(item_ledger_entries) ⇒ Mail::Message

Alerts AP of inventory adjustments.

Parameters:

Returns:

  • (Mail::Message)

    the alert, or a null mail when the list is empty



75
76
77
78
79
80
81
82
83
84
# File 'app/mailers/inventory_mailer.rb', line 75

def inventory_adjustment_notification(item_ledger_entries)
  item_ledger_entries = [item_ledger_entries].flatten.compact.uniq

  return null_mail if item_ledger_entries.blank?

  @item_ledger_entries = item_ledger_entries
  mail(from: 'Heatwave Team <heatwaveteam@warmlyyours.com>',
       to: 'ap@warmlyyours.com',
       subject: 'Inventory adjustment alert')
end

#inventory_commit_expiration_notification(resource) ⇒ Mail::Message

Notifies the sales rep that an inventory reservation has expired.

Parameters:

  • resource (Quote, Order)

    the reserved document whose hold expired

Returns:

  • (Mail::Message)


60
61
62
63
64
65
66
67
68
69
# File 'app/mailers/inventory_mailer.rb', line 60

def inventory_commit_expiration_notification(resource)
  @resource = resource
  @resource_class = resource.class.to_s
  @customer = @resource.customer
  @rep = @customer.primary_sales_rep

  mail(from: 'Heatwave Team <heatwaveteam@warmlyyours.com>',
       to: @rep.present? ? @rep.email_with_name : 'orders@warmlyyours.com',
       subject: "#{@resource_class} #{@resource.reference_number} inventory reservation has expired")
end

#inventory_reorder_reminder(records) ⇒ Mail::Message

Reminds AP of items that need replenishment.

Parameters:

  • records (Array)

    reorder rows to list

Returns:

  • (Mail::Message)

    the reminder, or a null mail when records is blank



90
91
92
93
94
95
96
97
# File 'app/mailers/inventory_mailer.rb', line 90

def inventory_reorder_reminder(records)
  return null_mail if records.blank?

  @records = records
  mail(from: "Accounts Payable <#{ACCOUNTS_PAYABLE_EMAIL}>",
       to: ACCOUNTS_PAYABLE_EMAIL,
       subject: 'Stock Replenishment Reminder')
end

#items_need_packaging_review_notification(item_ids) ⇒ Mail::Message

Asks the warehouses to review item weights/packaging.

Parameters:

  • item_ids (Array<Integer>)

    item ids that need review

Returns:

  • (Mail::Message)

    the notice, or a null mail when no items match



167
168
169
170
171
172
173
174
# File 'app/mailers/inventory_mailer.rb', line 167

def items_need_packaging_review_notification(item_ids)
  @items = Item.where(id: item_ids)
  return null_mail if @items.blank?

  mail(from: 'Heatwave Team <heatwaveteam@warmlyyours.com>',
       to: 'warehouseusa@warmlyyours.com, warehousecanada@warmlyyours.com',
       subject: 'Items that need weight review')
end

#marketing_cycle_counts_due(store) ⇒ Mail::Message

Draft marketing-only cycle counts that are due for the given store.

Parameters:

  • store (Store)

    the warehouse whose marketing cycle counts to report

Returns:

  • (Mail::Message)


48
49
50
51
52
53
54
# File 'app/mailers/inventory_mailer.rb', line 48

def marketing_cycle_counts_due(store)
  @cycle_counts = store.cycle_counts.where(state: 'draft', marketing_only: true)

  mail(from: 'Heatwave Team <heatwaveteam@warmlyyours.com>',
       to: store.id == 2 ? 'warehousecanada@warmlyyours.com' : 'marketingcyclecounts@warmlyyours.com',
       subject: "You Have Marketing Inventory Cycle Counts Due For #{store.name}")
end

#past_promised_date_reminder(store, po_items) ⇒ Mail::Message

Reminds AP and the warehouse of PO lines past their promised date.

Parameters:

  • store (Store)

    warehouse used to pick the warehouse inbox

  • po_items (Array<PurchaseOrderItem>)

    overdue lines

Returns:

  • (Mail::Message)

    the reminder, or a null mail when po_items is blank



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'app/mailers/inventory_mailer.rb', line 117

def past_promised_date_reminder(store, po_items)
  return null_mail if po_items.blank?

  @store = store
  @po_items = po_items.group_by(&:purchase_order)

  warehouse_email = if store.id == 1
                      'warehouseusa@warmlyyours.com'
                    elsif store.id == 2
                      'warehousecanada@warmlyyours.com'
                    end
  mail(from: "Accounts Payable <#{ACCOUNTS_PAYABLE_EMAIL}>",
       to: "#{ACCOUNTS_PAYABLE_EMAIL},#{warehouse_email}",
       subject: "POs Past Promised Date Found (#{store.name})")
end

#price_changed_alert(changes) ⇒ Mail::Message

Reports scheduled catalog-item price changes.

Called by CatalogItem::ScheduledPriceChanger.

Parameters:

  • changes (Array)

    price-change rows

Returns:

  • (Mail::Message)

    the alert, or a null mail when changes is blank



139
140
141
142
143
144
145
146
147
# File 'app/mailers/inventory_mailer.rb', line 139

def price_changed_alert(changes)
  @changes = changes
  return null_mail if @changes.blank?

  mail(from: ADMINISTRATOR_EMAIL,
       to: 'price_alerts@warmlyyours.com',
       cc: 'heatwaveteam@warmlyyours.com',
       subject: 'Price Change Alert')
end

#promo_item_sync_notification(results) ⇒ Mail::Message

Reports coupon promo-item sync results.

Parameters:

  • results (Array)

    per-coupon sync rows

Returns:

  • (Mail::Message)

    the digest, or a null mail when results is blank



180
181
182
183
184
185
186
187
# File 'app/mailers/inventory_mailer.rb', line 180

def promo_item_sync_notification(results)
  return null_mail if results.blank?

  @results = results
  mail(from: 'Heatwave Team <heatwaveteam@warmlyyours.com>',
       to: 'Heatwave Team <heatwaveteam@warmlyyours.com>',
       subject: "Promo Item Sync Results #{I18n.l(Date.current, format: :long)}")
end

#store_item_availability_timed_update(results, destination) ⇒ Mail::Message?

Availability-date changes for publications or other store items.

Parameters:

  • results (Array)

    rows to list in the email

  • destination (Symbol)

    :publications or :non_publications

Returns:

  • (Mail::Message, nil)

    the email, or nil when destination is unrecognized



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/mailers/inventory_mailer.rb', line 14

def store_item_availability_timed_update(results, destination)
  @results = results

  if destination == :publications
    @title = 'Publication Status Changes'
    mail(from: 'Heatwave Team <heatwaveteam@warmlyyours.com>',
         to: 'cwitbeck@warmlyyours.com,pgammeri@warmlyyours.com',
         cc: 'cbillen@warmlyyours.com',
         subject: 'Publication Availability Updates')
  elsif destination == :non_publications
    @title = 'Store Item Status Changes'
    mail(from: 'Heatwave Team <heatwaveteam@warmlyyours.com>',
         to: 'vadepu@warmlyyours.com',
         cc: 'cbillen@warmlyyours.com',
         subject: 'Store Item Availability Updates')
  end
end