mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-11 23:17:48 +00:00
Update Order model distribution validation - make fully inclusive of order cycles
This commit is contained in:
@@ -5,15 +5,15 @@ Spree::Order.class_eval do
|
||||
belongs_to :distributor, :class_name => 'Enterprise'
|
||||
|
||||
before_validation :shipping_address_from_distributor
|
||||
validate :products_available_from_new_distributor, :if => :distributor_id_changed?
|
||||
validate :products_available_from_new_distribution, :if => lambda { distributor_id_changed? || order_cycle_id_changed? }
|
||||
attr_accessible :order_cycle_id, :distributor_id
|
||||
|
||||
after_create :set_default_shipping_method
|
||||
|
||||
|
||||
def products_available_from_new_distributor
|
||||
# Check that the line_items in the current order are available from a newly selected distributor
|
||||
errors.add(:distributor_id, "cannot supply the products in your cart") unless DistributionChangeValidator.new(self).can_change_to_distribution?(distributor, order_cycle)
|
||||
def products_available_from_new_distribution
|
||||
# Check that the line_items in the current order are available from a newly selected distribution
|
||||
errors.add(:base, "Distributor or order cycle cannot supply the products in your cart") unless DistributionChangeValidator.new(self).can_change_to_distribution?(distributor, order_cycle)
|
||||
end
|
||||
|
||||
def set_order_cycle!(order_cycle)
|
||||
|
||||
@@ -121,7 +121,7 @@ describe Spree::Order do
|
||||
|
||||
subject.distributor = test_enterprise
|
||||
subject.should_not be_valid
|
||||
subject.errors.should include :distributor_id
|
||||
subject.errors.messages.should == {base: ["Distributor or order cycle cannot supply the products in your cart"]}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user