Class: Store

Inherits:
ApplicationRecord show all
Includes:
Models::Auditable
Defined in:
app/models/store.rb

Overview

== Schema Information

Table name: stores
Database name: primary

id :integer not null, primary key
base_handling_charge :decimal(8, 2)
contact_email :string(255)
contact_number :string(255)
country_iso3 :string(3)
fax_number :string(255)
jde_branch :string(255)
name :string(255)
order_notification_emails :string default([]), is an Array
owner :string
short_name :string(255)
tax_identification_number_for_shipping :string(255)
warehouse_email :string
company_id :integer
consignee_party_id :integer
customer_for_st_id :integer
mailing_address_id :integer
preferred_inbound_shipping_option_id :integer
preferred_outbound_shipping_option_id :integer
primary_catalog_id :integer
supplier_id :integer
warehouse_address_id :integer
warehouse_service_address_id :integer

Indexes

idx_country_iso3 (country_iso3)
idx_owner (owner)
index_stores_on_company_id (company_id)
index_stores_on_supplier_id (supplier_id)

Foreign Keys

fk_rails_... (consignee_party_id => parties.id)
fk_rails_... (customer_for_st_id => parties.id)
fk_rails_... (supplier_id => parties.id)

Constant Summary collapse

WARMLYYOURS_US_ID =

= Store.find(1)

1
WARMLYYOURS_CA_ID =

= Store.find(2)

2
PUBLIC_STORE_IDS =

Public store ids.

[WARMLYYOURS_US_ID, WARMLYYOURS_CA_ID].freeze
STORE_TO_LOCALE =

Store to locale.

{ 'WarmlyYours-US' => :'en-US', 'WarmlyYours-CA' => :'en-CA' }.freeze
LOCALE_TO_STORE =

Locale to store.

{
  en: 'WarmlyYours-US',
  'en-US': 'WarmlyYours-US',
  'en-CA': 'WarmlyYours-CA',
  'fr-CA': 'WarmlyYours-CA'
}.freeze
LOCALE_TO_STORE_ID =

Locale to store id.

{
  en: 1,
  'en-US': 1,
  'en-CA': 2,
  'fr-CA': 2
}.freeze
CURRENCY_TO_STORE =

Currency to store.

{ 'USD' => 'WarmlyYours-US', 'CAD' => 'WarmlyYours-CA' }.freeze
CARRIERS_FOR_MASS_SHIP_CONFIRM =

Carriers for mass ship confirm.

{ 'WarmlyYours-US' => %w[FedExGround FedExExpress FedExFreight UPS USPS],
'WarmlyYours-CA' => %w[FedExGround FedExExpress FedExFreight UPS Canadapost Canpar Purolator] }.freeze
CARRIER_PICKUP_TIMES =

Carrier pickup times.

{
  'WarmlyYours-US' => { 'FedExGround' => '16:30:00', 'FedExExpress' => '16:00:00', 'FedExFreight' => '17:00:00', 'UPS' => '17:30:00',
                        'USPS' => '14:00:00' }, 'WarmlyYours-CA' => { 'FedExGround' => '14:00:00', 'FedExFreight' => '17:00:00', 'UPS' => '16:00:00', 'Purolator' => '15:30:00', 'Canadapost' => '15:30:00', 'Canpar' => '14:30:00' }
}.freeze
CARRIER_PICKUP_CUT_OFF_TIMES =

Carrier pickup cut off times.

{ 'WarmlyYours-US' => { 'FedExFreight' => '12:00:00', 'ShipengineSaia' => '14:00:00', 'USPS' => '14:55:00' },
                                   'WarmlyYours-CA' => { 'FedEx' => '14:00:00', 'FedExFreight' => '12:00:00', 'Canadapost' => '14:55:00',
'Canpar' => '10:55:00' } }.freeze

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Constants included from Schedulable

Schedulable::SIMPLE_FORM_OPTIONS

