Update delegation and method chaining between product and tax_category

This commit is contained in:
Matt-Yorkley
2023-07-03 12:56:45 +01:00
committed by Maikel Linke
parent d33e780411
commit 4934d09a4c
11 changed files with 15 additions and 15 deletions

View File

@@ -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'

View File

@@ -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,

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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]

View File

@@ -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

View File

@@ -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("<p>A description...</p>")
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