diff --git a/app/components/product_component.rb b/app/components/product_component.rb index c3f859116c..b6edcc0986 100644 --- a/app/components/product_component.rb +++ b/app/components/product_component.rb @@ -40,7 +40,7 @@ class ProductComponent < ViewComponentReflex::Component when 'on_demand' @product.on_demand when 'tax_category' - @product.tax_category.name + @product.variant.tax_category.name when 'inherits_properties' @product.inherits_properties when 'import_date' diff --git a/app/models/calculator/default_tax.rb b/app/models/calculator/default_tax.rb index f9c118905a..b6c8b1d3c2 100644 --- a/app/models/calculator/default_tax.rb +++ b/app/models/calculator/default_tax.rb @@ -45,7 +45,7 @@ module Calculator def line_items_total(order) matched_line_items = order.line_items.select do |line_item| - line_item.product.tax_category == rate.tax_category + line_item.variant.tax_category == rate.tax_category end matched_line_items.sum(&:total) @@ -70,7 +70,7 @@ module Calculator def applicable_rate?(applicator, line_item) fee = applicator.enterprise_fee (!fee.inherits_tax_category && fee.tax_category == rate.tax_category) || - (fee.inherits_tax_category && line_item.product.tax_category == rate.tax_category) + (fee.inherits_tax_category && line_item.variant.tax_category == rate.tax_category) end # Finds relevant fees for whole order, diff --git a/app/models/spree/line_item.rb b/app/models/spree/line_item.rb index ef0ea3a86b..17d678ebdf 100644 --- a/app/models/spree/line_item.rb +++ b/app/models/spree/line_item.rb @@ -121,7 +121,7 @@ module Spree def copy_tax_category return unless variant - self.tax_category = variant.product.tax_category + self.tax_category = variant.tax_category end def copy_dimensions @@ -192,7 +192,7 @@ module Spree end def tax_rates - product.tax_category&.tax_rates || [] + variant&.tax_category&.tax_rates || [] end def price_with_adjustments diff --git a/app/services/tax_rate_finder.rb b/app/services/tax_rate_finder.rb index e49d615976..351555e444 100644 --- a/app/services/tax_rate_finder.rb +++ b/app/services/tax_rate_finder.rb @@ -43,7 +43,7 @@ class TaxRateFinder def line_item_tax_category(enterprise_fee, line_item) if enterprise_fee.inherits_tax_category? - line_item.product.tax_category + line_item.variant.tax_category else enterprise_fee.tax_category end diff --git a/lib/open_food_network/enterprise_fee_applicator.rb b/lib/open_food_network/enterprise_fee_applicator.rb index 5a46117e19..db50ceabb5 100644 --- a/lib/open_food_network/enterprise_fee_applicator.rb +++ b/lib/open_food_network/enterprise_fee_applicator.rb @@ -37,7 +37,7 @@ module OpenFoodNetwork def tax_category(target) if target.is_a?(Spree::LineItem) && enterprise_fee.inherits_tax_category? - target.product.tax_category + target.variant.tax_category else enterprise_fee.tax_category end diff --git a/lib/reporting/reports/orders_and_fulfillment/base.rb b/lib/reporting/reports/orders_and_fulfillment/base.rb index 9d20695e09..4d223be657 100644 --- a/lib/reporting/reports/orders_and_fulfillment/base.rb +++ b/lib/reporting/reports/orders_and_fulfillment/base.rb @@ -61,7 +61,7 @@ module Reporting end def product_tax_category - proc { |line_items| line_items.first.variant.product.tax_category&.name } + proc { |line_items| line_items.first.variant.tax_category&.name } end def hub_name diff --git a/lib/reporting/reports/products_and_inventory/lettuce_share.rb b/lib/reporting/reports/products_and_inventory/lettuce_share.rb index 96100b1ecb..8311ff111d 100644 --- a/lib/reporting/reports/products_and_inventory/lettuce_share.rb +++ b/lib/reporting/reports/products_and_inventory/lettuce_share.rb @@ -39,7 +39,7 @@ module Reporting private def gst(variant) - tax_category = variant.product.tax_category + tax_category = variant.tax_category if tax_category && tax_category.tax_rates.present? tax_rate = tax_category.tax_rates.first line_item = mock_line_item(variant) diff --git a/spec/controllers/api/v0/orders_controller_spec.rb b/spec/controllers/api/v0/orders_controller_spec.rb index 9f29e41b9b..773a9170b8 100644 --- a/spec/controllers/api/v0/orders_controller_spec.rb +++ b/spec/controllers/api/v0/orders_controller_spec.rb @@ -276,7 +276,7 @@ module Api expect(json_response[:line_items].first[:variant][:product_name]) .to eq order.line_items.first.variant.product.name expect(json_response[:line_items].first[:tax_category_id]) - .to eq order.line_items.first.product.tax_category_id + .to eq order.line_items.first.variant.tax_category_id end end end diff --git a/spec/lib/reports/orders_and_fulfillment/orders_cycle_supplier_totals_report_spec.rb b/spec/lib/reports/orders_and_fulfillment/orders_cycle_supplier_totals_report_spec.rb index ebf1d44aae..6dcba9b807 100644 --- a/spec/lib/reports/orders_and_fulfillment/orders_cycle_supplier_totals_report_spec.rb +++ b/spec/lib/reports/orders_and_fulfillment/orders_cycle_supplier_totals_report_spec.rb @@ -110,7 +110,7 @@ describe Reporting::Reports::OrdersAndFulfillment::OrderCycleSupplierTotals do end it "has a variant row when product belongs to a tax category" do - product_tax_category_name = order.line_items.first.variant.product.tax_category.name + product_tax_category_name = order.line_items.first.variant.tax_category.name supplier_name_field = report_table.first[0] supplier_vat_status_field = report_table.first[-2] @@ -139,7 +139,7 @@ describe Reporting::Reports::OrdersAndFulfillment::OrderCycleSupplierTotals do end it "has a variant row when product belongs to a tax category" do - product_tax_category_name = order.line_items.first.variant.product.tax_category.name + product_tax_category_name = order.line_items.first.variant.tax_category.name supplier_name_field = report_table.first[0] supplier_vat_status_field = report_table.first[-2] diff --git a/spec/models/spree/line_item_spec.rb b/spec/models/spree/line_item_spec.rb index 62db1f36be..30af1dde24 100644 --- a/spec/models/spree/line_item_spec.rb +++ b/spec/models/spree/line_item_spec.rb @@ -51,7 +51,7 @@ module Spree it "copies over a variant's tax category" do line_item.tax_category = nil line_item.copy_tax_category - expect(line_item.tax_category).to eq line_item.variant.product.tax_category + expect(line_item.tax_category).to eq line_item.variant.tax_category end end diff --git a/spec/system/admin/products_spec.rb b/spec/system/admin/products_spec.rb index 88703215fc..1f22b1a71d 100644 --- a/spec/system/admin/products_spec.rb +++ b/spec/system/admin/products_spec.rb @@ -109,7 +109,7 @@ describe ' expect(product.primary_taxon_id).to eq(taxon.id) expect(product.variants.first.price.to_s).to eq('19.99') expect(product.on_hand).to eq(5) - expect(product.tax_category_id).to eq(tax_category.id) + expect(product.variants.first.tax_category_id).to eq(tax_category.id) expect(product.shipping_category).to eq(shipping_category) expect(product.description).to eq("

A description...

") expect(product.group_buy).to be_falsey @@ -285,7 +285,7 @@ describe ' expect(flash_message).to eq('Product "A new product !!!" has been successfully created!') product = Spree::Product.find_by(name: 'A new product !!!') expect(product.supplier).to eq(@supplier2) - expect(product.tax_category).to be_nil + expect(product.variants.first.tax_category).to be_nil end end end