Class: PrintProfile

Inherits:
ApplicationRecord show all
Defined in:
app/models/print_profile.rb

Overview

== Schema Information

Table name: print_profiles
Database name: primary

id :integer not null, primary key
bin :string
duplex :string
fit_to_page :boolean
job_type :enum
name :string not null
paper :string
rotate :integer
employee_record_id :integer
printer_id :integer not null

Indexes

index_print_profiles_on_employee_record_id (employee_record_id)
index_print_profiles_on_printer_id (printer_id)

Foreign Keys

fk_rails_... (employee_record_id => employee_records.id)
fk_rails_... (printer_id => printers.id)

Constant Summary

Constants included from Models::Schedulable

Models::Schedulable::SIMPLE_FORM_OPTIONS

Instance Attribute Summary collapse

Belongs to collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#nameString (readonly)

Returns:

  • (String)


51
# File 'app/models/print_profile.rb', line 51

validates :name, presence: true

#printer_idInteger (readonly)

Returns:

  • (Integer)


53
# File 'app/models/print_profile.rb', line 53

validates :printer_id, presence: true

Class Method Details

.in_store_idActiveRecord::Relation<PrintProfile>

A relation of PrintProfiles that are in store id. Active Record Scope

Returns:

See Also:



47
# File 'app/models/print_profile.rb', line 47

scope :in_store_id, ->(store_id) { joins(:printer).where(printers: { store_id: store_id }) }

.onlineActiveRecord::Relation<PrintProfile>

A relation of PrintProfiles that are online. Active Record Scope

Returns:

See Also:



48
# File 'app/models/print_profile.rb', line 48

scope :online, -> { joins(:printer).where(printers: { state: 'online' }) }

.select_optionsvoid

This method returns an undefined value.



57
58
59
# File 'app/models/print_profile.rb', line 57

def self.select_options
  eager_load(:printer).order(Printer[:name], :name).map { |pp| ["#{pp.printer.name} > #{pp.name}", pp.id] }
end

.warehouseActiveRecord::Relation<PrintProfile>

A relation of PrintProfiles that are warehouse. Active Record Scope

Returns:

See Also:



46
# File 'app/models/print_profile.rb', line 46

scope :warehouse, -> { where(job_type: %w[shipping_document shipping_label upc_label]) }

Instance Method Details

#bin_options_for_selectvoid

This method returns an undefined value.



74
75
76
# File 'app/models/print_profile.rb', line 74

def bin_options_for_select
  [['Default', '']] + printer.bins.map { |b| [b, b] }
end

#duplex_options_for_selectvoid

This method returns an undefined value.



67
68
69
70
71
# File 'app/models/print_profile.rb', line 67

def duplex_options_for_select
  return [] unless printer.duplex?

  [['Default', '']] + %w[long-edge short-edge].map { |o| [o.titleize, o] }
end

#employee_recordEmployeeRecord?

Returns:



40
# File 'app/models/print_profile.rb', line 40

belongs_to :employee_record, optional: true

#job_type_for_selectvoid

This method returns an undefined value.



79
80
81
# File 'app/models/print_profile.rb', line 79

def job_type_for_select
  [['Default', '']] + PrintProfile.job_types.keys.map { |k| [k.titleize, k] }
end

#paper_options_for_selectvoid

This method returns an undefined value.



62
63
64
# File 'app/models/print_profile.rb', line 62

def paper_options_for_select
  printer.capabilities.dig('papers', 'table')&.keys || []
end

Parameters:

  • content (Object)
  • content_type (Object) (defaults to: :pdf_base64)
  • quantity (Object) (defaults to: 1)
  • content (Object)
  • content_type (Object) (defaults to: :pdf_base64)
  • quantity (Object) (defaults to: 1)

Returns:

  • (void)
  • (void)


101
102
103
104
105
106
107
108
109
110
111
# File 'app/models/print_profile.rb', line 101

def print(content, content_type: :pdf_base64, quantity: 1)
  # https://www.printnode.com/en/docs/api/curl#printjobs
  # normally printer should listen to the copies option but with dymo label that's not the case
  print_options = to_print_options # .merge(copies: quantity.to_i)
  payload = {
    options: print_options,
    expireAfter: 120_000,
    qty: quantity.to_i
  }
  printer.print(content, content_type: content_type, payload: payload)
end

Parameters:

  • upload (Object)
  • quantity (Object) (defaults to: 1)
  • upload (Object)
  • quantity (Object) (defaults to: 1)

Returns:

  • (void)
  • (void)


89
90
91
# File 'app/models/print_profile.rb', line 89

def print_upload(upload, quantity: 1)
  printer.print_upload(upload, bin: bin, duplex: duplex, quantity: quantity, rotate: rotate, fit_to_page: fit_to_page)
end

#printerPrinter?

Returns:



38
# File 'app/models/print_profile.rb', line 38

belongs_to :printer, optional: true

#to_partial_pathObject

Partial lives under app/views/crm/print_profiles/, not the
conventional app/views/print_profiles/. Override so
render @print_profiles (or render print_profile) resolves from
any controller, not just Crm::PrintProfilesController.



33
34
35
# File 'app/models/print_profile.rb', line 33

def to_partial_path
  'crm/print_profiles/print_profile'
end

#to_print_optionsvoid

This method returns an undefined value.



114
115
116
117
118
119
120
121
122
# File 'app/models/print_profile.rb', line 114

def to_print_options
  {
    bin: bin.presence,
    duplex: duplex.presence,
    rotate: rotate.presence,
    fit_to_page: fit_to_page.to_b,
    paper: paper.presence
  }.compact
end

#to_sString

Returns:

  • (String)


125
126
127
# File 'app/models/print_profile.rb', line 125

def to_s
  "#{printer.computer_name} > #{printer.name} > #{name}"
end