Fixed typo
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
class Job < ApplicationRecord
|
||||
attr_accessor :current_user
|
||||
|
||||
belongs_to :costumer, class_name: "User", optional: true, counter_cache: :costumer_jobs_count, inverse_of: :costumer_jobs
|
||||
belongs_to :customer, class_name: "User", optional: true, counter_cache: :customer_jobs_count, inverse_of: :customer_jobs
|
||||
belongs_to :operator, class_name: "User", optional: true, counter_cache: :operator_jobs_count, inverse_of: :operator_jobs
|
||||
belongs_to :creator, class_name: "User", optional: true, counter_cache: :created_jobs_count, inverse_of: :created_jobs
|
||||
belongs_to :cashier, class_name: "User", optional: true, counter_cache: :cashed_jobs_count, inverse_of: :cashed_jobs
|
||||
|
||||
has_one_attached :pdf, dependent: :purge
|
||||
|
||||
validates_presence_of :costumer_firstname, :costumer_lastname, :pdf
|
||||
validates_presence_of :customer_firstname, :customer_lastname, :pdf
|
||||
validates_presence_of :cost_center, if: :intern
|
||||
validates :privacy_policy, acceptance: true, unless: :created_by_operator?
|
||||
validates :number_of_plans_a0, :number_of_plans_a1, :number_of_plans_a2, :number_of_plans_a3, :costum_qm_plan, numericality: { greater_than_or_equal_to: 0 }
|
||||
@@ -21,7 +21,7 @@ class Job < ApplicationRecord
|
||||
before_save :set_cost_qm
|
||||
before_save :calc_cost, if: :printed_pages_changes?
|
||||
|
||||
before_validation :set_costumer_infos, unless: :created_by_operator?, on: :create
|
||||
before_validation :set_customer_infos, unless: :created_by_operator?, on: :create
|
||||
|
||||
# TODO: works only when job is created. Should move analyzer to activestorage :
|
||||
# https://discuss.rubyonrails.org/t/active-storage-in-production-lessons-learned-and-in-depth-look-at-how-it-works/83289
|
||||
@@ -42,7 +42,7 @@ class Job < ApplicationRecord
|
||||
AVAILABLE_PAGE_FORMATS = [ :a0, :a1, :a2, :a3 ]
|
||||
|
||||
# scope :created_as_operator, -> { where created_as_operator: true }
|
||||
# scope :created_as_costumer, -> { where created_as_operator: false }
|
||||
# scope :created_as_customer, -> { where created_as_operator: false }
|
||||
scope :not_canceled, -> { !canceled }
|
||||
|
||||
# NOTE: only named status are returned because of WHERE/IN clause for the enum values
|
||||
@@ -60,7 +60,7 @@ class Job < ApplicationRecord
|
||||
scope :status_changed_on_day, lambda { |date|
|
||||
where("status_changed_at >= ? AND status_changed_at <= ?", date.beginning_of_day, date.end_of_day)
|
||||
}
|
||||
scope :created_by_costumer, -> { not(:created_by_operator) }
|
||||
scope :created_by_customer, -> { not(:created_by_operator) }
|
||||
|
||||
# Returns all jobs with status: open print pickup and jobs from today with status: paid canceled
|
||||
# paid: only updated_at today
|
||||
@@ -72,7 +72,7 @@ class Job < ApplicationRecord
|
||||
.where("status_changed_at >= ?", Time.now.beginning_of_day))
|
||||
# .in_status_order
|
||||
.order(created_at: :asc)
|
||||
# .order(:costumer_firstname, :costumer_lastname)
|
||||
# .order(:customer_firstname, :customer_lastname)
|
||||
.with_attached_pdf # scope from activestorage for .includes(pdf_attachment: :blob)
|
||||
# .references(:pdf_attachment, :blob) # creates big join table
|
||||
end
|
||||
@@ -81,8 +81,8 @@ class Job < ApplicationRecord
|
||||
Job.where(status: %i[paid canceled])
|
||||
end
|
||||
|
||||
def costumer_fullname
|
||||
[ costumer_firstname, " ", costumer_lastname ].join
|
||||
def customer_fullname
|
||||
[ customer_firstname, " ", customer_lastname ].join
|
||||
end
|
||||
|
||||
def acceptable_pdf
|
||||
@@ -127,13 +127,13 @@ class Job < ApplicationRecord
|
||||
csv << columns_readable
|
||||
jobs.each do |job|
|
||||
# csv << job.attributes.values_at(*columns)
|
||||
csv << [ job.id, job.costumer_firstname, job.costumer_lastname, job.cashier_firstname, job.cashier_lastname, job.paid_at.localtime.strftime("%Y-%m-%d"), job.cost.to_s + " €" ]
|
||||
csv << [ job.id, job.customer_firstname, job.customer_lastname, job.cashier_firstname, job.cashier_lastname, job.paid_at.localtime.strftime("%Y-%m-%d"), job.cost.to_s + " €" ]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.ransackable_attributes(auth_object = nil)
|
||||
[ "created_at", "id", "costumer_firstname", "costumer_lastname", "pdf.", "created_by_operator", "number_of_plans_a0", "number_of_plans_a1", "number_of_plans_a2", "number_of_plans_a3", "costum_qm_plan", "cost", "status" ]
|
||||
[ "created_at", "id", "customer_firstname", "customer_lastname", "pdf.", "created_by_operator", "number_of_plans_a0", "number_of_plans_a1", "number_of_plans_a2", "number_of_plans_a3", "costum_qm_plan", "cost", "status" ]
|
||||
end
|
||||
|
||||
def self.ransackable_associations(auth_object = nil)
|
||||
@@ -187,10 +187,10 @@ class Job < ApplicationRecord
|
||||
save
|
||||
end
|
||||
|
||||
def set_costumer_infos
|
||||
self.costumer = current_user unless self.costumer
|
||||
self.costumer_firstname = costumer.firstname
|
||||
self.costumer_lastname = costumer.lastname
|
||||
def set_customer_infos
|
||||
self.customer = current_user unless self.customer
|
||||
self.customer_firstname = customer.firstname
|
||||
self.customer_lastname = customer.lastname
|
||||
end
|
||||
|
||||
def set_operator_infos
|
||||
|
||||
Reference in New Issue
Block a user