app/models/exchange.rb in artfully_ose-1.2.0.pre.15 vs app/models/exchange.rb in artfully_ose-1.2.0.pre.16

- old
+ new

@@ -1,9 +1,9 @@ class Exchange include ActiveModel::Validations - attr_accessor :order, :items, :tickets, :ticket_type + attr_accessor :order, :items, :tickets, :ticket_type, :send_email_confirmation attr_reader :exchange_order validates_presence_of :order validates_presence_of :ticket_type validates_length_of :items, :minimum => 1 @@ -15,15 +15,16 @@ validate :tickets_belong_to_organization #The original order #The items to exchange #The tickets that they are being exchanged for - def initialize(order, items, tickets = [], ticket_type) + def initialize(order, items, tickets, ticket_type, send_email_confirmation = false) self.order = order self.items = items - self.tickets = tickets - self.ticket_type = ticket_type + self.tickets = tickets || [] + self.ticket_type = ticket_type + self.send_email_confirmation = send_email_confirmation end def items_are_exchangeable errors.add(:items, "are not available to exchange") unless items.all?(&:exchangeable?) end @@ -40,11 +41,11 @@ errors.add(:tickets, "do not belong to this organization") unless tickets.all? { |ticket| order.organization.can? :manage, ticket } end def submit ActiveRecord::Base.transaction do - self.tickets = Ticket.lock(tickets, ticket_type, Cart.create) + self.tickets = Ticket.lock(self.tickets, self.ticket_type, Cart.create) sell_new_items return_old_items end end @@ -73,9 +74,10 @@ exchange_order.parent = order exchange_order.payment_method = order.payment_method exchange_order.created_at = time exchange_order.for_organization order.organization exchange_order.details = "Order is the result of an exchange on #{I18n.l time, :format => :slashed_date}" + exchange_order.skip_email = !send_email_confirmation exchange_order << tickets end exchange_order.record_exchange! items exchange_order.save! @exchange_order = exchange_order