Skip to content

Commit 5979f25

Browse files
Harmony BouvieradammathysstewartjarednormanNoah-Silvera
authored andcommitted
Set tax adjustment amount without persistance
To support the in-memory order updater, we want adjustments to be modified without writing to the database immediately. We added `autosave: true` in the association on line_items ensures that the adjustment amount will be saved with the line_item, or by extension the order when it is eventually persisted by the order updater. The tests for the OrderTaxation have been updated to use `size` instead of `count` to ensure an in-memory reported count/size. Co-authored-by: Adam Mueller <[email protected]> Co-authored-by: Andrew Stewart <[email protected]> Co-authored-by: Jared Norman <[email protected]> Co-authored-by: Noah Silvera <[email protected]> Co-authored-by: benjamin wil <[email protected]> Co-authored-by: Alistair Norman <[email protected]>
1 parent 1f0a28f commit 5979f25

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

core/app/models/spree/line_item.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class LineItem < Spree::Base
1818

1919
has_one :product, through: :variant
2020

21-
has_many :adjustments, as: :adjustable, inverse_of: :adjustable, dependent: :destroy
21+
has_many :adjustments, as: :adjustable, inverse_of: :adjustable, dependent: :destroy, autosave: true
2222
has_many :inventory_units, inverse_of: :line_item
2323

2424
before_validation :normalize_quantity

core/app/models/spree/order_taxation.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ def update_adjustment(item, tax_item)
7777
label: tax_item.label,
7878
included: tax_item.included_in_price
7979
)
80-
tax_adjustment.update!(amount: tax_item.amount)
80+
81+
tax_adjustment.amount = tax_item.amount
8182
tax_adjustment
8283
end
8384
end

core/spec/models/spree/order_taxation_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868

6969
it "creates a new tax adjustment", aggregate_failures: true do
7070
apply
71-
expect(line_item.adjustments.count).to eq 1
71+
expect(line_item.adjustments.size).to eq 1
7272

7373
tax_adjustment = line_item.adjustments.first
7474
expect(tax_adjustment.label).to eq "Tax!"
@@ -136,7 +136,7 @@
136136
expect {
137137
taxation.apply(new_taxes)
138138
}.to change {
139-
line_item.adjustments.count
139+
line_item.adjustments.size
140140
}.from(1).to(0)
141141
end
142142
end
@@ -174,7 +174,7 @@
174174
end
175175

176176
it "creates a new tax adjustment", aggregate_failures: true do
177-
expect(order.adjustments.count).to eq 1
177+
expect(order.adjustments.size).to eq 1
178178

179179
tax_adjustment = order.adjustments.first
180180
expect(tax_adjustment.label).to eq "Order Tax!"

0 commit comments

Comments
 (0)