Sha256: 684c5e9e2fc1dd16802da4b3498c9af787336c70aef1f5161b1957bb6634d2dc

Contents?: true

Size: 667 Bytes

Versions: 1

Compression:

Stored size: 667 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

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unidom-order-1.2 app/models/unidom/order/concerns/as_adjusted.rb