Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ module PromotionCalculator
def description
self.class.human_attribute_name(:description)
end

private

def round_to_currency(number, currency)
currency_exponent = ::Money::Currency.find(currency).exponent
number.round(currency_exponent)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class Percent < Spree::Calculator
preference :percent, :decimal, default: 0

def compute(object)
preferred_currency = object.order.currency
currency_exponent = ::Money::Currency.find(preferred_currency).exponent
(object.discountable_amount * preferred_percent / 100).round(currency_exponent)
round_to_currency(object.discountable_amount * preferred_percent / 100, object.order.currency)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def compute_item(object)
end

if preferred_currency.casecmp(order.currency).zero?
currency_exponent = ::Money::Currency.find(preferred_currency).exponent
(object.amount * (percent || preferred_base_percent) / 100).round(currency_exponent)
round_to_currency(object.amount * (percent || preferred_base_percent) / 100, preferred_currency)
else
0
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ def compute_line_item(line_item)
eligible_line_items_quantity_total(order) >= value
end
if preferred_currency.casecmp(order.currency).zero?
currency_exponent = ::Money::Currency.find(preferred_currency).exponent
(line_item.discountable_amount * (percent || preferred_base_percent) / 100).round(currency_exponent)
round_to_currency(line_item.discountable_amount * (percent || preferred_base_percent) / 100, preferred_currency)
else
0
end
Expand Down
Loading