Sha256: 82d213cfaf2f388a4e0024418e1925ffcc35e5bdfb2f7693a79fc6816b4d7302

Contents?: true

Size: 1.43 KB

Versions: 48

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require 'spree/testing_support/factories/line_item_factory'
require 'spree/testing_support/factories/order_factory'
require 'spree/testing_support/factories/tax_category_factory'
require 'spree/testing_support/factories/tax_rate_factory'
require 'spree/testing_support/factories/zone_factory'

FactoryBot.define do
  factory :adjustment, class: 'Spree::Adjustment' do
    order
    adjustable { order }
    amount { 100.0 }
    label { 'Shipping' }
    association(:source, factory: :tax_rate)
    eligible { true }

    after(:build) do |adjustment|
      adjustments = adjustment.adjustable.adjustments
      if adjustments.loaded? && !adjustments.include?(adjustment)
        adjustments.proxy_association.add_to_target(adjustment)
      end
    end

    factory :tax_adjustment, class: 'Spree::Adjustment' do
      order { adjustable.order }
      association(:adjustable, factory: :line_item)
      amount { 10.0 }
      label { 'VAT 5%' }

      after(:create) do |adjustment|
        # Set correct tax category, so that adjustment amount is not 0
        if adjustment.adjustable.is_a?(Spree::LineItem)
          if adjustment.adjustable.tax_category.present?
            adjustment.source.tax_categories = [adjustment.adjustable.tax_category]
          else
            adjustment.source.tax_categories = []
          end
          adjustment.source.save
          adjustment.recalculate
        end
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 2 rubygems

Version Path
solidus_core-2.10.5 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.11.3 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.11.2 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.11.1 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.10.3 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.11.0 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.10.2 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.9.6 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.8.6 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.10.1 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.9.5 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.10.0 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.9.4 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.6.6 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.7.4 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.8.5 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.9.3 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.9.2 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.10.0.beta1 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.7.3 lib/spree/testing_support/factories/adjustment_factory.rb