Class: Edi::AmazonVc::PackingSlipProcessor
- Inherits:
-
BaseEdiService
- Object
- BaseService
- BaseEdiService
- Edi::AmazonVc::PackingSlipProcessor
- Defined in:
- app/services/edi/amazon_vc/packing_slip_processor.rb
Overview
Service object: packing slip processor.
Constant Summary
Constants included from RequestIdentifiable
RequestIdentifiable::REQUEST_ID_HEADERS
Constants included from Edi::AddressAbbreviator
Edi::AddressAbbreviator::MAX_LENGTH
Instance Attribute Summary
Attributes inherited from BaseEdiService
Attributes inherited from BaseService
Instance Method Summary collapse
- #find_order(po_number) ⇒ Object
- #process(edi_communication_logs = nil) ⇒ Object
- #process_communication_log(ecl) ⇒ Object
Methods inherited from BaseEdiService
#amazon_feed_product_type, #duplicate_po_already_notified?, #initialize, #mark_duplicate_po_as_notified, #onboard_ordered_catalog_items, #report_order_creation_issues, #safe_process_edi_communication_log
Methods included from RequestIdentifiable
Methods included from Edi::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
#find_order(po_number) ⇒ Object
46 47 48 49 50 51 |
# File 'app/services/edi/amazon_vc/packing_slip_processor.rb', line 46 def find_order(po_number) Order.joins(:customer) .merge(orchestrator.customers) .sales_orders.order('orders.created_at desc') .where(edi_po_number: po_number).first end |
#process(edi_communication_logs = nil) ⇒ Object
7 8 9 10 11 12 |
# File 'app/services/edi/amazon_vc/packing_slip_processor.rb', line 7 def process(edi_communication_logs = nil) edi_communication_logs ||= EdiCommunicationLog.where(state: 'ready', category: 'packing_slip', partner: orchestrator.partner) [edi_communication_logs].flatten.each do |ecl| safe_process_edi_communication_log ecl end end |
#process_communication_log(ecl) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/services/edi/amazon_vc/packing_slip_processor.rb', line 14 def process_communication_log(ecl) return unless ecl.ready? && ecl.category == 'packing_slip' EdiCommunicationLog.transaction do unless ecl.uploads.any? # No `error!` here — same reason as the CommerceHub twin: the raise # rolls this transaction back, so it never persists and only poisons # the in-memory state the rescue needs. msg = "Could not find uploads for edi communication log #{ecl.id}" logger.error msg raise msg end ecl.uploads.each do |u| po_number = u..split('_packing_slip.pdf').first if po_number.present? && (order = find_order(po_number)) logger.info "Found order #{order.reference_number}, cloning pdf" new_u = Upload.uploadify(u..path, 'custom_packing_slip_pdf', order) new_u.save! ecl.edi_documents.create(order: order, note: 'packing list') ecl.complete # We can try releasing the order order.release_order else msg = "Cannot match to order with PO number: #{po_number}." logger.error msg ecl.notes = msg ecl.error! end end end end |