When you edit an adjustment of an order the tax rate displayed is not the tax rate that has been selected previously.
In this screenshot the 20% tax is displayed but we can clearly see that the tax rate that was calculated to get to 0,05 cents was not 20%
bug-s3: a feature is broken but there is a workaround
there must be a problem in the form or controller setting the tax_rate_id used app/views/spree/admin/adjustments/_edit_form.html.haml and probably set in app/controllers/spree/admin/adjustments_controller.rb
I am tagging good-first-issue, should be easy for a dev with experience with rails.
Can I work on this?
yes! thanks!!
@luisramos0 I found two things
The tax rate that is been used during the editing is correct. However, there is a config that is changing one boolean variable of the selected tax rate.
34: def compute_line_item(line_item)
=> 35: if line_item.tax_category == rate.tax_category
36: if rate.included_in_price
37: deduced_total_by_rate(line_item.total, rate)
38: else
39: round_to_two_places(line_item.total * rate.amount)
40: end
41: else
42: 0
43: end
44: end
[16] pry(#<Spree::Calculator::DefaultTax>)> rate
=> #<Spree::TaxRate id: 1, amount: #<BigDecimal:564e41ba0be0,'0.2E0',9(18)>, zone_id: 3, tax_category_id: 1, created_at: "2020-06-07 00:38:33", updated_at: "2020-06-07 00:50:35", included_in_price: true, name: "Teste", show_rate_in_label: true, deleted_at: nil>
[17] pry(#<Spree::Calculator::DefaultTax>)> TaxRate.find_by_id(line_item.tax_category_id)
=> #<Spree::TaxRate id: 1, amount: #<BigDecimal:564e3ea59528,'0.2E0',9(18)>, zone_id: 3, tax_category_id: 1, created_at: "2020-06-07 00:38:33", updated_at: "2020-06-07 00:50:35", included_in_price: false, name: "Teste", show_rate_in_label: true, deleted_at: nil>
As you can se, the rate is the selected tax rate (in the case, 20%), but the attribute included_in_price was changed, causing the incorrect value
My guess is this configuration on this method from tax_rate_decorator.rb used on adjustments_controller.rb
def compute_tax(amount)
line_item = LineItem.new quantity: 1
line_item.tax_category = tax_category
line_item.define_singleton_method(:price) { amount }
# Tax on adjustments (represented by the included_tax field) is always inclusive of
# tax. However, there's nothing to stop an admin from setting one up with a tax rate
# that's marked as not inclusive of tax, and that would result in the DefaultTax
# calculator generating a slightly incorrect value. Therefore, we treat the tax
# rate as inclusive of tax for the calculations below, regardless of its original
# setting.
with_tax_included_in_price do
calculator.compute line_item
end
end
private
def with_tax_included_in_price
old_included_in_price = included_in_price
self.included_in_price = true
calculator.calculable.included_in_price = true
result = yield
ensure
self.included_in_price = old_included_in_price
calculator.calculable.included_in_price = old_included_in_price
result
end
end
What do you think?
I dont think there's an incorrect value, do you?
The fix to this issue should just change the drop down selection to the correct tax rate.
Maybe just something wrong with this line?
= select_tag :tax_rate_id, options_from_collection_for_select(Spree::TaxRate.all, :id, :name, @tax_rate_id), prompt: t(:remove_tax), class: 'select2 fullwidth'
Hmmm, I will check this @luisramos0