Sha256: 3d85d4fcd370894501d0b7608e8ca65dca4b684d6bf1d494b34b2751b5904427

Contents?: true

Size: 707 Bytes

Versions: 62

Compression:

Stored size: 707 Bytes

Contents

module Workarea
  class PricingOverrideParams
    attr_reader :params, :user

    def initialize(params, user = nil)
      @params = params.with_indifferent_access
      @user = user
    end

    def to_h
      flip_adjustment_values
      set_created_by
      params
    end

    def flip_adjustment_values
      if params[:subtotal_adjustment].present?
        params[:subtotal_adjustment] = params[:subtotal_adjustment].to_f * -1
      end

      if params[:shipping_adjustment].present?
        params[:shipping_adjustment] = params[:shipping_adjustment].to_f * -1
      end
    end

    def set_created_by
      return unless user.present?
      params.merge!(created_by_id: user.id)
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/queries/workarea/pricing_override_params.rb
workarea-core-3.5.26 app/queries/workarea/pricing_override_params.rb
workarea-core-3.4.45 app/queries/workarea/pricing_override_params.rb
workarea-core-3.5.25 app/queries/workarea/pricing_override_params.rb
workarea-core-3.5.23 app/queries/workarea/pricing_override_params.rb
workarea-core-3.4.44 app/queries/workarea/pricing_override_params.rb
workarea-core-3.5.22 app/queries/workarea/pricing_override_params.rb
workarea-core-3.4.43 app/queries/workarea/pricing_override_params.rb
workarea-core-3.5.21 app/queries/workarea/pricing_override_params.rb
workarea-core-3.4.42 app/queries/workarea/pricing_override_params.rb
workarea-core-3.5.20 app/queries/workarea/pricing_override_params.rb
workarea-core-3.4.41 app/queries/workarea/pricing_override_params.rb
workarea-core-3.5.19 app/queries/workarea/pricing_override_params.rb
workarea-core-3.4.40 app/queries/workarea/pricing_override_params.rb
workarea-core-3.5.18 app/queries/workarea/pricing_override_params.rb
workarea-core-3.4.39 app/queries/workarea/pricing_override_params.rb
workarea-core-3.5.17 app/queries/workarea/pricing_override_params.rb
workarea-core-3.4.38 app/queries/workarea/pricing_override_params.rb
workarea-core-3.5.16 app/queries/workarea/pricing_override_params.rb
workarea-core-3.4.37 app/queries/workarea/pricing_override_params.rb