$ rails g model User
belongs_to
has_one
orders = Spree::Order.complete.master_program | |
puts orders.map(&:user_id).uniq.size | |
puts orders.sum(:total) | |
orders = Spree::Order.complete.time_program | |
puts orders.map(&:user_id).uniq.size | |
puts orders.sum(:total) |
accounts = [ | |
["[email protected]", SecureRandom.hex], | |
["[email protected]", SecureRandom.hex], | |
] | |
role = Spree::Role.first | |
accounts.each do |account| | |
email, password = account | |
user = Spree::User.create(email: email, password: password) | |
role.users << user | |
puts "User #{email} - Password #{password}" |
range = 6.months.ago..Time.zone.now | |
cs = ConsultationSpecialty.find_by_slug("erectile_dysfunction") | |
with_reco = Consultation. | |
includes(:spree_order).where(spree_orders: { first_of_type: true }). | |
where(consultation_specialty: cs, recommended_master: true, first_finished_at: range).finished.count | |
total = Consultation. | |
includes(:spree_order).where(spree_orders: { first_of_type: true }). | |
where(consultation_specialty: cs, first_finished_at: range).finished.count |
|
class EnrollmentsExportService | |
def self.export_to_excel scope = Enrollment.admin_viewable | |
workbook = FastExcel.open | |
bold = workbook.bold_cell_format | |
worksheet = workbook.add_worksheet | |
worksheet.auto_width = true | |
enrollments = scope.includes(:program, :doctor, :attendances, patient: [:spree_user], enrollment_payments: [:spree_order], spree_order: [line_items: [variant: [:option_values]]]) | |
data = self.create_enrollment_lines(enrollments) | |
data.each_with_index do |datum, index| |
# Goal: Allow addition of instances to a collection in a factory-built object | |
# when those instances require references to the parent. | |
# Typically occurs in Rails when one model has_many instances of another | |
# See more at: | |
# http://stackoverflow.com/questions/2937326/populating-an-association-with-children-in-factory-girl | |
class Factory | |
def has_many(collection) | |
# after_build is where you add instances to the factory-built collection. |