mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Use included boolean in tax adjustments
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user