mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-17 06:52:27 +01:00
remove unused recuced_amount from event + allow to rollback migrations + openAPI will display custom prices for events
This commit is contained in:
parent
e281a20ada
commit
87104a6b97
@ -22,10 +22,14 @@ class OpenAPI::V1::EventsDoc < OpenAPI::V1::BaseDoc
|
||||
"description": "Que vous soyez Fab user, visiteur, curieux ou bricoleur, l’atelier de fabrication numérique vous ouvre ses portes les mercredis soirs pour avancer vos projets ou rencontrer la «communauté» Fab Lab. \r\n\r\nCe soir, venez spécialement découvrir les machines à commandes numérique du Fab Lab de La Casemate, venez comprendre ce lieux ouvert à tous. \r\n\r\n\r\nVenez découvrir un concept, une organisation, des machines, pour stimuler votre sens de la créativité.",
|
||||
"updated_at": "2016-04-25T10:49:40.055+02:00",
|
||||
"created_at": "2016-04-25T10:49:40.055+02:00",
|
||||
"amount": 0,
|
||||
"reduced_amount": 0,
|
||||
"nb_total_places": 18,
|
||||
"nb_free_places": 16
|
||||
"nb_free_places": 16,
|
||||
"prices": {
|
||||
"normal": {
|
||||
"name": "Plein tarif",
|
||||
"amount": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 182,
|
||||
@ -33,10 +37,18 @@ class OpenAPI::V1::EventsDoc < OpenAPI::V1::BaseDoc
|
||||
"description": "Envie de rider à travers Grenoble sur une planche unique ? Envie de découvrir la fabrication éco-responsable d'un skate ? Alors bienvenue à l'atelier Skate Board du Fablab ! Encadré par Ivan Mago et l'équipe du FabLab, vous réaliserez votre planche (skate, longboard,...) depuis son design jusqu'à sa décoration sur 4 séances.\r\n\r\nLe tarif 50€ inclut la participation aux ateliers, l'utilisations des machines, et tout le matériel de fabrication (bois+colle+grip+vinyle).\r\n\r\nCette première séance sera consacré au design de votre planche et à la découpe des gabarits. N'hésitez pas à venir avec votre ordinateur et vos logiciels de création 2D si vous le souhaitez.\r\n\r\nNous vous attendons nombreux !",
|
||||
"updated_at": "2016-04-11T17:40:15.146+02:00",
|
||||
"created_at": "2016-04-11T17:40:15.146+02:00",
|
||||
"amount": 5000,
|
||||
"reduced_amount": null,
|
||||
"nb_total_places": 8,
|
||||
"nb_free_places": 0
|
||||
"nb_free_places": 0,
|
||||
"prices": {
|
||||
"normal": {
|
||||
"name": "Plein tarif",
|
||||
"amount": 5000
|
||||
},
|
||||
"1": {
|
||||
"name": "Tarif réduit",
|
||||
"amount": 4000
|
||||
},
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -47,6 +47,24 @@ class Event < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# @deprecated
|
||||
# <b>DEPRECATED:</b> Please use <tt>event_price_categories</tt> instead.
|
||||
# This method is for backward compatibility only, do not use in new code
|
||||
def reduced_amount
|
||||
if ActiveRecord::Base.connection.column_exists?(:events, :reduced_amount)
|
||||
read_attribute(:reduced_amount)
|
||||
else
|
||||
pc = PriceCategory.find_by(name: I18n.t('price_category.reduced_fare'))
|
||||
reduced_fare = event_price_categories.where(price_category: pc).first
|
||||
if reduced_fare.nil?
|
||||
nil
|
||||
else
|
||||
reduced_fare.amount
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# def reservations
|
||||
# Reservation.where(reservable: self)
|
||||
# end
|
||||
|
@ -1,4 +1,17 @@
|
||||
json.events @events do |event|
|
||||
json.partial! 'open_api/v1/events/event', event: event
|
||||
json.extract! event, :amount, :reduced_amount, :nb_total_places, :nb_free_places
|
||||
json.extract! event, :nb_total_places, :nb_free_places
|
||||
json.prices do
|
||||
json.normal do
|
||||
json.name I18n.t('app.public.home.full_price')
|
||||
json.amount event.amount
|
||||
end
|
||||
event.event_price_categories.each do |epc|
|
||||
pc = epc.price_category
|
||||
json.set! pc.id do
|
||||
json.name pc.name
|
||||
json.amount epc.amount
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,5 +1,5 @@
|
||||
class MigrateEventReducedAmountToPriceCategory < ActiveRecord::Migration
|
||||
def change
|
||||
def up
|
||||
pc = PriceCategory.new(
|
||||
name: I18n.t('price_category.reduced_fare'),
|
||||
conditions: I18n.t('price_category.reduced_fare_if_you_are_under_25_student_or_unemployed')
|
||||
@ -26,4 +26,24 @@ class MigrateEventReducedAmountToPriceCategory < ActiveRecord::Migration
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
pc = PriceCategory.find_by_name(I18n.t('price_category.reduced_fare'))
|
||||
EventPriceCategory.where(price_category_id: pc.id).each do |epc|
|
||||
epc.event.update_column(:reduced_amount, epc.amount)
|
||||
|
||||
Reservation.where(reservable_type: 'Event', reservable_id: epc.event.id).each do |r|
|
||||
r.tickets.each do |t|
|
||||
if t.event_price_category_id == epc.id
|
||||
r.update_column(:nb_reserve_reduced_places, t.booked)
|
||||
t.destroy!
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
epc.destroy!
|
||||
end
|
||||
|
||||
pc.destroy!
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,5 @@
|
||||
class RemoveReducedAmountFromEvent < ActiveRecord::Migration
|
||||
def change
|
||||
remove_column :events, :reduced_amount, :integer
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
class RemoveNbReserveReducedPlacesFromReservation < ActiveRecord::Migration
|
||||
def change
|
||||
remove_column :reservations, :nb_reserve_reduced_places, :integer
|
||||
end
|
||||
end
|
@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160830154719) do
|
||||
ActiveRecord::Schema.define(version: 20160831084519) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@ -165,7 +165,6 @@ ActiveRecord::Schema.define(version: 20160830154719) do
|
||||
t.datetime "updated_at"
|
||||
t.integer "availability_id"
|
||||
t.integer "amount"
|
||||
t.integer "reduced_amount"
|
||||
t.integer "nb_total_places"
|
||||
t.integer "nb_free_places"
|
||||
t.integer "recurrence_id"
|
||||
@ -497,10 +496,9 @@ ActiveRecord::Schema.define(version: 20160830154719) do
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "reservable_id"
|
||||
t.string "reservable_type", limit: 255
|
||||
t.string "stp_invoice_id", limit: 255
|
||||
t.string "reservable_type", limit: 255
|
||||
t.string "stp_invoice_id", limit: 255
|
||||
t.integer "nb_reserve_places"
|
||||
t.integer "nb_reserve_reduced_places"
|
||||
end
|
||||
|
||||
add_index "reservations", ["reservable_id", "reservable_type"], name: "index_reservations_on_reservable_id_and_reservable_type", using: :btree
|
||||
|
Loading…
x
Reference in New Issue
Block a user