Class: Edi::Houzz::InventoryMessageProcessor
- Inherits:
-
BaseEdiService
- Object
- BaseService
- BaseEdiService
- Edi::Houzz::InventoryMessageProcessor
- Defined in:
- app/services/edi/houzz/inventory_message_processor.rb
Constant Summary
Constants included from AddressAbbreviator
AddressAbbreviator::MAX_LENGTH
Instance Attribute Summary
Attributes inherited from BaseEdiService
Instance Method Summary collapse
- #build_csv(catalog_items: nil, states: nil) ⇒ Object
- #catalog_item_to_csv_row(ci) ⇒ Object
- #load_catalog_items(states: nil, use_delta_since_last_message: nil) ⇒ Object
- #process(catalog_items: nil, states: nil, inventory_updated_since: nil) ⇒ Object
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, #options, #tagged_logger
Constructor Details
This class inherits a constructor from Edi::BaseEdiService
Instance Method Details
#build_csv(catalog_items: nil, states: nil) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'app/services/edi/houzz/inventory_message_processor.rb', line 43 def build_csv(catalog_items: nil, states: nil) logger.info "#{catalog_items.size} items in inventory payload" CSV.generate(force_quotes: true) do |csv| csv << %w[SupplierSKU Quantity] catalog_items.each do |ci| csv << catalog_item_to_csv_row(ci) end end end |
#catalog_item_to_csv_row(ci) ⇒ Object
53 54 55 56 57 58 |
# File 'app/services/edi/houzz/inventory_message_processor.rb', line 53 def catalog_item_to_csv_row(ci) row = [] row << ci.reported_vendor_sku # SupplierSKU row << ci.reported_stock(use_alternate_warehouse: false) # Quantity row end |
#load_catalog_items(states: nil, use_delta_since_last_message: nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/services/edi/houzz/inventory_message_processor.rb', line 25 def load_catalog_items(states: nil, use_delta_since_last_message: nil) states ||= %w[active require_vendor_update pending_vendor_update pending_discontinue] catalog_item_ids = [] orchestrator.customers.each do |customer| catalog_items = customer.catalog.catalog_items.where(state: states).not_hidden_from_catalog # When our catalog requires third party part number, do not grab those catalog items without one catalog_items = catalog_items.where.not(third_party_part_number: nil) if customer.catalog.third_party_part_number_required catalog_items = catalog_items.where('third_party_sku ~ ?', customer.catalog.third_party_sku_filter_regex) if customer.catalog.is_active_third_party_sku_filter catalog_item_ids += catalog_items.pluck(:id) end catalog_items = CatalogItem.where(id: catalog_item_ids.uniq) .with_item .eager_load(:store_item, :item) .order(Item[:sku]) catalog_items = catalog_items.edi_delta_feeds_for_partner_inventory_advice(orchestrator.partner) if && catalog_items end |
#process(catalog_items: nil, states: nil, inventory_updated_since: nil) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/services/edi/houzz/inventory_message_processor.rb', line 5 def process(catalog_items: nil, states: nil, inventory_updated_since: nil) ecl = nil EdiCommunicationLog.transaction do logger.info "Creating inventory advice for partner #{orchestrator.partner}" catalog_items ||= load_catalog_items(states:, use_delta_since_last_message: true) if catalog_items.any? data = build_csv(catalog_items: catalog_items, states: states) ecl = EdiCommunicationLog.create_outbound_file_from_data( data: data, file_extension: 'inv', partner: orchestrator.partner, category: 'inventory_advice', resources: catalog_items, file_info: {} ) end end ecl end |