Instance Attribute Summary collapse

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Has one collapse

Has many collapse

Has and belongs to many collapse

Delegated Instance Attributes collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Models::Auditable

#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#company_idObject (readonly)



120
# File 'app/models/store.rb', line 120

validates :company_id, :name, :country_iso3, :warehouse_address, presence: true

#contact_emailObject (readonly)



123
# File 'app/models/store.rb', line 123

validates :contact_email, email_format: true

#contact_numberObject (readonly)



125
# File 'app/models/store.rb', line 125

validates :contact_number, phone_format: true

#country_iso3Object (readonly)



120
# File 'app/models/store.rb', line 120

validates :company_id, :name, :country_iso3, :warehouse_address, presence: true

#nameObject (readonly)



120
# File 'app/models/store.rb', line 120

validates :company_id, :name, :country_iso3, :warehouse_address, presence: true

#order_notification_emailsObject (readonly)



122
# File 'app/models/store.rb', line 122

validates :order_notification_emails, email_format: true

#short_nameObject (readonly)



121
# File 'app/models/store.rb', line 121

validates :name, :short_name, uniqueness: true

#warehouse_emailObject (readonly)



124
# File 'app/models/store.rb', line 124

validates :warehouse_email, email_format: true, allow_blank: true

Class Method Details

.by_currency(currency) ⇒ Object

Todo make this more I18n



189
190
191
# File 'app/models/store.rb', line 189

def self.by_currency(currency)
  find_by(name: CURRENCY_TO_STORE[currency])
end

.defaultObject



199
200
201
# File 'app/models/store.rb', line 199

def self.default
  find_by(name: 'WarmlyYours-US')
end

.locale_to_catalog(locale = nil) ⇒ Object

Todo make this more I18n



183
184
185
186
# File 'app/models/store.rb', line 183

def self.locale_to_catalog(locale = nil)
  locale ||= I18n.locale
  Store.find(store_id_for_locale(locale))
end

.options_for_select(filters = nil) ⇒ Object



203
204
205
# File 'app/models/store.rb', line 203

def self.options_for_select(filters = nil)
  where(filters).order(:name).pluck(:name, :id)
end

.potential_ownersObject



139
140
141
# File 'app/models/store.rb', line 139

def self.potential_owners
  %w[warmlyyours amazon dimass]
end

.store_id_for_locale(locale = nil) ⇒ Object

Todo make this more I18n



178
179
180
# File 'app/models/store.rb', line 178

def self.store_id_for_locale(locale = nil)
  LOCALE_TO_STORE_ID[locale&.to_sym]
end

.store_locations_by_idObject



257
258
259
# File 'app/models/store.rb', line 257

def self.store_locations_by_id
  Store.all.to_h { |s| [s.id, s.locations] }
end

.warmlyyours_warehousesActiveRecord::Relation<Store>

A relation of Stores that are warmlyyours warehouses. Active Record Scope

Returns:

  • (ActiveRecord::Relation<Store>)

See Also:



135
# File 'app/models/store.rb', line 135

scope :warmlyyours_warehouses, -> { where(owner: 'warmlyyours') }

Instance Method Details

#alternative_storeObject

Todo make this more I18n



160
161
162
# File 'app/models/store.rb', line 160

def alternative_store
  find(id == WARMLYYOURS_US_ID ? WARMLYYOURS_CA_ID : WARMLYYOURS_US_ID)
end

#alternative_storesObject



168
169
170
# File 'app/models/store.rb', line 168

def alternative_stores
  Store.where.not(id:).where(owner: 'warmlyyours')
end

#carrier_pickup_for_datetime(carrier_account_id, datetime) ⇒ Object



269
270
271
# File 'app/models/store.rb', line 269

def carrier_pickup_for_datetime(, datetime)
  carrier_pickups.().for_datetime(datetime).first
end

#carrier_pickup_for_today(carrier_account_id) ⇒ Object



