diff --git a/app/models/spree/tax_rate.rb b/app/models/spree/tax_rate.rb index 064baf8852..50abeeb021 100644 --- a/app/models/spree/tax_rate.rb +++ b/app/models/spree/tax_rate.rb @@ -61,7 +61,7 @@ module Spree def adjust(order) label = create_label if included_in_price - if Zone.default_tax.contains? order.tax_zone + if default_zone_or_zone_match? order order.line_items.each { |line_item| create_adjustment(label, line_item, line_item) } else amount = -1 * calculator.compute(order) @@ -89,6 +89,10 @@ module Spree end end + def default_zone_or_zone_match?(order) + Zone.default_tax.contains?(order.tax_zone) || order.tax_zone == zone + end + # Manually apply a TaxRate to a particular amount. TaxRates normally compute against # LineItems or Orders, so we mock out a line item here to fit the interface # that our calculator (usually DefaultTax) expects. @@ -114,6 +118,8 @@ module Spree label = "" label << (name.presence || tax_category.name) + " " label << (show_rate_in_label? ? "#{amount * 100}%" : "") + label << " (#{I18n.t('models.tax_rate.included_in_price')})" if included_in_price? + label end def with_tax_included_in_price diff --git a/config/locales/en.yml b/config/locales/en.yml index 0354b9c4d2..2dff764d14 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -140,6 +140,8 @@ en: models: order_cycle: cloned_order_cycle_name: "COPY OF %{order_cycle}" + tax_rate: + included_in_price: "Included in price" validators: date_time_string_validator: diff --git a/lib/spree/core/calculated_adjustments.rb b/lib/spree/core/calculated_adjustments.rb index 6388369209..301d821642 100644 --- a/lib/spree/core/calculated_adjustments.rb +++ b/lib/spree/core/calculated_adjustments.rb @@ -43,7 +43,8 @@ module Spree order: order_object_for(target), label: label, mandatory: mandatory, - state: state + state: state, + included: tax_included?(self, target) ) end @@ -78,6 +79,15 @@ module Spree private + # Used for setting the #included boolean on tax adjustments. This will be removed in a + # later step, as the responsibility for creating all adjustments related to tax will be + # moved into the Spree::TaxRate class. + def tax_included?(originator, target) + originator.is_a?(Spree::TaxRate) && + originator.included_in_price && + originator.default_zone_or_zone_match?(order_object_for(target)) + end + def order_object_for(target) # Temporary method for adjustments transition. if target.is_a? Spree::Order