Class: Dscf::Marketplace::OrderSplittingService
- Inherits:
-
Object
- Object
- Dscf::Marketplace::OrderSplittingService
- Defined in:
- app/services/dscf/marketplace/order_splitting_service.rb
Class Method Summary collapse
-
.assign_source(order_item, source_type:, source_id:) ⇒ Object
Handles source assignment and the split operation per requirements.
-
.confirm_item(order, order_item, confirmed: true, reason: nil) ⇒ Object
Per-source confirmation (requirements doc: "Supplier and aggregator order confirmation").
- .perform_split(order) ⇒ Object
- .supplier_confirm(order, confirmed: true, reason: nil) ⇒ Object
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 |
.confirm_item(order, order_item, confirmed: true, reason: nil) ⇒ Object
Per-source confirmation (requirements doc: "Supplier and aggregator order confirmation"). The aggregator confirms each sub-supplier / aggregator-store allocation individually; other-supplier items are confirmed by that supplier. Once every item has responded (confirmed or cancelled), the order advances to retailer confirmation.
52 53 54 55 56 57 58 59 |
# File 'app/services/dscf/marketplace/order_splitting_service.rb', line 52 def self.confirm_item(order, order_item, confirmed: true, reason: nil) order_item.status = confirmed ? :confirmed : :cancelled order_item.save! order.reload order.mark_waiting_retailer_confirmation! if order.supplier_confirmation_complete? 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 |
# File 'app/services/dscf/marketplace/order_splitting_service.rb', line 33 def self.supplier_confirm(order, confirmed: true, reason: nil) if confirmed order.order_items.where(status: :processing).update_all(status: OrderItem.statuses[:confirmed]) 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 |