Class: Maintenance::PriceUpdateFromSpreadsheet

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/maintenance/price_update_from_spreadsheet.rb

Instance Method Summary collapse

Methods inherited from BaseService

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

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#process(path = nil) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/maintenance/price_update_from_spreadsheet.rb', line 2

def process(path = nil)
  require 'roo'
  path ||= '/Users/cbillen/Desktop/TWPricing_072024.xlsx'
  xlsx = Roo::Spreadsheet.open(path)
  rows = xlsx.sheet(0).each.to_a
  # [0] "TW-SUM08KS-HP",
  # [1] 40,
  # [2] 850,
  # [3] 40,
  # [4] 1310,
  # [5] 5,
  # [6] 552.5,
  # [7] 5,
  # [8] 851.5
  PaperTrail.request(whodunnit: 101) do
    CatalogItem.transaction do
      rows[2..].each do |row|
        sku, max_discount_usa, price_usa, max_discount_can, price_can, amz_usa_max_discount, amz_usa_price, amz_can_max_discount, amz_can_price = row
        update_catalog_item(1, sku, max_discount_usa, price_usa)
        update_catalog_item(2, sku, max_discount_can, price_can)
        update_catalog_item(74, sku, amz_usa_max_discount, amz_usa_price)
        update_catalog_item(17, sku, amz_can_max_discount, amz_can_price)
      end
    end
  end
end

#update_catalog_item(catalog_id, sku, max_discount, amount) ⇒ Object



29
30
31
32
33
# File 'app/services/maintenance/price_update_from_spreadsheet.rb', line 29

def update_catalog_item(catalog_id, sku, max_discount, amount)
  return unless ci = CatalogItem.where(catalog_id: catalog_id).by_skus(sku).first

  ci.update!(max_discount: max_discount, amount: amount)
end