mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Include ItemAdjustments handling in Adjustment class
Currently only applies to shipments, but will later include line items, etc
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user