265
266
267
# File 'app/models/store.rb', line 265

def carrier_pickup_for_today()
  carrier_pickups.().for_today.first
end

#carrier_pickup_time(carrier) ⇒ Object



449
450
451
452
453
454
455
# File 'app/models/store.rb', line 449

def carrier_pickup_time(carrier)
  pu_time = nil
  if CARRIER_PICKUP_TIMES[name] && (pu_time_str = CARRIER_PICKUP_TIMES[name][carrier])
    pu_time = Time.zone.parse(pu_time_str)
  end
  pu_time
end

#carrier_pickupsActiveRecord::Relation<CarrierPickup>

Returns:

See Also:



107
# File 'app/models/store.rb', line 107

has_many :carrier_pickups, dependent: :destroy

#catalogsActiveRecord::Relation<Catalog>

Returns:

  • (ActiveRecord::Relation<Catalog>)

See Also:



101
# File 'app/models/store.rb', line 101

has_many :catalogs, inverse_of: :store

#companyCompany

Returns:

See Also:



88
# File 'app/models/store.rb', line 88

belongs_to :company, optional: true

#consignee_partyCustomer

Returns:

See Also:



89
# File 'app/models/store.rb', line 89

belongs_to :consignee_party, class_name: 'Customer', inverse_of: :consignment_stores, optional: true

#countryCountry

Returns:

See Also:



87
# File 'app/models/store.rb', line 87

belongs_to :country, foreign_key: :country_iso3, primary_key: :iso3, optional: true

#country_codeObject



207
208
209
# File 'app/models/store.rb', line 207

def country_code
  country.iso
end

#currencyObject

Alias for Company#currency

Returns:

  • (Object)

    Company#currency

See Also:



197
# File 'app/models/store.rb', line 197

delegate :currency, to: :company

#currency_symbolObject



193
194
195
# File 'app/models/store.rb', line 193

def currency_symbol
  Money::Currency.new(currency).symbol
end

#current_shipping_document_print_profile(employee_record_id = nil) ⇒ Object



225
226
227
# File 'app/models/store.rb', line 225

def current_shipping_document_print_profile(employee_record_id = nil)
  printer_profile_for_scope(:shipping_document, employee_record_id)
end

#current_shipping_label_print_profile(employee_record_id = nil) ⇒ Object



229
230
231
# File 'app/models/store.rb', line 229

def current_shipping_label_print_profile(employee_record_id = nil)
  printer_profile_for_scope(:shipping_label, employee_record_id)
end

#current_upc_label_print_profile(employee_record_id = nil) ⇒ Object



221
222
223
# File 'app/models/store.rb', line 221

def current_upc_label_print_profile(employee_record_id = nil)
  printer_profile_for_scope(:upc_label, employee_record_id)
end

#customer_for_stCustomer

Returns:

See Also:



90
# File 'app/models/store.rb', line 90

belongs_to :customer_for_st, class_name: 'Customer', optional: true

#cycle_countsActiveRecord::Relation<CycleCount>

Returns:

See Also:



105
# File 'app/models/store.rb', line 105

has_many :cycle_counts

#default_shipping_methodObject



249
250
251
# File 'app/models/store.rb', line 249

def default_shipping_method
  { USA: 'ground', CAN: 'standard' }.dig(country.iso3)
end

#emailObject



241
242
243
244
245
246
247
# File 'app/models/store.rb', line 241

def email
  if country_iso3 == 'CAN'
    'warehousecanada@warmlyyours.com'
  else
    'warehouseusa@warmlyyours.com'
  end
end

#email_options_for_order_notification_emailsObject



164
165
166
# File 'app/models/store.rb', line 164

def email_options_for_order_notification_emails
  [order_notification_emails].flatten.compact.uniq
end

#floor_typesActiveRecord::Relation<FloorType>

Returns:

See Also:



115
# File 'app/models/store.rb', line 115

