mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Add adjustment_total to spree_shipments
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
class AddAdjustmentTotalToShipment < ActiveRecord::Migration
|
||||
def up
|
||||
add_column :spree_shipments, :adjustment_total, :decimal,
|
||||
precision: 10, scale: 2, null: false, default: 0.0
|
||||
|
||||
populate_adjustment_totals
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :spree_shipments, :adjustment_total
|
||||
end
|
||||
|
||||
def populate_adjustment_totals
|
||||
# Populates the new `adjustment_total` field in the spree_shipments table. Sets the value
|
||||
# to the shipment's (shipping fee) adjustment amount.
|
||||
|
||||
adjustment_totals_sql = <<-SQL
|
||||
UPDATE spree_shipments
|
||||
SET adjustment_total = shipping_adjustment.fee_amount
|
||||
FROM (
|
||||
SELECT spree_adjustments.source_id AS shipment_id, spree_adjustments.amount AS fee_amount
|
||||
FROM spree_adjustments
|
||||
WHERE spree_adjustments.source_type = 'Spree::Shipment'
|
||||
AND spree_adjustments.amount <> 0
|
||||
) shipping_adjustment
|
||||
WHERE spree_shipments.id = shipping_adjustment.shipment_id
|
||||
SQL
|
||||
|
||||
ActiveRecord::Base.connection.execute(adjustment_totals_sql)
|
||||
end
|
||||
end
|
||||
@@ -780,6 +780,7 @@ ActiveRecord::Schema.define(version: 20210320003951) do
|
||||
t.integer "stock_location_id"
|
||||
t.decimal "included_tax_total", precision: 10, scale: 2, default: "0.0", null: false
|
||||
t.decimal "additional_tax_total", precision: 10, scale: 2, default: "0.0", null: false
|
||||
t.decimal "adjustment_total", precision: 10, scale: 2, default: "0.0", null: false
|
||||
t.index ["number"], name: "index_shipments_on_number", using: :btree
|
||||
t.index ["order_id"], name: "index_spree_shipments_on_order_id", unique: true, using: :btree
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user