From a22fe9f948c01785d8248313cee5bda7bf499d0a Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Thu, 16 Mar 2023 05:05:25 +0100 Subject: [PATCH] fix existing invalid enterprise fees --- ...category_from_per_order_enterprise_fees.rb | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 db/migrate/20230316034707_disable_inherits_tax_category_from_per_order_enterprise_fees.rb diff --git a/db/migrate/20230316034707_disable_inherits_tax_category_from_per_order_enterprise_fees.rb b/db/migrate/20230316034707_disable_inherits_tax_category_from_per_order_enterprise_fees.rb new file mode 100644 index 0000000000..4771fe826b --- /dev/null +++ b/db/migrate/20230316034707_disable_inherits_tax_category_from_per_order_enterprise_fees.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class DisableInheritsTaxCategoryFromPerOrderEnterpriseFees < ActiveRecord::Migration[6.1] + class EnterpriseFee < ApplicationRecord + has_one :calculator, as: :calculable, class_name: "Spree::Calculator", dependent: :destroy + end + + class Spree + class Calculator < ApplicationRecord + self.table_name = 'spree_calculators' + end + end + + def change + EnterpriseFee.joins(:calculator).merge(calculators) + .where(inherits_tax_category: true) + .update_all(inherits_tax_category: false) + end + + def calculators + Spree::Calculator.where(type: per_order_calculators) + end + + def per_order_calculators + ['Calculator::FlatRate', + 'Calculator::FlexiRate', + 'Calculator::PriceSack'] + end +end