has_and_belongs_to_many :floor_types

#future_carrier_pickups(carrier_account_id) ⇒ Object



273
274
275
# File 'app/models/store.rb', line 273

def future_carrier_pickups()
  carrier_pickups.().future_days
end

#get_next_sales_rep_assignments_for_customer(customer) ⇒ Object



143
144
145
# File 'app/models/store.rb', line 143

def get_next_sales_rep_assignments_for_customer(customer)
  sales_rep_queue&.get_next_sales_rep_assignments_for_customer(customer)
end

#goods_accountObject



151
152
153
# File 'app/models/store.rb', line 151

def 
  warmlyyours_warehouse? ? PURCHASED_FINISHED_GOODS_ACCOUNT : CONSIGNMENT_ACCOUNT
end

#heating_element_product_line_optionsActiveRecord::Relation<HeatingElementProductLineOption>

Returns:

See Also:



108
# File 'app/models/store.rb', line 108

has_many :heating_element_product_line_options, inverse_of: :store

#import_catalog(catalog) ⇒ Object

Import a catalog's store item into this store assuming that will be the only catalog for that store



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'app/models/store.rb', line 278

def import_catalog(catalog)
  return if catalog.store_id == id
  return if catalog.store.country_iso3 != country_iso3

  # Now we can proceed, clone only active
  Catalog.transaction do
    # Clone catalog
    if (new_catalog = catalogs.first)
      logger.info "Existing catalog: #{new_catalog.name}"
    else
      new_catalog = catalog.dup
      new_catalog.store_id = id
      new_catalog.parent_catalog_id = nil
      new_catalog.price_sync_policy = :price_sync_manual
      new_catalog.price_sync_delay = nil
      new_catalog.save!
      logger.info "New catalog created: #{new_catalog.id}"
    end

    catalog.catalog_items.with_item.active.each do |ci|
      item_sku = ci.store_item.item.sku
      logger.info "Evaluating #{item_sku} from catalog #{catalog.name} for import into store id #{id} - #{name}"
      # Does this store item already exist?
      if (new_si = store_items.where(item_id: ci.store_item.item_id).first)
        logger.info 'Store item already exists'
      else
        logger.info 'New store item required'
        # clone the store item
        new_si = ci.store_item.dup
        new_si.qty_on_hand = 0
        new_si.qty_committed = 0
        new_si.unit_cogs = 0
        new_si.last_item_ledger_entry_id = nil
        new_si.store_id = id
        new_si.save!
        logger.info "New Store item saved as #{new_si.id}"
      end
      # Was this catalog item already mapped
      if (new_ci = new_si.catalog_items.first)
        logger.info 'Existing catalog item'
        new_ci.attributes = ci.attributes
      else
        logger.info 'New catalog item'
        new_ci = ci.dup
      end
      new_ci.catalog_id = new_catalog.id
      new_ci.store_item_id = new_si.id
      new_ci.save!
      logger.info "Catalog item #{new_ci.id} saved to catalog id #{new_catalog.id}"
    end
  end
end

#invoicesActiveRecord::Relation<Invoice>

Returns:

  • (ActiveRecord::Relation<Invoice>)

See Also:



113
# File 'app/models/store.rb', line 113

has_many :invoices

#itemsActiveRecord::Relation<Item>

Returns:

  • (ActiveRecord::Relation<Item>)

See Also:



100
# File 'app/models/store.rb', line 100

has_many :items, through: :store_items

#locales_servedObject

Todo make this more I18n, look at its catalog?



173
174
175
# File 'app/models/store.rb', line 173

def locales_served
  country.locales_for_country
end

#locationsObject



253
254
255
# File 'app/models/store.rb', line 253

def locations
  store_items.pluck(:location).uniq
end

#mailing_addressAddress

Returns:

See Also:



86
# File 'app/models/store.rb', line 86

belongs_to :mailing_address, class_name: 'Address', optional: true

