mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-14 23:47:48 +00:00
Make all calculators use FlatPercentPerItem instead of FlatPercentItemTotal
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
class SwapCalculatorToFlatPercentPerItem < ActiveRecord::Migration
|
||||
class Spree::Calculator < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def up
|
||||
Spree::Calculator.where(calculable_type: "EnterpriseFee", type: 'Spree::Calculator::FlatPercentItemTotal').each do |c|
|
||||
swap_calculator_type c, 'Calculator::FlatPercentPerItem'
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
Spree::Calculator.where(calculable_type: "EnterpriseFee", type: 'Spree::Calculator::FlatPercentPerItem').each do |c|
|
||||
swap_calculator_type c, 'Calculator::FlatPercentItemTotal'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def swap_calculator_type(calculator, to_class)
|
||||
value = calculator.preferred_flat_percent
|
||||
|
||||
calculator.type = to_class
|
||||
calculator.save
|
||||
|
||||
calculator = Spree::Calculator.find calculator.id
|
||||
calculator.preferred_flat_percent = value
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20160713013358) do
|
||||
ActiveRecord::Schema.define(:version => 20160819065331) do
|
||||
|
||||
create_table "account_invoices", :force => true do |t|
|
||||
t.integer "user_id", :null => false
|
||||
@@ -582,9 +582,9 @@ ActiveRecord::Schema.define(:version => 20160713013358) do
|
||||
t.string "email"
|
||||
t.text "special_instructions"
|
||||
t.integer "distributor_id"
|
||||
t.integer "order_cycle_id"
|
||||
t.string "currency"
|
||||
t.string "last_ip_address"
|
||||
t.integer "order_cycle_id"
|
||||
t.integer "cart_id"
|
||||
t.integer "customer_id"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user