mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Sort tax total by percentage on invoice
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user