Class: Edi::Menard::InventoryMessageProcessor

Inherits:
BaseEdiService show all
Defined in:
app/services/edi/menard/inventory_message_processor.rb

Overview

Service object: inventory message processor.

Constant Summary collapse

VENDOR_NUMBER =

Vendor number.

Edi::Menard::Orchestrator::VENDOR_NUMBER
HEADER_ROW =

Header row.

2
DATA_START_ROW =

Data start row.

3
DEFAULT_RESTOCK_LEAD_TIME =

Default restock lead time.

3.months
HEADERS =

Headers.

[
  'Sku#',
  'Menard Inc. Sales Unit',
  'Model#',
  'Item Description',
  'Qty on Hand',
  'Date when back in stock (YYYY/MM/DD)',
  'QTY to be available when back in stock',
  'Status',
  'Discontinued Date (YYYY/MM/DD)'
].freeze

Constants included from AddressAbbreviator

AddressAbbreviator::MAX_LENGTH

Instance Attribute Summary

Attributes inherited from BaseEdiService

#orchestrator

Attributes inherited from BaseService

#options

Instance Method Summary collapse

Methods inherited from BaseEdiService

#duplicate_po_already_notified?, #initialize, #mark_duplicate_po_as_notified, #report_order_creation_issues, #safe_process_edi_communication_log

Methods included from AddressAbbreviator

#abbreviate_street, #collect_street_originals, #record_address_abbreviation_notes

Methods inherited from BaseService

#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #tagged_logger

Constructor Details

This class inherits a constructor from Edi::BaseEdiService

Instance Method Details

#generate_preview_workbook(catalog_items) ⇒ Object



75
76
77
# File 'app/services/edi/menard/inventory_message_processor.rb', line 75

def generate_preview_workbook(catalog_items)
  build_workbook(catalog_items)
end

#load_catalog_itemsObject



66
67
68
69
70
71
72
73
# File 'app/services/edi/menard/inventory_message_processor.rb', line 66

def load_catalog_items
  base = orchestrator.customer.catalog.catalog_items
  base
    .where(state: %w[active pending_discontinue])
    .joins(store_item: :item)
    .includes(store_item: :item)
    .order('items.sku')
end

#process(catalog_items: nil, triggered_by: 'scheduled') ⇒ Object



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
# File 'app/services/edi/menard/inventory_message_processor.rb', line 31

def process(catalog_items: nil, triggered_by: 'scheduled')
  logger.info "Creating inventory feed for partner #{orchestrator.partner}"
  catalog_items ||= load_catalog_items
  return :empty_set if catalog_items.blank?

  catalog_items = catalog_items.to_a
  file_path = generate_spreadsheet(catalog_items)

  ecl = nil
  EdiCommunicationLog.transaction do
    ecl = EdiCommunicationLog.create!(
      partner: orchestrator.partner.to_s,
      state: 'ready',
      file_name: File.basename(file_path),
      category: 'inventory_advice',
      data: build_summary_csv(catalog_items),
      data_type: 'csv',
      file_info: {
        triggered_by: triggered_by,
        item_count: catalog_items.size,
        vendor_number: VENDOR_NUMBER,
        catalog_id: orchestrator.catalog_id
      }
    )
    catalog_items.each do |ci|
      ecl.edi_documents.create!(resource: ci)
    end

    attach_spreadsheet(ecl, file_path)
  end

  cleanup_file(file_path)
  ecl
end