Class: Menard::InventorySpreadsheetGenerator

Inherits:
Object
  • Object
show all
Defined in:
app/services/menard/inventory_spreadsheet_generator.rb

Defined Under Namespace

Classes: Result

Constant Summary collapse

CATALOG_ID =
192
VENDOR_NUMBER =
'WARML001'
HEADER_ROW =
2
DATA_START_ROW =
3
DEFAULT_RESTOCK_LEAD_TIME =
3.months
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

Instance Method Summary collapse

Constructor Details

#initialize(catalog: nil, output_path: nil) ⇒ InventorySpreadsheetGenerator

Returns a new instance of InventorySpreadsheetGenerator.



30
31
32
33
# File 'app/services/menard/inventory_spreadsheet_generator.rb', line 30

def initialize(catalog: nil, output_path: nil)
  @catalog = catalog || Catalog.find(CATALOG_ID)
  @output_path = output_path || default_output_path
end

Instance Method Details

#callObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/services/menard/inventory_spreadsheet_generator.rb', line 35

def call
  catalog_items = eligible_catalog_items.to_a
  workbook = build_workbook(catalog_items)
  workbook.write(@output_path)

  Result.new(
    file_path: @output_path,
    catalog_items_count: catalog_items.size,
    messages: build_messages(catalog_items)
  )
rescue StandardError => e
  Rails.logger.error("[Menard::InventorySpreadsheetGenerator] #{e.class}: #{e.message}")
  Result.new(file_path: nil, catalog_items_count: 0, messages: [e.message])
end