Class: Dscf::Marketplace::AggregatorListing
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Dscf::Marketplace::AggregatorListing
- Defined in:
- app/models/dscf/marketplace/aggregator_listing.rb
Class Method Summary collapse
- .ransackable_associations(_auth_object = nil) ⇒ Object
- .ransackable_attributes(_auth_object = nil) ⇒ Object
Instance Method Summary collapse
- #available? ⇒ Boolean
-
#confirming_business ⇒ Object
The real external business that should confirm an order line placed against this listing on their OWN business dashboard, if any.
-
#cost_price ⇒ Object
The aggregator's cost basis for this listing (nil for catalog — the aggregator sets a selling price directly with no upstream cost to compare against).
- #margin ⇒ Object
-
#product ⇒ Object
Resolves the catalogue product regardless of how the listing was sourced.
-
#source_label ⇒ Object
Human-readable name of who ultimately fulfils a line placed against this listing.
- #total_value ⇒ Object
Class Method Details
.ransackable_associations(_auth_object = nil) ⇒ Object
37 38 39 |
# File 'app/models/dscf/marketplace/aggregator_listing.rb', line 37 def self.ransackable_associations(_auth_object = nil) %w[aggregator supplier_product product sub_supplier_product] end |
.ransackable_attributes(_auth_object = nil) ⇒ Object
33 34 35 |
# File 'app/models/dscf/marketplace/aggregator_listing.rb', line 33 def self.ransackable_attributes(_auth_object = nil) %w[id aggregator_id supplier_product_id product_id sub_supplier_product_id source_kind price quantity status created_at updated_at] end |
Instance Method Details
#available? ⇒ Boolean
89 90 91 |
# File 'app/models/dscf/marketplace/aggregator_listing.rb', line 89 def available? active? && quantity > 0 end |
#confirming_business ⇒ Object
The real external business that should confirm an order line placed against this listing on their OWN business dashboard, if any. Only meaningful for :supplier — that business is a genuine third party, unambiguously distinct from the aggregator. :catalog has no external party (the aggregator fulfils it) and :sub_supplier's business is offline/has no login (requirements doc: sub-suppliers "don't act directly on the system"), so both stay aggregator-managed (nil here).
85 86 87 |
# File 'app/models/dscf/marketplace/aggregator_listing.rb', line 85 def confirming_business supplier_product&.business if supplier? end |
#cost_price ⇒ Object
The aggregator's cost basis for this listing (nil for catalog — the aggregator sets a selling price directly with no upstream cost to compare against).
52 53 54 55 56 57 |
# File 'app/models/dscf/marketplace/aggregator_listing.rb', line 52 def cost_price case source_kind when "supplier" then supplier_product&.supplier_price when "sub_supplier" then sub_supplier_product&.sub_supplier_price end end |
#margin ⇒ Object
59 60 61 62 |
# File 'app/models/dscf/marketplace/aggregator_listing.rb', line 59 def margin return nil unless cost_price price - cost_price end |
#product ⇒ Object
Resolves the catalogue product regardless of how the listing was sourced.
42 43 44 45 46 47 48 |
# File 'app/models/dscf/marketplace/aggregator_listing.rb', line 42 def product case source_kind when "supplier" then supplier_product&.product when "sub_supplier" then sub_supplier_product&.product else super end end |
#source_label ⇒ Object
Human-readable name of who ultimately fulfils a line placed against this listing. An order line is auto-sourced to the AggregatorListing itself, so this drives the "Product source name" the requirements ask for:
catalog -> the aggregator (self-fulfilled)
supplier -> the supplier's business name
sub_supplier -> the sub-supplier's business name
70 71 72 73 74 75 76 |
# File 'app/models/dscf/marketplace/aggregator_listing.rb', line 70 def source_label case source_kind when "supplier" then supplier_product&.business&.name when "sub_supplier" then sub_supplier_product&.sub_supplier&.business_name else aggregator&.name end end |
#total_value ⇒ Object
93 94 95 |
# File 'app/models/dscf/marketplace/aggregator_listing.rb', line 93 def total_value price * quantity end |