Include ItemAdjustments handling in Adjustment class

Currently only applies to shipments, but will later include line items, etc
This commit is contained in:
Matt-Yorkley
2021-02-08 17:58:29 +00:00
parent 0d5d4aca11
commit 7425ad5c4a
2 changed files with 13 additions and 1 deletions

View File

@@ -47,6 +47,8 @@ module Spree
validates :label, presence: true
validates :amount, numericality: true
after_create :update_adjustable_adjustment_total
state_machine :state, initial: :open do
event :close do
transition from: :open, to: :closed
@@ -149,5 +151,11 @@ module Spree
originator_type.constantize.unscoped { super }
end
private
def update_adjustable_adjustment_total
Spree::ItemAdjustments.new(adjustable).update if adjustable
end
end
end

View File

@@ -12,7 +12,7 @@ module Spree
end
def update
update_adjustments if item.persisted?
update_adjustments if updatable_totals?
item
end
@@ -31,6 +31,10 @@ module Spree
private
def updatable_totals?
item.persisted? && item.is_a?(Spree::Shipment)
end
def tax_adjustments
(item.respond_to?(:all_adjustments) ? item.all_adjustments : item.adjustments).tax
end