#manifestsActiveRecord::Relation<Manifest>

Returns:

See Also:



109
# File 'app/models/store.rb', line 109

has_many :manifests, inverse_of: :store

#mass_ship_confirm_counter(carrier) ⇒ Object



445
446
447
# File 'app/models/store.rb', line 445

def mass_ship_confirm_counter(carrier)
  query_mass_ship_confirm_delivery_candidates(carrier).size
end

#partiesActiveRecord::Relation<Party>

Returns:

  • (ActiveRecord::Relation<Party>)

See Also:



98
# File 'app/models/store.rb', line 98

has_many :parties, through: :catalogs

#preferred_inbound_shipping_optionShippingOption



93
# File 'app/models/store.rb', line 93

belongs_to :preferred_inbound_shipping_option, class_name: 'ShippingOption', optional: true

#preferred_outbound_shipping_optionShippingOption



94
# File 'app/models/store.rb', line 94

belongs_to :preferred_outbound_shipping_option, class_name: 'ShippingOption', optional: true

#primary_catalogCatalog

Returns:

See Also:



92
# File 'app/models/store.rb', line 92

belongs_to :primary_catalog, class_name: 'Catalog', optional: true

#printer_profile_for_scope(scope_name, employee_record_id = nil) ⇒ Object



211
212
213
214
215
216
217
218
219
# File 'app/models/store.rb', line 211

def printer_profile_for_scope(scope_name, employee_record_id = nil)
  profiles = PrintProfile.in_store_id(id).send(scope_name).order(:id)
  profiles = if employee_record_id && profiles.where(employee_record_id:).exists? # If there is a specificity use it
               profiles.where(employee_record_id:)
             else # Take the default
               profiles.where(employee_record_id: nil)
             end
  profiles.first
end

#printersActiveRecord::Relation<Printer>

Returns:

  • (ActiveRecord::Relation<Printer>)

See Also:



111
# File 'app/models/store.rb', line 111

has_many :printers

#purchase_ordersActiveRecord::Relation<PurchaseOrder>

Returns:

See Also:



110
# File 'app/models/store.rb', line 110

has_many :purchase_orders

#query_awaiting_carrier_assignment_ordersObject



348
349
350
# File 'app/models/store.rb', line 348

def query_awaiting_carrier_assignment_orders
  Order.by_store_id(id).where(state: 'awaiting_carrier_assignment').with_associations
end

#query_mass_ship_confirm_delivery_candidates(carrier) ⇒ Object



409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# File 'app/models/store.rb', line 409

def query_mass_ship_confirm_delivery_candidates(carrier)
  carrier_to_use = carrier
  carrier_to_use = 'FedEx' if %w[FedExGround FedExExpress].include?(carrier) # deal with annoying FedEx ground vs express

  hw_query = Delivery.by_store_id(id).with_shipment_carrier(carrier_to_use).pending_ship_confirm
  hw_query = hw_query.fedex_ground if carrier == 'FedExGround'
  hw_query = hw_query.fedex_express if carrier == 'FedExExpress'

  # Include AMZ Buy Shipping deliveries whose underlying physical carrier matches.
  # FedExGround captures all AMZ BS FedEx (Home Delivery, Ground, etc.) since the
  # amz_metadata doesn't reliably distinguish ground vs express service level.
  # FedExExpress is therefore HW-only to avoid double-counting.
  amz_query = if carrier == 'FedExExpress'
                Delivery.none
              else
                Delivery.by_store_id(id).with_amz_bs_carrier(carrier_to_use).pending_ship_confirm
              end

  # Gate by carrier pickup time: only show deliveries whose label was printed
  # before today's scheduled pickup (i.e. the carrier presumably already took
  # them). ship_labeled_at is now persisted atomically with the state
  # transition into pending_ship_confirm via a before_transition callback in
  # Delivery, so NULL is a real signal of "labels not finalized" and these
  # rows should NOT surface as candidates. If the store has no pickup time
  # configured for this carrier, don't gate at all.
  pickup_time = carrier_pickup_time(carrier)
  if pickup_time
    hw_query = hw_query.ship_labeled_before(pickup_time)
    amz_query = amz_query.ship_labeled_before(pickup_time)
  end

  Delivery.where(id: hw_query.select(:id))
          .or(Delivery.where(id: amz_query.select(:id)))
          .distinct.order(:created_at)
