Skip to content

Instantly share code, notes, and snippets.

View babgyy's full-sized avatar

Lucas Babey babgyy

View GitHub Profile
@babgyy
babgyy / calcul-revenus.rb
Created October 3, 2023 16:08
Calcul revenus programms
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)
@babgyy
babgyy / create-admin-prod.rb
Last active March 21, 2023 09:33
Create admin on prod
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}"
@babgyy
babgyy / stats-reco-time.rb
Last active May 27, 2025 11:53
Stats Reco TIME
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
@babgyy
babgyy / bug-fix-missing-prescription.rb
Created September 13, 2022 16:22
Bug pharma ordo manquante
‎‎​
@babgyy
babgyy / expanded-enrollment-export.rb
Last active March 1, 2022 09:08
Export Enrollment ++
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.
@babgyy
babgyy / index.md
Created February 19, 2016 10:39 — forked from rstacruz/index.md
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one