Sha256: d154198d8b5d00aaa4fc210a306af9509294b6a84e35b09e10df88ef284a45e7

Contents?: true

Size: 837 Bytes

Versions: 3

Compression:

Stored size: 837 Bytes

Contents

# frozen_string_literal: true

namespace :taxes do
  desc "Creates all of the records necessary to start collecting the Colorado Delivery Fee"
  task colorado_delivery_fee: :environment do
    usa = Spree::Country.find_by!(iso: "US")
    colorado = usa.states.find_by!(abbr: "CO")

    ActiveRecord::Base.transaction do
      zone = Spree::Zone.create!(
        name: "Colorado",
        description: "State-based zone containing only Colorado.",
        states: [colorado]
      )

      calculator = Spree::Calculator::FlatFee.new
      rate = Spree::TaxRate.create!(
        name: "Colorado Delivery Fee",
        calculator:,
        zone:,
        amount: 0.27,
        show_rate_in_label: false,
        level: "order"
      )
      rate.tax_categories << Spree::TaxCategory.default if Spree::TaxCategory.default
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
solidus_core-4.4.2 lib/tasks/colorado_delivery_fee.rake
solidus_core-4.4.1 lib/tasks/colorado_delivery_fee.rake
solidus_core-4.4.0 lib/tasks/colorado_delivery_fee.rake