Sha256: cdd735b19eb8657c1a90ad5d25d74755e7ca92a686bd63f04d3f7acd8a8f4b00

Contents?: true

Size: 841 Bytes

Versions: 18

Compression:

Stored size: 841 Bytes

Contents

module Unidom::Order::Concerns::AsAdjusted

  extend ActiveSupport::Concern

  included do |includer|

    has_many :adjustments, class_name: 'Unidom::Order::OrderAdjustment', as: :adjusted

    def is_adjusted!(amount, due_to: 'FRGT', at: Time.now)
      query      = adjustments.adjustment_factor_coded_as(due_to).valid_at(now: at).alive
      adjustment = query.first
      if adjustment.present?
        if 0==amount
          adjustment.soft_destroy
        else
          adjustment.amount = amount
          adjustment.save!
        end
      else
        adjustment = query.create! amount: amount, opened_at: at
      end
      adjustment
    end

    def is_adjusted?(due_to: 'FRGT', at: Time.now)
      adjustments.adjustment_factor_coded_as(due_to).valid_at(now: at).alive.exists?
    end

  end

  module ClassMethods
  end

end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
unidom-order-2.0 app/models/unidom/order/concerns/as_adjusted.rb
unidom-order-1.5.9 app/models/unidom/order/concerns/as_adjusted.rb
unidom-order-1.5.8 app/models/unidom/order/concerns/as_adjusted.rb
unidom-order-1.5.7 app/models/unidom/order/concerns/as_adjusted.rb
unidom-order-1.5.6 app/models/unidom/order/concerns/as_adjusted.rb
unidom-order-1.5.5 app/models/unidom/order/concerns/as_adjusted.rb
unidom-order-1.5.4 app/models/unidom/order/concerns/as_adjusted.rb
unidom-order-1.5.3 app/models/unidom/order/concerns/as_adjusted.rb
unidom-order-1.5.2 app/models/unidom/order/concerns/as_adjusted.rb
unidom-order-1.5.1 app/models/unidom/order/concerns/as_adjusted.rb
unidom-order-1.5 app/models/unidom/order/concerns/as_adjusted.rb
unidom-order-1.4.2 app/models/unidom/order/concerns/as_adjusted.rb
unidom-order-1.4.1 app/models/unidom/order/concerns/as_adjusted.rb
unidom-order-1.4 app/models/unidom/order/concerns/as_adjusted.rb
unidom-order-1.3.3 app/models/unidom/order/concerns/as_adjusted.rb
unidom-order-1.3.2 app/models/unidom/order/concerns/as_adjusted.rb
unidom-order-1.3.1 app/models/unidom/order/concerns/as_adjusted.rb
unidom-order-1.3 app/models/unidom/order/concerns/as_adjusted.rb