Class: Dscf::Marketplace::OrderSplittingService

Inherits:
Object
  • Object
show all
Defined in:
app/services/dscf/marketplace/order_splitting_service.rb

Class Method Summary collapse

Class Method Details

.assign_source(order_item, source_type:, source_id:) ⇒ Object

Handles source assignment and the split operation per requirements. Sources can be:

  • Aggregator self (via aggregator listing or direct)

  • Sub-supplier

  • Other supplier



10
11
12
13
14
15
# File 'app/services/dscf/marketplace/order_splitting_service.rb', line 10

def self.assign_source(order_item, source_type:, source_id:)
  order_item.source_type = source_type
  order_item.source_id = source_id
  order_item.save!
  order_item
end

.perform_split(order) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/services/dscf/marketplace/order_splitting_service.rb', line 17

def self.perform_split(order)
  raise "Cannot split order that is not ready" unless order.all_items_validated?

  # Mark items ready for source assignment / supplier confirmation
  order.order_items.each do |item|
    if item.status.to_s == "pending" || item.status.to_s == "confirmed"
      item.status = :processing
    end
    item.save! if item.changed?
  end

  order.mark_waiting_supplier_confirmation!

  order
end

.supplier_confirm(order, confirmed: true, reason: nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/services/dscf/marketplace/order_splitting_service.rb', line 33

def self.supplier_confirm(order, confirmed: true, reason: nil)
  if confirmed
    # In full impl, mark specific allocation as confirmed
    # For now advance whole if appropriate
  else
    order.order_items.where(status: :processing).update_all(status: OrderItem.statuses[:cancelled])
  end

  # Check if supplier side is done
  if order.supplier_confirmation_complete?
    order.mark_waiting_retailer_confirmation!
  end
  order
end