summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/super_good/solidus_taxjar.rb2
-rw-r--r--lib/super_good/solidus_taxjar/tax_calculator.rb18
-rw-r--r--spec/super_good/solidus_taxjar/tax_calculator_spec.rb4
-rw-r--r--spec/super_good/solidus_taxjar_spec.rb3
4 files changed, 17 insertions, 10 deletions
diff --git a/lib/super_good/solidus_taxjar.rb b/lib/super_good/solidus_taxjar.rb
index ef9497d..818947d 100644
--- a/lib/super_good/solidus_taxjar.rb
+++ b/lib/super_good/solidus_taxjar.rb
@@ -26,6 +26,6 @@ module SuperGood
}
self.taxable_address_check = ->(address) { true }
self.shipping_tax_label_maker = ->(shipment, shipping_tax) { "Sales Tax" }
- self.line_item_tax_label_maker = ->(taxjar_line_item) { "Sales Tax" }
+ self.line_item_tax_label_maker = ->(taxjar_line_item, spree_line_item) { "Sales Tax" }
end
end
diff --git a/lib/super_good/solidus_taxjar/tax_calculator.rb b/lib/super_good/solidus_taxjar/tax_calculator.rb
index 91ff6c0..5052814 100644
--- a/lib/super_good/solidus_taxjar/tax_calculator.rb
+++ b/lib/super_good/solidus_taxjar/tax_calculator.rb
@@ -35,12 +35,18 @@ module SuperGood
def line_item_taxes
@line_item_taxes ||=
- taxjar_breakdown.line_items.map do |line_item|
+ taxjar_breakdown.line_items.map do |taxjar_line_item|
+ spree_line_item_id = taxjar_line_item.id.to_i
+
+ # Searching in memory because this association is loaded and most
+ # orders aren't going to have a huge number of line items.
+ spree_line_item = order.line_items.find { |li| li.id == spree_line_item_id }
+
Spree::Tax::ItemTax.new(
- item_id: line_item.id.to_i,
- label: line_item_tax_label(line_item),
+ item_id: spree_line_item_id,
+ label: line_item_tax_label(taxjar_line_item, spree_line_item),
tax_rate: tax_rate,
- amount: line_item.tax_collectable,
+ amount: taxjar_line_item.tax_collectable,
included_in_price: false
)
end
@@ -141,8 +147,8 @@ module SuperGood
)
end
- def line_item_tax_label(taxjar_line_item)
- SuperGood::SolidusTaxJar.line_item_tax_label_maker.(taxjar_line_item)
+ def line_item_tax_label(taxjar_line_item, spree_line_item)
+ SuperGood::SolidusTaxJar.line_item_tax_label_maker.(taxjar_line_item, spree_line_item)
end
end
end
diff --git a/spec/super_good/solidus_taxjar/tax_calculator_spec.rb b/spec/super_good/solidus_taxjar/tax_calculator_spec.rb
index 1899443..a13f564 100644
--- a/spec/super_good/solidus_taxjar/tax_calculator_spec.rb
+++ b/spec/super_good/solidus_taxjar/tax_calculator_spec.rb
@@ -24,7 +24,7 @@ RSpec.describe ::SuperGood::SolidusTaxJar::TaxCalculator do
)
end
- let(:line_items) { [::Spree::LineItem.new] }
+ let(:line_items) { [::Spree::LineItem.new(id: 33)] }
let(:boring_shipment) do
::Spree::Shipment.new(id: 1, cost: 7)
@@ -178,7 +178,7 @@ RSpec.describe ::SuperGood::SolidusTaxJar::TaxCalculator do
before do
allow(SuperGood::SolidusTaxJar.line_item_tax_label_maker)
.to receive(:call)
- .with(taxjar_line_item)
+ .with(taxjar_line_item, line_items.first)
.and_return("Space Tax")
end
diff --git a/spec/super_good/solidus_taxjar_spec.rb b/spec/super_good/solidus_taxjar_spec.rb
index 957e2e3..dafc4fb 100644
--- a/spec/super_good/solidus_taxjar_spec.rb
+++ b/spec/super_good/solidus_taxjar_spec.rb
@@ -45,8 +45,9 @@ RSpec.describe SuperGood::SolidusTaxJar do
end
describe ".line_item_tax_label_maker" do
- subject { described_class.line_item_tax_label_maker.(taxjar_line_item) }
+ subject { described_class.line_item_tax_label_maker.(taxjar_line_item, spree_line_item) }
let(:taxjar_line_item) { instance_double Taxjar::BreakdownLineItem }
+ let(:spree_line_item) { Spree::LineItem.new }
it { is_expected.to eq "Sales Tax" }
end
end