Sort tax total by percentage on invoice

This commit is contained in:
Maikel Linke
2022-09-01 11:19:02 +10:00
parent 91eaa522cf
commit 326b0af35f
2 changed files with 28 additions and 3 deletions

View File

@@ -74,8 +74,9 @@ module CheckoutHelper
{
amount: Spree::Money.new(tax_amount, currency: order.currency),
percentage: number_to_percentage(tax_rate.amount * 100, precision: 1),
rate_amount: tax_rate.amount,
}
end
end.sort_by { |tax| tax[:rate_amount] }
end
def display_line_item_tax_rates(line_item)

View File

@@ -51,6 +51,7 @@ describe CheckoutHelper, type: :helper do
{
amount: Spree::Money.new(1, currency: order.currency),
percentage: "10.0%",
rate_amount: 0.1,
}
]
end
@@ -60,14 +61,35 @@ describe CheckoutHelper, type: :helper do
order.all_adjustments << adjustment2
order.save!
expect(helper.display_checkout_taxes_hash(order)).to match_array [
expect(helper.display_checkout_taxes_hash(order)).to eq [
{
amount: Spree::Money.new(1, currency: order.currency),
percentage: "10.0%",
rate_amount: 0.1,
},
{
amount: Spree::Money.new(2, currency: order.currency),
percentage: "20.0%",
rate_amount: 0.2,
},
]
end
it "sorts adjustments by percentage" do
order.all_adjustments << adjustment2
order.all_adjustments << adjustment1
order.save!
expect(helper.display_checkout_taxes_hash(order)).to eq [
{
amount: Spree::Money.new(1, currency: order.currency),
percentage: "10.0%",
rate_amount: 0.1,
},
{
amount: Spree::Money.new(2, currency: order.currency),
percentage: "20.0%",
rate_amount: 0.2,
},
]
end
@@ -77,14 +99,16 @@ describe CheckoutHelper, type: :helper do
order.all_adjustments << other_adjustment2
order.save!
expect(helper.display_checkout_taxes_hash(order)).to match_array [
expect(helper.display_checkout_taxes_hash(order)).to eq [
{
amount: Spree::Money.new(2, currency: order.currency),
percentage: "20.0%",
rate_amount: 0.2,
},
{
amount: Spree::Money.new(2, currency: order.currency),
percentage: "20.0%",
rate_amount: 0.2,
},
]