-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use in-memory objects for adjustments in ItemAdjustments #1401
Changes from 14 commits
1e60956
dd22bd0
df3135b
57a1234
6ce4f90
69982a8
7af5898
03f3c82
1fa59b1
bcea902
d27d092
9b4e493
1f8972e
bbfc068
9ad5b23
a0234db
e8a6a70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,18 +6,18 @@ class Spree::UnitCancel < Spree::Base | |
DEFAULT_REASON = 'Cancel' | ||
|
||
belongs_to :inventory_unit | ||
has_one :adjustment, as: :source, dependent: :destroy | ||
has_many :adjustments, as: :source, dependent: :destroy | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps this change would merit an entry in the CHANGELOG? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bbuchalter good point. I updated to @jhawthorn's solution though, so I've reverted back to |
||
|
||
validates :inventory_unit, presence: true | ||
|
||
# Creates necessary cancel adjustments for the line item. | ||
def adjust! | ||
raise "Adjustment is already created" if adjustment | ||
raise "Adjustment is already created" if adjustments.exists? | ||
|
||
amount = compute_amount(inventory_unit.line_item) | ||
|
||
create_adjustment!( | ||
adjustable: inventory_unit.line_item, | ||
inventory_unit.line_item.adjustments.create!( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively, I think this could be.
This should keep both associations fresh without performing an extra query (no query run since source will already be set correctly). This avoids the need to change the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. Thanks! |
||
source: self, | ||
amount: amount, | ||
order: inventory_unit.order, | ||
label: "#{Spree.t(:cancellation)} - #{reason}", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this we should probably fix this line https://github.com/solidusio/solidus/blob/master/core/app/models/spree/tax/item_adjuster.rb#L31
and then remove the
skip_destroy_adjustments
optionorders here should never have tax adjustments (they've been only on items since spree 2.2), so I don't think we need to consider that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jhawthorn thanks, updated!