1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-30 19:52:20 +01:00

fix creation of prices with float values

This commit is contained in:
Sylvain 2016-11-29 15:23:36 +01:00
parent a9e593a840
commit 82fa5416ce
3 changed files with 5 additions and 5 deletions

View File

@ -83,7 +83,7 @@ class API::CouponsController < API::ApiController
@parameters
else
@parameters = params
@parameters[:coupon][:amount_off] = @parameters[:coupon][:amount_off].to_i * 100.0 if @parameters[:coupon][:amount_off]
@parameters[:coupon][:amount_off] = @parameters[:coupon][:amount_off].to_f * 100.0 if @parameters[:coupon][:amount_off]
@parameters = @parameters.require(:coupon).permit(:name, :code, :percent_off, :amount_off, :validity_per_user, :valid_until, :max_usages, :active)
end

View File

@ -86,12 +86,12 @@ class API::EventsController < API::ApiController
event_preparams.merge!(availability_attributes: {id: event_preparams[:availability_id], start_at: start_at, end_at: end_at, available_type: 'event'})
.except!(:start_date, :end_date, :start_time, :end_time, :all_day)
# convert main price to centimes
event_preparams.merge!(amount: (event_preparams[:amount].to_i * 100 if event_preparams[:amount].present?))
event_preparams.merge!(amount: (event_preparams[:amount].to_f * 100 if event_preparams[:amount].present?))
# delete non-complete "other" prices and convert them to centimes
unless event_preparams[:event_price_categories_attributes].nil?
event_preparams[:event_price_categories_attributes].delete_if { |price_cat| price_cat[:price_category_id].empty? or price_cat[:amount].empty? }
event_preparams[:event_price_categories_attributes].each do |price_cat|
price_cat[:amount] = price_cat[:amount].to_i * 100
price_cat[:amount] = price_cat[:amount].to_f * 100
end
end
# return the resulting params object

View File

@ -81,9 +81,9 @@
@parameters
else
@parameters = params
@parameters[:plan][:amount] = @parameters[:plan][:amount].to_i * 100.0 if @parameters[:plan][:amount]
@parameters[:plan][:amount] = @parameters[:plan][:amount].to_f * 100.0 if @parameters[:plan][:amount]
@parameters[:plan][:prices_attributes] = @parameters[:plan][:prices_attributes].map do |price|
{ amount: price[:amount].to_i * 100.0, id: price[:id] }
{ amount: price[:amount].to_f * 100.0, id: price[:id] }
end if @parameters[:plan][:prices_attributes]
@parameters = @parameters.require(:plan).permit(:base_name, :type, :group_id, :amount, :interval, :interval_count, :is_rolling,