Add a printer job queue via the printer plugin
This commit is contained in:
parent
63e1541aa3
commit
c955a6ee40
24 changed files with 561 additions and 1 deletions
31
plugins/printer/app/models/printer_job.rb
Normal file
31
plugins/printer/app/models/printer_job.rb
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
class PrinterJob < ActiveRecord::Base
|
||||
|
||||
belongs_to :order
|
||||
belongs_to :created_by, class_name: 'User', foreign_key: 'created_by_user_id'
|
||||
belongs_to :finished_by, class_name: 'User', foreign_key: 'finished_by_user_id'
|
||||
has_many :printer_job_updates
|
||||
|
||||
scope :finished, -> { where.not(finished_at: nil) }
|
||||
scope :unfinished, -> { where(finished_at: nil).order(:id) }
|
||||
scope :pending, -> { unfinished.includes(:order).where.not(orders: {state: 'open'}) }
|
||||
scope :queued, -> { unfinished.includes(:order).where(orders: {state: 'open'}) }
|
||||
|
||||
def last_update_at
|
||||
printer_job_updates.order(:created_at).last.try(&:created_at)
|
||||
end
|
||||
|
||||
def last_update_state
|
||||
printer_job_updates.order(:created_at).last.try(&:state)
|
||||
end
|
||||
|
||||
def add_update!(state, message=nil)
|
||||
return unless finished_at.nil?
|
||||
PrinterJobUpdate.create! printer_job: self, state: state, message: message
|
||||
end
|
||||
|
||||
def finish!(user=nil)
|
||||
return unless finished_at.nil?
|
||||
update_attributes finished_at: Time.now, finished_by: user
|
||||
end
|
||||
|
||||
end
|
||||
5
plugins/printer/app/models/printer_job_update.rb
Normal file
5
plugins/printer/app/models/printer_job_update.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class PrinterJobUpdate < ActiveRecord::Base
|
||||
|
||||
belongs_to :printer_job
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue