Skip to content

Commit

Permalink
Add Spree::OrderCancellations#recalculate_adjustments
Browse files Browse the repository at this point in the history
This removes the final occurrence of Spree::Adjustment#recalculate, and
makes it a cancellation-specific method. No checks for eligibility
(promotion only), no checks if it's taxed, very simple.
  • Loading branch information
mamhoff committed Jan 27, 2024
1 parent 4b46992 commit 075f11e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 10 additions & 0 deletions core/app/models/spree/order_cancellations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ def reimburse_units(inventory_units, created_by:)
reimbursement
end

def recalculate_adjustments
@order.line_items.each do |line_item|
line_item.adjustments.select(&:cancellation?).each do |adjustment|
next if adjustment.finalized?
amount = adjustment.source.compute_amount(line_item)
adjustment.update!(amount: amount)

Check warning on line 104 in core/app/models/spree/order_cancellations.rb

View check run for this annotation

Codecov / codecov/patch

core/app/models/spree/order_cancellations.rb#L103-L104

Added lines #L103 - L104 were not covered by tests
end
end
end

private

def short_ship_unit(inventory_unit, created_by: nil)
Expand Down
4 changes: 1 addition & 3 deletions core/app/models/spree/order_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ def update_taxes
end

def update_cancellations
line_items.each do |line_item|
line_item.adjustments.select(&:cancellation?).each(&:recalculate)
end
Spree::Config.order_cancellations_class.new(order).recalculate_adjustments
end

def update_item_totals
Expand Down

0 comments on commit 075f11e

Please sign in to comment.