From 1aeee83c29cda1e2b1cafb437af41efdba52de00 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 25 Jan 2021 17:24:51 +0000 Subject: [PATCH] Populate tax total fields on spree_orders --- ...20210125171611_populate_order_tax_totals.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 db/migrate/20210125171611_populate_order_tax_totals.rb diff --git a/db/migrate/20210125171611_populate_order_tax_totals.rb b/db/migrate/20210125171611_populate_order_tax_totals.rb new file mode 100644 index 0000000000..7a68121451 --- /dev/null +++ b/db/migrate/20210125171611_populate_order_tax_totals.rb @@ -0,0 +1,18 @@ +class PopulateOrderTaxTotals < ActiveRecord::Migration + def up + Spree::Order.where(additional_tax_total: 0, included_tax_total: 0). + find_each(batch_size: 500) do |order| + + additional_tax_total = order.all_adjustments.tax.additional.sum(:amount) + + included_tax_total = order.line_item_adjustments.tax.sum(:included_tax) + + order.all_adjustments.enterprise_fee.sum(:included_tax) + + order.adjustments.shipping.sum(:included_tax) + + order.update_columns( + additional_tax_total: additional_tax_total, + included_tax_total: included_tax_total + ) + end + end +end