Skip to content

Commit

Permalink
Add Bugsnag notification if we reach tax rate refund code
Browse files Browse the repository at this point in the history
The original Spree code allow for a tax adjustment to be considered a
refund in a specific scenario:
- instance is using inclusive tax
- instance that applies different tax rate in different tax zones

This scenario should not happen with how our instances are configured
More info: openfoodfoundation#6565 (comment)
  • Loading branch information
rioug committed Oct 16, 2024
1 parent ed668de commit f024aff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/models/spree/tax_rate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ def compute_amount(item)
if default_zone_or_zone_match?(item.order)
calculator.compute(item)
else
# Tax refund should not be possible with the way our production server are configured
Bugsnag.notify(
"Notice: Tax refund should not be possible, please check the default zone and " \
"the tax rate zone configuration"
) do |payload|
payload.add_metadata :order_tax_zone, order.tax_zone
payload.add_metadata :tax_rate_zone, zone
payload.add_metadata :default_zone, Zone.default_tax
end
# In this case, it's a refund.
calculator.compute(item) * - 1
end
Expand Down
10 changes: 10 additions & 0 deletions spec/models/spree/tax_rate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,16 @@ module Spree
Spree::TaxRate.adjust(order, order.line_items)
expect(line_item.adjustments.credit.count).to eq 2
end

it "notifies bugsnag" do
# there are two tax rate
expect(Bugsnag).to receive(:notify).with(
"Notice: Tax refund should not be possible, please check the default zone and " \
"the tax rate zone configuration"
).twice

Spree::TaxRate.adjust(order, order.line_items)
end
end
end

Expand Down

0 comments on commit f024aff

Please sign in to comment.