end

#query_recently_shippedObject



392
393
394
395
396
397
398
399
400
401
402
403
# File 'app/models/store.rb', line 392

def query_recently_shipped
  Delivery.by_store_id(id)
          .where(state: %w[shipped invoiced])
          .where(Delivery[:shipped_date].gteq(Date.current))
          .includes(:uploads,
                    :destination_address,
                    :shipping_option,
                    :freight_events,
                    line_items: [:item],
                    order: [:uploads, :creator, { customer: :primary_sales_rep }])
          .order(:created_at)
end

#query_serial_numbers_pending_printObject



388
389
390
# File 'app/models/store.rb', line 388

def query_serial_numbers_pending_print
  serial_numbers.pending_print.order(:number)
end

#query_warehouse_amazon_ordersObject



374
375
376
377
378
# File 'app/models/store.rb', line 374

def query_warehouse_amazon_orders
  Order.by_store_id(id).limit_to_fba.where(state: %w[in_cr_hold crm_back_order] + Order::SHIPPING_STATES).joins(:deliveries).order(
    Delivery[:future_release_date], Delivery[:created_at]
  )
end

#query_warehouse_back_ordersObject



352
353
354
# File 'app/models/store.rb', line 352

def query_warehouse_back_orders
  Order.by_store_id(id).back_order.with_associations
end

#query_warehouse_deliveries(state: nil) ⇒ Object



362
363
364
365
366
367
368
369
370
371
372
# File 'app/models/store.rb', line 362

def query_warehouse_deliveries(state: nil)
  deliveries = Delivery.by_store_id(id).all_at_warehouse.with_active_parent
                       .includes(:uploads,
                                 :destination_address,
                                 :shipping_option,
                                 :freight_events,
                                 line_items: [:item],
                                 order: [:uploads, :creator, { customer: :primary_sales_rep }])
  deliveries = deliveries.where(state:) if state.present?
  deliveries
end

#query_warehouse_deliveries_groupedObject



380
381
382
# File 'app/models/store.rb', line 380

def query_warehouse_deliveries_grouped
  query_warehouse_deliveries.group_by(&:state)
end

#query_warehouse_deliveries_grouped_countersObject



384
385
386
# File 'app/models/store.rb', line 384

def query_warehouse_deliveries_grouped_counters
  query_warehouse_deliveries.group('deliveries.state').count
end

#query_warehouse_held_ordersObject



344
345
346
# File 'app/models/store.rb', line 344

def query_warehouse_held_orders
  Order.by_store_id(id).held.with_associations
end

#query_warehouse_orders_need_attentionObject



356
357
358
359
360
# File 'app/models/store.rb', line 356

def query_warehouse_orders_need_attention
  Order.by_store_id(id).all_awaiting_deliveries.with_associations.joins(:deliveries).where(Delivery[:state].eq('quoting')).order(
    Delivery[:future_release_date], Delivery[:created_at]
  )
end

#query_warehouse_purchase_orders_shippedObject



405
406
407
# File 'app/models/store.rb', line 405

def query_warehouse_purchase_orders_shipped
  purchase_orders.where(state: 'shipped')
end

#room_typesActiveRecord::Relation<RoomType>

Returns:

See Also:



116
# File 'app/models/store.rb', line 116

has_and_belongs_to_many :room_types

#sales_rep_queueSalesRepQueue



96
# File 'app/models/store.rb', line 96

