<commit_before>Spree::Order.class_eval do

  def display_handling_total
    Spree::Money.new(handling_total, { currency: currency })
  end

  # Override if you want to create custom situations for applying the handling charge
  def needs_handling_charge?
    true
  end

  # Creates a adjustments representing handling charges, if applicable.
  # Following 'create_tax_charge!' convention.
  def create_handling_charge!
    return unless needs_handling_charge?

    shipments.each do |shipment|
      if shipment.stock_location.calculator
        amount = shipment.stock_location.calculator.compute_shipment(shipment)
        unless amount == 0
          shipment.adjustments.create!({
            source: shipment.stock_location,
            adjustable: shipment,
            amount: amount,
            order: shipment.order,
            label: "Handling"
          })
        end
      end
    end
  end

  module OverrideOrder
    def create_proposed_shipments
      shipments = super

      create_handling_charge!

      shipments
    end
  end

  prepend OverrideOrder

end
<commit_msg>Made it possible to still call Spree::Order#create_handling_charge<commit_after>Spree::Order.class_eval do

  def display_handling_total
    Spree::Money.new(handling_total, { currency: currency })
  end

  # Override if you want to create custom situations for applying the handling charge
  def needs_handling_charge?
    true
  end

  # Creates a adjustments representing handling charges, if applicable.
  # Following 'create_tax_charge!' convention.
  def create_handling_charge!
    shipments.each do |shipment|
      if shipment.stock_location.calculator
        amount = shipment.stock_location.calculator.compute_shipment(shipment)
        unless amount == 0
          shipment.adjustments.create!({
            source: shipment.stock_location,
            adjustable: shipment,
            amount: amount,
            order: shipment.order,
            label: "Handling"
          })
        end
      end
    end
  end

  module OverrideOrder
    def create_proposed_shipments
      shipments = super

      create_handling_charge! if needs_handling_charge?

      shipments
    end
  end

  prepend OverrideOrder

end

{'fraction_non_alphanumeric': 0.05713000449842555, 'fraction_numerical': 0.000899685110211426, 'mean_word_length': 2.73781512605042, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3812550', 'n_tokens_mistral': 638, 'n_tokens_neox': 588, 'n_words': 163}