Update Order model distribution validation - make fully inclusive of order cycles

This commit is contained in:
Rohan Mitchell
2013-06-21 11:35:42 +10:00
parent bc40b2c856
commit 72f1c52b3e
2 changed files with 5 additions and 5 deletions

View File

@@ -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)

View File

@@ -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