diff options
author | Nicholas Van Doorn <nick@super.gd> | 2021-04-15 15:33:32 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-15 15:33:32 -0700 |
commit | a467dd0eae45d74da3b4c8ca26e01fb804e8ca3d (patch) | |
tree | 47659441a337a3d8c40cf4b7a6622ce9743bcc5a | |
parent | 19e9513bb8e3aca8c98128071d27d4ba59abc90b (diff) | |
parent | 4eda78c5a025efa56d914983d9c88a576d66e6d5 (diff) |
Merge pull request #58 from Noah-Silvera/56-take-adjustments-into-account-when-calculating-shipping
Take adjustments into account when calculating shipping
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | lib/super_good/solidus_taxjar.rb | 2 | ||||
-rw-r--r-- | spec/super_good/solidus_taxjar/api_params_spec.rb | 4 | ||||
-rw-r--r-- | spec/super_good/solidus_taxjar_spec.rb | 15 |
4 files changed, 20 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index d953efa..f5a75f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## master - [#51](https://github.com/SuperGoodSoft/solidus_taxjar/pull/51) Add nexus regions method to API +- [#58](https://github.com/SuperGoodSoft/solidus_taxjar/pull/58) Take shipping promotions into account in default calculator ## v0.18.1 diff --git a/lib/super_good/solidus_taxjar.rb b/lib/super_good/solidus_taxjar.rb index 36b5d85..a3cb730 100644 --- a/lib/super_good/solidus_taxjar.rb +++ b/lib/super_good/solidus_taxjar.rb @@ -44,7 +44,7 @@ module SuperGood } self.line_item_tax_label_maker = ->(taxjar_line_item, spree_line_item) { "Sales Tax" } self.logging_enabled = false - self.shipping_calculator = ->(order) { order.shipment_total } + self.shipping_calculator = ->(order) { order.shipments.sum(&:total_before_tax) } self.shipping_tax_label_maker = ->(shipment, shipping_tax) { "Sales Tax" } self.taxable_address_check = ->(address) { true } self.taxable_order_check = ->(order) { true } diff --git a/spec/super_good/solidus_taxjar/api_params_spec.rb b/spec/super_good/solidus_taxjar/api_params_spec.rb index 6c13e03..1e879e7 100644 --- a/spec/super_good/solidus_taxjar/api_params_spec.rb +++ b/spec/super_good/solidus_taxjar/api_params_spec.rb @@ -8,9 +8,9 @@ RSpec.describe SuperGood::SolidusTaxjar::ApiParams do line_items: [line_item], number: "R111222333", ship_address: ship_address, - shipment_total: BigDecimal("3.01"), store: store, total: order_total, + shipments: [shipment], user_id: 12345 ).tap do |order| order.update! completed_at: DateTime.new(2018, 3, 6, 12, 10, 33) @@ -119,6 +119,8 @@ RSpec.describe SuperGood::SolidusTaxjar::ApiParams do ) end + let(:shipment) { Spree::Shipment.create!(cost: BigDecimal("3.01")) } + describe "#order_params" do subject { described_class.order_params(order) } diff --git a/spec/super_good/solidus_taxjar_spec.rb b/spec/super_good/solidus_taxjar_spec.rb index 6236b2f..d9ef1d4 100644 --- a/spec/super_good/solidus_taxjar_spec.rb +++ b/spec/super_good/solidus_taxjar_spec.rb @@ -73,5 +73,20 @@ RSpec.describe SuperGood::SolidusTaxjar do let(:spree_line_item) { Spree::LineItem.new } it { is_expected.to eq "Sales Tax" } end + + describe ".shipping_calculator" do + subject { described_class.shipping_calculator.call(order) } + + let(:order) { create :order } + let(:shipment) { create :shipment, order: order, cost: 20 } + + before do + create :adjustment, order: order, adjustable: shipment, amount: -10, eligible: true, source: create(:shipping_rate, shipment: shipment) + end + + it "returns the shipment total including promotions" do + expect(subject).to eq(10) + end + end end end |