Class: ViewInventoryPlan
- Inherits:
-
ApplicationViewRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ApplicationViewRecord
- ViewInventoryPlan
- Includes:
- Models::SearchableView
- Defined in:
- app/models/view_inventory_plan.rb
Overview
== Schema Information
Table name: view_inventory_plans
Database name: primary
id :bigint primary key
avg_lead_time :decimal(, )
backorder_ca :decimal(, )
backorder_combined :decimal(, )
backorder_us :decimal(, )
daily_sales_avg_ca :float
daily_sales_avg_combined :float
daily_sales_avg_us :float
domestic :boolean
item_name :string(255)
item_sku :string
last_refreshed_at :timestamptz
lead_time :integer
lead_time_demand_16_ca :decimal(, )
lead_time_demand_16_ca_st :decimal(, )
lead_time_demand_16_combined :decimal(, )
lead_time_demand_16_us :decimal(, )
lead_time_demand_52_ca :decimal(, )
lead_time_demand_52_ca_st :decimal(, )
lead_time_demand_52_combined :decimal(, )
lead_time_demand_52_us :decimal(, )
lead_time_demand_average_ca :decimal(, )
lead_time_demand_average_ca_st :decimal(, )
lead_time_demand_average_combined :decimal(, )
lead_time_demand_average_us :decimal(, )
lead_time_st :integer
max_lead_time :integer
min_lead_time :integer
po_in_transit_ca :bigint
po_in_transit_combined :bigint
po_in_transit_us :bigint
product_category_ids :integer is an Array
product_line_ids :integer is an Array
qty_on_hand_ca :integer
qty_on_hand_combined :bigint
qty_on_hand_us :integer
reorder_amount_ca :float
reorder_amount_ca_st :float
reorder_amount_combined :float
reorder_amount_us :float
reorder_date_ca :date
reorder_date_ca_st :date
reorder_date_combined :date
reorder_date_us :date
reorder_point_ca :float
reorder_point_ca_st :float
reorder_point_combined :float
reorder_point_us :float
reorder_safety_stock_ca :float
reorder_safety_stock_ca_st :float
reorder_safety_stock_combined :float
reorder_safety_stock_us :float
replacement_for_sku :string
safety_stock_ca :float
safety_stock_ca_st :float
safety_stock_combined :float
safety_stock_days_ca :integer
safety_stock_days_us :integer
safety_stock_fixed_ca :integer
safety_stock_fixed_us :integer
safety_stock_percentage_ca :decimal(, )
safety_stock_percentage_us :decimal(, )
safety_stock_us :float
st_in_transit_ca :bigint
st_in_transit_combined :bigint
st_in_transit_us :bigint
status_ca :text
status_ca_st :text
status_combined :text
status_us :text
stock_depletion_date_ca :date
stock_depletion_date_combined :date
stock_depletion_date_us :date
supplier_lead_time :integer
supplier_lead_time_override :integer
supplier_linked :boolean
supplier_name :string(255)
total_stock_ca :decimal(, )
total_stock_combined :decimal(, )
total_stock_us :decimal(, )
item_id :integer
supplier_id :integer
Indexes
index_view_inventory_plans_on_id (id) UNIQUE
index_view_inventory_plans_on_supplier_linked (supplier_linked)
Has many collapse
- #item_demand_facts ⇒ ActiveRecord::Relation<Analytic::ItemDemandFact>
- #item_demand_forecasts ⇒ ActiveRecord::Relation<ItemDemandForecast>
Class Method Summary collapse
Instance Method Summary collapse
Methods included from Models::SearchableView
#crm_link, #crm_link_subtitle, #has_columns?, #main_resource, #readonly?
Methods inherited from ApplicationViewRecord
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::EventPublishable
Class Method Details
.last_refreshed_at ⇒ Object
100 101 102 |
# File 'app/models/view_inventory_plan.rb', line 100 def self.last_refreshed_at ViewInventoryPlan.order(:item_sku).first&.last_refreshed_at end |
.refresh ⇒ Object
104 105 106 |
# File 'app/models/view_inventory_plan.rb', line 104 def self.refresh Scenic.database.refresh_materialized_view(table_name, concurrently: true, cascade: false) end |
Instance Method Details
#item_demand_facts ⇒ ActiveRecord::Relation<Analytic::ItemDemandFact>
97 |
# File 'app/models/view_inventory_plan.rb', line 97 has_many :item_demand_facts, class_name: 'Analytic::ItemDemandFact', foreign_key: :item_id, primary_key: :item_id |
#item_demand_forecasts ⇒ ActiveRecord::Relation<ItemDemandForecast>
98 |
# File 'app/models/view_inventory_plan.rb', line 98 has_many :item_demand_forecasts, foreign_key: :item_id, primary_key: :item_id |
#safety_stock_method_ca ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/models/view_inventory_plan.rb', line 120 def safety_stock_method_ca if safety_stock_fixed_ca "#{safety_stock_fixed_ca} (fixed)" elsif safety_stock_days_ca "#{safety_stock_days_ca} days (avg daily sales: #{daily_sales_avg_ca.round(2)})" elsif safety_stock_percentage_ca "#{safety_stock_percentage_ca}% (of lead time demand)" else "50% (of lead time demand)" end end |
#safety_stock_method_us ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 |
# File 'app/models/view_inventory_plan.rb', line 108 def safety_stock_method_us if safety_stock_fixed_us "#{safety_stock_fixed_us} (fixed)" elsif safety_stock_days_us "#{safety_stock_days_us} days (avg daily sales: #{daily_sales_avg_us.round(2)})" elsif safety_stock_percentage_us "#{safety_stock_percentage_us}% (of lead time demand)" else "50% (of lead time demand)" end end |