mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-10 23:07:47 +00:00
Load relevant tax rates in a single query outside of find_each block
This commit is contained in:
@@ -56,13 +56,15 @@ class MigrateShippingTaxes < ActiveRecord::Migration
|
||||
end
|
||||
|
||||
def migrate_tax_amounts_to_adjustments
|
||||
shipping_tax_rates = Spree::TaxRate.where(tax_category: shipping_tax_category).to_a
|
||||
|
||||
# Migrate all shipping tax amounts from shipment field to tax adjustments
|
||||
Spree::Adjustment.shipping.where("included_tax <> 0").includes(:source, :order).find_each do |shipping_fee|
|
||||
shipment = shipping_fee.source
|
||||
order = shipping_fee.order
|
||||
next if order.nil?
|
||||
|
||||
tax_rate = Spree::TaxRate.find_by(tax_category: shipping_tax_category, zone: order.tax_zone)
|
||||
tax_rate = shipping_tax_rates.detect{ |rate| rate.zone == order.tax_zone }
|
||||
|
||||
# Move all tax totals to adjustments
|
||||
Spree::Adjustment.create!(
|
||||
|
||||
Reference in New Issue
Block a user