-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only destroy tax adjustment for open order when the associated tax ra…
…te is deleted. For closed order just nullify the source_id. Update line_item & order when adjustments are deleted. Add rspec tests to cover cases where adjustments get (or not get) destroyed when taxrate/promotion is deleted. Move deals_with_adjustments to a separate mixin. Add new mixin to core Revert previous changes to remove unnecessary tests. Remove order.update! and simplify rspec. Fixes #4828 Fixes #4771 Conflicts: core/spec/models/spree/tax_rate_spec.rb
- Loading branch information
1 parent
e2a75cd
commit c1d44b1
Showing
6 changed files
with
50 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Spree | ||
module Core | ||
module AdjustmentSource | ||
def self.included(klass) | ||
klass.class_eval do | ||
def deals_with_adjustments_for_deleted_source | ||
adjustment_scope = self.adjustments.includes(:order).references(:spree_orders) | ||
|
||
# For incomplete orders, remove the adjustment completely. | ||
adjustment_scope.where("spree_orders.completed_at IS NULL").destroy_all | ||
|
||
# For complete orders, the source will be invalid. | ||
# Therefore we nullify the source_id, leaving the adjustment in place. | ||
# This would mean that the order's total is not altered at all. | ||
adjustment_scope.where("spree_orders.completed_at IS NOT NULL").each do |adjustment| | ||
adjustment.update_columns( | ||
source_id: nil, | ||
updated_at: Time.now, | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters