Class: Workarea::Pricing::Discount::ReconcileTotal
- Inherits:
-
Object
- Object
- Workarea::Pricing::Discount::ReconcileTotal
- Defined in:
- app/models/workarea/pricing/discount/reconcile_total.rb
Instance Method Summary collapse
-
#initialize(price_adjustments) ⇒ ReconcileTotal
constructor
A new instance of ReconcileTotal.
- #over_discounted? ⇒ Boolean
- #over_discounted_amount ⇒ Object
- #perform ⇒ Object
Constructor Details
#initialize(price_adjustments) ⇒ ReconcileTotal
Returns a new instance of ReconcileTotal.
5 6 7 |
# File 'app/models/workarea/pricing/discount/reconcile_total.rb', line 5 def initialize(price_adjustments) @price_adjustments = price_adjustments end |
Instance Method Details
#over_discounted? ⇒ Boolean
9 10 11 |
# File 'app/models/workarea/pricing/discount/reconcile_total.rb', line 9 def over_discounted? over_discounted_amount > 0 end |
#over_discounted_amount ⇒ Object
13 14 15 |
# File 'app/models/workarea/pricing/discount/reconcile_total.rb', line 13 def over_discounted_amount 0.to_m - @price_adjustments.sum end |
#perform ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/workarea/pricing/discount/reconcile_total.rb', line 17 def perform units = discount_adjustments.map do |adjustment| { id: adjustment.id, price: adjustment.amount.abs } end distributor = PriceDistributor.new(over_discounted_amount, units) distributor.results.each do |id, value| adjustment = discount_adjustments.detect { |a| a.id == id } adjustment.amount += value end end |