has_one :sales_rep_queue

#serial_numbersActiveRecord::Relation<SerialNumber>

Returns:

See Also:



106
# File 'app/models/store.rb', line 106

has_many :serial_numbers, through: :store_items

#services_accountObject



155
156
157
# File 'app/models/store.rb', line 155

def 
  warmlyyours_warehouse? ? SERVICES_PENDING_FULFILLMENT_DEBIT_ACCOUNT : CONSIGNMENT_ACCOUNT
end

#set_carrier_pickup(carrier, carrier_account_id, pickup_resp, pickup_number, scheduled_start, scheduled_end) ⇒ Object



331
332
333
334
335
336
337
338
339
340
341
342
# File 'app/models/store.rb', line 331

def set_carrier_pickup(carrier, , pickup_resp, pickup_number, scheduled_start, scheduled_end)
  Rails.logger.debug { "set_carrier_pickup: carrier: #{carrier}" }
  Rails.logger.debug { "set_carrier_pickup: carrier_account_id: #{}" }
  Rails.logger.debug { "set_carrier_pickup: pickup_resp: #{pickup_resp.inspect}" }
  Rails.logger.debug { "set_carrier_pickup: pickup_number: #{pickup_number}" }
  Rails.logger.debug { "set_carrier_pickup: scheduled_start: #{scheduled_start}" }
  Rails.logger.debug { "set_carrier_pickup: scheduled_end: #{scheduled_end}" }
  pickup = CarrierPickup.new(store_id: id, carrier:, carrier_account_id:, carrier_pickup_id: pickup_number,
                             scheduled_start:, scheduled_end:)
  carrier_pickups << pickup
  pickup
end

#storage_locationsActiveRecord::Relation<StorageLocation>

Returns:

See Also:



112
# File 'app/models/store.rb', line 112

has_many :storage_locations

#store_itemsActiveRecord::Relation<StoreItem>

Returns:

See Also:



99
# File 'app/models/store.rb', line 99

has_many :store_items, dependent: :destroy

#store_items_with_sku_for_selectObject



261
262
263
# File 'app/models/store.rb', line 261

def store_items_with_sku_for_select
  store_items.includes(:item).order('items.sku').pluck('items.sku', :id)
end

#store_transfersActiveRecord::Relation<StoreTransfer>

Returns:

See Also:



102
# File 'app/models/store.rb', line 102

has_many :store_transfers, foreign_key: :from_store_id, primary_key: :id

#supplierSupplier

Returns:

See Also:



91
# File 'app/models/store.rb', line 91

belongs_to :supplier, class_name: 'Supplier'

#time_zone_stringObject



233
234
235
236
237
238
239
# File 'app/models/store.rb', line 233

def time_zone_string
  if country_iso3 == 'CAN'
    'Eastern Time (US & Canada)'
  else
    'America/Chicago'
  end
end

#uploadsActiveRecord::Relation<Upload>

Returns:

  • (ActiveRecord::Relation<Upload>)

See Also:



104
# File 'app/models/store.rb', line 104

has_many :uploads, as: :resource, dependent: :destroy

#warehouse_addressAddress

Returns:

See Also:

Validations:



84
# File 'app/models/store.rb', line 84

belongs_to :warehouse_address, class_name: 'Address', optional: true

#warehouse_packagesActiveRecord::Relation<WarehousePackage>

Returns:

See Also:



103
# File 'app/models/store.rb', line 103

has_many :warehouse_packages, -> { order(:sort_order, :volume) }, dependent: :destroy

#warehouse_service_addressAddress

Returns:

See Also:



85
# File 'app/models/store.rb', line 85

belongs_to :warehouse_service_address, class_name: 'Address', optional: true

#warmlyyours_warehouse?Boolean

Returns:

  • (Boolean)


147
148
149
# File 'app/models/store.rb', line 147

def warmlyyours_warehouse?
  owner == 'warmlyyours'
end