Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Commit

Permalink
Rename #discounted_amount to #discountable_amount
Browse files Browse the repository at this point in the history
This naming is clearer, I think, as it doesn't describe how the amount
has already been discounted, but which amount we can still apply
discounts to.
  • Loading branch information
mamhoff committed Oct 2, 2023
1 parent c83d364 commit 22607e7
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Percent < Spree::Calculator
def compute(object)
preferred_currency = object.order.currency
currency_exponent = ::Money::Currency.find(preferred_currency).exponent
(object.discounted_amount * preferred_percent / 100).round(currency_exponent)
(object.discountable_amount * preferred_percent / 100).round(currency_exponent)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TieredFlatRate < Spree::Calculator

def compute_item(object)
_base, amount = preferred_tiers.sort.reverse.detect do |value, _|
object.discounted_amount >= value
object.discountable_amount >= value
end

if preferred_currency.casecmp(object.currency).zero?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def line_item
__getobj__
end

def discounted_amount
def discountable_amount
amount + discounts.sum(&:amount)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def shipment
__getobj__
end

def discounted_amount
def discountable_amount
amount + discounts.sum(&:amount)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def shipping_rate
__getobj__
end

def discounted_amount
def discountable_amount
amount + discounts.sum(&:amount)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def line_item_ids
end

def elligible_amounts
line_items.map(&:discounted_amount)
line_items.map(&:discountable_amount)
end

def subtotal
Expand Down
2 changes: 1 addition & 1 deletion app/models/solidus_friendly_promotions/promotion_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def discount(adjustable)
# Ensure a negative amount which does not exceed the object's amount
def compute_amount(adjustable)
promotion_amount = calculator.compute(adjustable) || BigDecimal("0")
[adjustable.discounted_amount, promotion_amount.abs].min * -1
[adjustable.discountable_amount, promotion_amount.abs].min * -1
end

def adjustment_label(adjustable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
context "compute" do
let(:currency) { "USD" }
let(:order) { double(currency: currency) }
let(:line_item) { double("SolidusFriendlyPromotions::Discountable::LineItem", discounted_amount: 100, order: order) }
let(:line_item) { double("SolidusFriendlyPromotions::Discountable::LineItem", discountable_amount: 100, order: order) }

before { subject.preferred_percent = 15 }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
it { is_expected.to eq(discountable_order) }
end

describe "#discounted_amount" do
subject(:discounted_amount) { discountable_line_item.discounted_amount }
describe "#discountable_amount" do
subject(:discountable_amount) { discountable_line_item.discountable_amount }

context "with no discounts" do
it { is_expected.to eq(20) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
it { is_expected.to eq(discountable_order) }
end

describe "#discounted_amount" do
subject(:discounted_amount) { discountable_shipment.discounted_amount }
describe "#discountable_amount" do
subject(:discountable_amount) { discountable_shipment.discountable_amount }

context "with no discounts" do
it { is_expected.to eq(20) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
it { is_expected.to eq(discountable_shipment) }
end

describe "#discounted_amount" do
subject(:discounted_amount) { discountable_shipping_rate.discounted_amount }
describe "#discountable_amount" do
subject(:discountable_amount) { discountable_shipping_rate.discountable_amount }

context "with no discounts" do
it { is_expected.to eq(20) }
Expand Down

0 comments on commit 22607e7

Please sign in to comment.